Skip to content

Instantly share code, notes, and snippets.

@hteibler
Created June 3, 2020 13:45
Show Gist options
  • Save hteibler/74f0ee2659eab77dcd6161de6a41705a to your computer and use it in GitHub Desktop.
Save hteibler/74f0ee2659eab77dcd6161de6a41705a to your computer and use it in GitHub Desktop.
deploy network
overlay_network_name="Net-AP4"
overlay_network_pre="172.24."
create_network()
def create_network():
'''
c n
'''
# Load the zero-os sal and create empty reservation method
zos = j.sal.zosv2
r = zos.reservation_create()
overlay_network_ip_range = overlay_network_pre+"0.0/16"
# Farm ID of the farms involved
green_edge_vienna2 = 82872
green_edge_salzburg1 = 12775
# Fixed IPv4 gateway node
ipv4_gateway='CBDY1Fu4CuxGpdU3zLL9QT5DGaRkxjpuJmzV6V5CBWg4'
gwnode = j.clients.explorer.explorer.nodes.get(ipv4_gateway)
# Create network data structure
network = zos.network.create(r, ip_range=overlay_network_ip_range, network_name=overlay_network_name)
# Create data structures for nodes involved
nodes_salzburg1 = zos.nodes_finder.nodes_search(farm_id=green_edge_salzburg1) # (IPv6 nodes)
nodes_vienna2 = zos.nodes_finder.nodes_search(farm_id=green_edge_vienna2) # (IPv6 nodes)
#nodes_gw = zos.nodes_finder.nodes_search(farm_id=1)
nodes_all=nodes_salzburg1 + nodes_vienna2
nodes_all.append(gwnode)
# We only need one WG interface, once set this is set to True
wg_already_set = False
# This adds all the nodes that are up and accepts 'FreeTFT' as a currency.
for i, node in enumerate(nodes_all):
if (zos.nodes_finder.filter_is_up(node) and zos.nodes_finder.filter_is_free_to_use(node)):
iprange = overlay_network_pre+f"{i+10}.0/24"
zos.network.add_node(network, node.node_id , iprange)
print("Node: ", i,node.farm_id, node.node_id, " (",node.total_resources.cru, ") :", iprange)
if (zos.nodes_finder.filter_public_ip4(node) and wg_already_set == False):
wg_config = zos.network.add_access(network, node.node_id, overlay_network_pre+'254.0/24', ipv4=True)
print("Node number: ", i, node.node_id, ":", iprange," WG")
wg_already_set = True
# print the wireguard config - store in a secure place.
print("WG Interface configured:")
print("------------------------")
print(wg_config)
print("------------------------")
# Everything is set - now make the reservation
currency='FreeTFT'
# Set the expiration time
expiration = int(j.data.time.HRDateToEpoch('2021/01/31'))
# register the reservation
registered_reservation = zos.reservation_register(r, expiration, currencies=currency)
print(registered_reservation)
time.sleep(5)
# inspect the result of the reservation provisioning
result = zos.reservation_result(registered_reservation.reservation_id)
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment