6 from ssh_client import SSHClient
9 exec_cmd = common.exec_cmd
11 check_file_exists = common.check_file_exists
14 CLOUD_DEPLOY_FILE = 'deploy.py'
17 class CloudDeploy(object):
19 def __init__(self, dha, fuel_ip, fuel_username, fuel_password, dea_file,
22 self.fuel_ip = fuel_ip
23 self.fuel_username = fuel_username
24 self.fuel_password = fuel_password
25 self.dea_file = dea_file
26 self.work_dir = work_dir
27 self.file_dir = os.path.dirname(os.path.realpath(__file__))
28 self.ssh = SSHClient(self.fuel_ip, self.fuel_username,
30 self.macs_file = '%s/macs.yaml' % self.file_dir
31 self.node_ids = self.dha.get_node_ids()
33 def upload_cloud_deployment_files(self):
34 dest ='~/%s/' % self.work_dir
37 s.exec_cmd('rm -rf %s' % self.work_dir, check=False)
38 s.exec_cmd('mkdir ~/%s' % self.work_dir)
39 s.scp_put(self.dea_file, dest)
40 s.scp_put(self.macs_file, dest)
41 s.scp_put('%s/common.py' % self.file_dir, dest)
42 s.scp_put('%s/dea.py' % self.file_dir, dest)
43 for f in glob.glob('%s/cloud/*' % self.file_dir):
46 def power_off_nodes(self):
47 for node_id in self.node_ids:
48 self.dha.node_power_off(node_id)
50 def power_on_nodes(self):
51 for node_id in self.node_ids:
52 self.dha.node_power_on(node_id)
54 def set_boot_order(self, boot_order_list):
55 for node_id in self.node_ids:
56 self.dha.node_set_boot_order(node_id, boot_order_list)
58 def get_mac_addresses(self):
60 for node_id in self.node_ids:
61 macs_per_node[node_id] = self.dha.get_node_pxe_mac(node_id)
62 with io.open(self.macs_file, 'w') as stream:
63 yaml.dump(macs_per_node, stream, default_flow_style=False)
65 def run_cloud_deploy(self, deploy_app):
66 log('START CLOUD DEPLOYMENT')
67 deploy_app = '%s/%s' % (self.work_dir, deploy_app)
68 dea_file = '%s/%s' % (self.work_dir, os.path.basename(self.dea_file))
69 macs_file = '%s/%s' % (self.work_dir, os.path.basename(self.macs_file))
71 self.ssh.run('python %s %s %s' % (deploy_app, dea_file, macs_file))
75 self.power_off_nodes()
77 self.set_boot_order(['pxe', 'disk'])
81 self.get_mac_addresses()
83 check_file_exists(self.macs_file)
85 self.upload_cloud_deployment_files()
87 self.run_cloud_deploy(CLOUD_DEPLOY_FILE)