5 from cloud import common
6 from cloud.dea import DeploymentEnvironmentAdapter
7 from hardware_adapters.dha import DeploymentHardwareAdapter
8 from ssh_client import SSHClient
10 exec_cmd = common.exec_cmd
12 check_file_exists = common.check_file_exists
15 class CloudDeploy(object):
17 def __init__(self, fuel_ip, fuel_username, fuel_password):
18 self.fuel_ip = fuel_ip
19 self.fuel_username = fuel_username
20 self.fuel_password = fuel_password
21 self.shelf_blades_dict = {}
22 self.macs_per_shelf_dict = {}
24 def copy_to_fuel_master(self, dir_path=None, file_path=None, target='~'):
26 path = '-r ' + dir_path
29 LOG.debug('Copying %s to Fuel Master %s' % (path, target))
31 exec_cmd('sshpass -p %s scp -o UserKnownHostsFile=/dev/null'
32 ' -o StrictHostKeyChecking=no -o ConnectTimeout=15'
34 % (self.fuel_password, path, self.fuel_username,
35 self.fuel_ip, target))
37 def run_cloud_deploy(self, deploy_dir, deploy_app):
38 LOG.debug('START CLOUD DEPLOYMENT')
39 ssh = SSHClient(self.fuel_ip, self.fuel_username, self.fuel_password)
41 ssh.run('python %s/%s' % (deploy_dir, deploy_app))
44 def power_off_blades(self, dea):
45 for shelf, blade_list in self.shelf_blades_dict.iteritems():
46 type, mgmt_ip, username, password = dea.get_shelf_info(shelf)
47 dha = DeploymentHardwareAdapter(type, mgmt_ip, username, password)
48 dha.power_off_blades(shelf, blade_list)
50 def power_on_blades(self, dea):
51 for shelf, blade_list in self.shelf_blades_dict.iteritems():
52 type, mgmt_ip, username, password = dea.get_shelf_info(shelf)
53 dha = DeploymentHardwareAdapter(type, mgmt_ip, username, password)
54 dha.power_on_blades(shelf, blade_list)
56 def set_boot_order(self, dea):
57 for shelf, blade_list in self.shelf_blades_dict.iteritems():
58 type, mgmt_ip, username, password = dea.get_shelf_info(shelf)
59 dha = DeploymentHardwareAdapter(type, mgmt_ip, username, password)
60 dha.set_boot_order_blades(shelf, blade_list)
62 def get_mac_addresses(self, dea, macs_yaml):
63 self.macs_per_shelf_dict = {}
64 for shelf, blade_list in self.shelf_blades_dict.iteritems():
65 type, mgmt_ip, username, password = dea.get_shelf_info(shelf)
66 dha = DeploymentHardwareAdapter(type, mgmt_ip, username, password)
67 self.macs_per_shelf_dict[shelf] = dha.get_blades_mac_addresses(
70 with io.open(macs_yaml, 'w') as stream:
71 yaml.dump(self.macs_per_shelf_dict, stream,
72 default_flow_style=False)
74 def collect_blade_ids_per_shelves(self, dea):
75 self.shelf_blades_dict = dea.get_blade_ids_per_shelves()
82 fuel_username = 'root'
83 fuel_password = 'r00tme'
84 deploy_dir = '~/cloud'
86 cloud = CloudDeploy(fuel_ip, fuel_username, fuel_password)
88 base_dir = os.path.dirname(os.path.realpath(__file__))
89 deployment_dir = base_dir + '/cloud'
90 macs_yaml = base_dir + '/macs.yaml'
91 dea_yaml = base_dir + '/dea.yaml'
92 check_file_exists(dea_yaml)
94 cloud.copy_to_fuel_master(dir_path=deployment_dir)
95 cloud.copy_to_fuel_master(file_path=dea_yaml, target=deploy_dir)
97 dea = DeploymentEnvironmentAdapter()
98 dea.parse_yaml(dea_yaml)
100 cloud.collect_blade_ids_per_shelves(dea)
102 cloud.power_off_blades(dea)
104 cloud.set_boot_order(dea)
106 cloud.power_on_blades(dea)
108 cloud.get_mac_addresses(dea, macs_yaml)
109 check_file_exists(dea_yaml)
111 cloud.copy_to_fuel_master(file_path=macs_yaml, target=deploy_dir)
113 cloud.run_cloud_deploy(deploy_dir, 'deploy.py')
116 if __name__ == '__main__':