Created
August 16, 2018 13:44
-
-
Save 0xIslamTaha/1da03497f9e2ab62c49c0908af85d9e7 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
""" | |
Pre-requests: | |
- zboot machine which is as an example: | |
- ubuntu machine 16.04 | |
- Create a zerotier nw and connect to it | |
- Install JS9 | |
- Install zrobot | |
- Run zrobot ex, `zrobot server start -D <zrobot-data-repo> -C <js9-config-repo> -T [email protected]:zero-os/0-boot-templates.git --auto-push` | |
Example: `zrobot server start -D ssh://[email protected]:7022/kristof_farm/gent_0boot_zrobot.git -C ssh://[email protected]:7022/kristof_farm/gent_0boot_config.git -T [email protected]:threefoldtech/0-templates.git --auto-push` | |
Example: `` | |
- Create zrobot client ex. `zrobot robot connect zero-boot http://127.0.0.1:6600` | |
- Router: | |
- Configure this router. | |
- Connect it to the same zerotier nw. | |
- List of hosts: | |
example :[{"network":"10.2.0.0/16", | |
"hostname":"ipmi-storage03", | |
"mac":"ac:1f:6b:4b:75:2a", | |
"ip":"10.2.20.43"}] | |
- Edit this script with your variables' values. | |
What is this script do? | |
- It creates a zboot pool which has all zboot_host_ipmi and turn all of them on to load the lkrn_url. | |
""" | |
from jumpscale import j | |
# lkrnurl | |
farmer_id = '' | |
lkrn_url = 'https://bootstrap.gig.tech/krn/v1.4.1/c7c8172af1f387a6/farmer_id={}'.formate(farmer_id) | |
# ssh client params | |
router_ip = '' | |
router_ssh_username = '' | |
router_ssh_password = '' | |
# zboot client params | |
zt_nw_id = '' | |
zt_token = '' | |
# IPMI client params | |
ipmi_username = '' | |
ipmi_password = '' | |
#hosts | |
hosts = [{"hostname":"ipmi-storage03", | |
"mac":"ac:1f:6b:4b:75:2a", | |
"ip":"10.2.20.43", | |
"network":"10.2.0.0/16" | |
"ipmi_username":ipmi_username, | |
"ipmi_password":ipmi_password, | |
"zb_ipmi_client": [], | |
"zb_ipmi_host": [] }] | |
robot = j.clients.zrobot.robots['zero-boot'] | |
print(' [*] create zerotier client') | |
data = { | |
'token': zt_token | |
} | |
robot.services.create("github.com/threefoldtech/0-templates/zerotier_client/0.0.1", "zboot1-zt-3", data=data) | |
print(' [*] zerotier client : zboot1-zt-3') | |
print(' [*] SSH client to the router') | |
data = { | |
'host': router_ip, | |
'login': router_ssh_username, | |
'password': router_ssh_password | |
} | |
ssh_service = robot.services.create("github.com/threefoldtech/0-templates/ssh_client/0.0.1", "zboot1-ssh-3", data=data) | |
print(' [*] SSH client : zboot1-ssh-3') | |
print(' [*] zboot client') | |
data = { | |
'networkId': zt_nw_id, | |
'sshClient' : 'zboot1-ssh-3', # ssh client instance name | |
'zerotierClient': 'zboot1-zt-3', # zerotier client instance name | |
} | |
zboot_client = robot.services.create("github.com/threefoldtech/0-templates/zeroboot_client/0.0.1", "zboot1-zb-3", data=data) | |
print(' [*] zboot client : zboot1-zb-3') | |
for host in hosts: | |
print(' [*] Create ipmi client') | |
ipmi_client_service_name = host['hostname']+'_ipmi_client' | |
data = { | |
"bmc": host['ip'], # ipmi interface address of the host | |
"user": host['ipmi_username'], | |
"password": host['ipmi_password'], | |
} | |
host['zb_ipmi_client'].append(robot.services.create("github.com/threefoldtech/0-templates/ipmi_client/0.0.1", ipmi_client_service_name, data=data)) | |
print(' [*] ipmi client : {}'.format(ipmi_client_service_name)) | |
print(' [*] Create ipmi host') | |
ipmi_hosts_service_name = [] | |
ipmi_host_service_name = host['hostname']+'_ipmi_host' | |
data = { | |
'zerobootClient': 'zboot1-zb-3', # zeroboot client instance name | |
'ipmiClient': ipmi_client_service_name, # ipmi client instance name | |
'hostname': host['hostname'], | |
'mac': host['mac'], | |
'ip': host['ip'], | |
'lkrnUrl': lkrn_url, | |
} | |
zb_ipmi_host = robot.services.create("github.com/threefoldtech/0-templates/zeroboot_ipmi_host/0.0.1",ipmi_host_service_name, data=data) | |
zb_ipmi_host.schedule_action('install').wait(die=True) | |
host['zb_ipmi_host'].append(zb_ipmi_host) | |
ipmi_hosts_service_name.append(ipmi_host_service_name) | |
print(' [*] ipmi host : {}'.format(ipmi_host_service_name)) | |
print(' [*] zboot pool ') | |
data = { | |
'zerobootHosts': ipmi_hosts_service_name # list of installed zeroboot host instances ready for reservation. | |
} | |
pool_service = robot.services.create("github.com/threefoldtech/0-templates/zeroboot_pool/0.0.1", "zboot1-pool", data=data) | |
print(' [*] zboot pool : zboot1-pool') | |
print(' [*] Install hosts and turn all of them ON') | |
for host in host['zb_ipmi_host']: | |
host.schedule_action("power_cycle").wait(die=True).result | |
host.schedule_action("power_status").wait(die=True).result | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment