Created
May 30, 2018 07:45
-
-
Save grimpy/394c2327367f2398e60de8dc28adfbe8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from js9 import j | |
GATEWAY_TEMPLATE_UID = 'github.com/zero-os/0-templates/gateway/0.0.1' | |
NODE_TEMPLATE_UID = 'github.com/zero-os/0-templates/node/0.0.1' | |
ZEROTIER_CLIENT_TEMPLATE_UID = 'github.com/zero-os/0-templates/zerotier_client/0.0.1' | |
cl = j.clients.zerotier.get() | |
zt_token = cl.config.data['token_'] | |
iyo = j.clients.itsyouonline.get() | |
jwt = iyo.jwt_get(scope='user:memberof:threefold.farmers.public_gateway') | |
url = 'http://10.103.199.4:6600' | |
j.clients.zrobot.get('gw2', data={'jwt_': jwt, 'url': url}) | |
api = j.clients.zrobot.robots['gw2'] | |
print('Create node') | |
node = api.services.find_or_create(NODE_TEMPLATE_UID, 'gw2', data={'hostname': 'public_gateway_2'}) | |
print('Install node') | |
node.schedule_action('install').wait(die=True) | |
print('Configure node network') | |
# node.schedule_action('configure_network', args={'vlan': 2312, 'cidr': '10.241.0.0/24'}).wait(die=True) | |
print('Configure zt token') | |
api.services.find_or_create(ZEROTIER_CLIENT_TEMPLATE_UID, 'gwzt', data={'token': zt_token}) | |
gatewaydata = { | |
'hostname': 'gw2', | |
'domain': 'lan', | |
'networks': [{ | |
'id': 0, | |
'type': 'vlan', | |
'name': 'public', | |
'config': { | |
'cidr': '185.69.166.242/24', | |
'gateway': '185.69.166.1' | |
} | |
}, { | |
'name': 'gw_zerotier', | |
'type': 'zerotier', | |
'ztClient': 'gwzt', | |
'id': '9f77fc393e094c66' | |
}] | |
} | |
print('Create gateway') | |
gateway = api.services.find_or_create(GATEWAY_TEMPLATE_UID, 'gw2', gatewaydata) | |
print('Install gateway') | |
gateway.schedule_action('install').wait(die=True) | |
forward = { | |
'name': 'joworklaptop', | |
'srcnetwork': 'public', | |
'srcport': 8080, | |
'dstip': '10.103.80.80', | |
'dstport': 8080, | |
'protocols': ['tcp'] | |
} | |
gateway.schedule_action('add_portforward', args={'forward': forward}).wait(die=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment