6 from dha import DeploymentHardwareAdapter
7 from dea import DeploymentEnvironmentAdapter
8 from configure_environment import ConfigureEnvironment
11 SUPPORTED_RELEASE = 'Juno on CentOS 6.5'
17 exec_cmd = common.exec_cmd
23 def __init__(self, yaml_config_dir):
24 self.supported_release = None
25 self.yaml_config_dir = yaml_config_dir
27 def get_id_list(self, list):
28 return [l[0] for l in list]
30 def cleanup_fuel_environments(self, env_list):
33 id_list = self.get_id_list(env_list)
35 exec_cmd('fuel env --env %s --delete' % id)
36 for i in range(WAIT_LOOP):
37 if id in self.get_id_list(parse(exec_cmd('fuel env list'))):
38 time.sleep(SLEEP_TIME)
42 def cleanup_fuel_nodes(self, node_list):
43 for node in node_list:
44 if node[N['status']] == 'discover':
45 exec_cmd('fuel node --node-id %s --delete-from-db'
47 exec_cmd('dockerctl shell cobbler cobbler system remove '
48 '--name node-%s' % node[N['id']])
50 def check_previous_installation(self):
51 env_list = parse(exec_cmd('fuel env list'))
53 self.cleanup_fuel_environments(env_list)
54 node_list = parse(exec_cmd('fuel node list'))
56 self.cleanup_fuel_nodes(node_list)
58 def check_supported_release(self):
59 release_list= parse(exec_cmd('fuel release -l'))
60 for release in release_list:
61 if release[R['name']] == SUPPORTED_RELEASE:
62 self.supported_release = release
64 if not self.supported_release:
65 err("This Fuel doesn't contain the following "
66 "release: %s\n" % SUPPORTED_RELEASE)
68 def check_role_definitions(self):
69 role_list= parse(exec_cmd('fuel role --release %s'
70 % self.supported_release[R['id']]))
71 roles = [role[RO['name']] for role in role_list]
72 if 'compute' not in roles:
73 err("Role compute does not exist in release %"
74 % self.supported_release[R['name']])
75 if 'controller' not in roles:
76 err("Role controller does not exist in release %"
77 % self.supported_release[R['name']])
79 def check_prerequisites(self):
80 self.check_supported_release()
81 self.check_role_definitions()
82 self.check_previous_installation()
84 def power_off_blades(self, dha, shelf_blades_dict):
85 for shelf, blade_list in shelf_blades_dict.iteritems():
86 dha.power_off_blades(shelf, blade_list)
88 def power_on_blades(self, dha, shelf_blades_dict):
89 for shelf, blade_list in shelf_blades_dict.iteritems():
90 dha.power_on_blades(shelf, blade_list)
92 def set_boot_order(self, dha, shelf_blades_dict):
93 for shelf, blade_list in shelf_blades_dict.iteritems():
94 dha.set_boot_order_blades(shelf, blade_list)
96 def count_discovered_nodes(self, node_list):
98 for node in node_list:
99 if node[N['status']] == 'discover':
100 discovered_nodes += 1
101 return discovered_nodes
103 def wait_for_discovered_blades(self, no_of_blades):
106 all_discovered = False
107 node_list = parse(exec_cmd('fuel node list'))
108 for i in range(WAIT_LOOP):
109 if (self.count_discovered_nodes(node_list) < no_of_blades):
110 time.sleep(SLEEP_TIME)
111 node_list = parse(exec_cmd('fuel node list'))
113 all_discovered = True
115 if not all_discovered:
116 err("There are %s blades defined, but not all of "
117 "them have been discovered\n" % no_of_blades)
119 def assign_cluster_node_ids(self, dha, dea, controllers, compute_hosts):
120 node_list= parse(exec_cmd('fuel node list'))
121 for shelf_id in dea.get_shelf_ids():
122 for blade_id in dea.get_blade_ids_per_shelf(shelf_id):
123 blade_mac_list = dha.get_blade_mac_addresses(
127 for node in node_list:
128 if (node[N['mac']] in blade_mac_list and
129 node[N['status']] == 'discover'):
133 if dea.is_controller(shelf_id, blade_id):
134 controllers.append(node[N['id']])
135 if dea.is_compute_host(shelf_id, blade_id):
136 compute_hosts.append(node[N['id']])
138 err("Could not find the Node ID for blade "
139 "with MACs %s or blade is not in "
140 "discover status\n" % blade_mac_list)
143 def configure_environment(self, dea):
144 config_env = ConfigureEnvironment(dea, self.yaml_config_dir)
152 def fix_power_address(self):
159 if id in self.get_id_list(parse(exec_cmd('fuel env list'))):
161 self.fix_power_address()
168 yaml_path = exec_cmd('pwd').strip() + '/dea.yaml'
169 yaml_config_dir = '/var/lib/opnfv/pre_deploy'
171 deploy = Deploy(yaml_config_dir)
173 dea = DeploymentEnvironmentAdapter()
175 if not os.path.isfile(yaml_path):
176 sys.stderr.write("ERROR: File %s not found\n" % yaml_path)
179 dea.parse_yaml(yaml_path)
181 server_type, mgmt_ip, username, password = dea.get_server_info()
182 shelf_blades_dict = dea.get_blade_ids_per_shelves()
184 dha = DeploymentHardwareAdapter(server_type, mgmt_ip, username, password)
186 deploy.check_prerequisites()
188 deploy.power_off_blades(dha, shelf_blades_dict)
190 deploy.set_boot_order(dha, shelf_blades_dict)
192 deploy.power_on_blades(dha, shelf_blades_dict)
194 macs = dha.get_blade_mac_addresses()
196 deploy.wait_for_discovered_blades(dea.get_no_of_blades())
201 deploy.assign_cluster_node_ids(dha, dea, controllers, compute_hosts)
205 deploy.configure_environment(dea)
211 if __name__ == '__main__':