diff options
author | 2015-05-04 12:11:29 +0200 | |
---|---|---|
committer | 2015-05-19 20:15:25 +0200 | |
commit | 945dca48c0b1fd93fec43513afb6680a8d828e33 (patch) | |
tree | 2023bf27393a7a1edd5a4b8178b5d20a63814bec /fuel/deploy/deploy_env.py | |
parent | 2debee7a4f97a6a9d90aa55877264b3c62e3e2df (diff) |
Autodeploy inspired on Prototype #2
- setup libvirt environment
- setup vfuel environment
- patch iso
- install Fuel Master
- deploy cloud
- hardware adapter for libvirt
- hardware adapter for ipmi
- hardware adapter for hp
- README: AutoDeploy instructions
JIRA: [BGS-2] Create Fuel deployment script
Change-Id: I862d824829baaae7d21115776d13355d575a47c8
Signed-off-by: Szilard Cserey <szilard.cserey@ericsson.com>
Diffstat (limited to 'fuel/deploy/deploy_env.py')
-rw-r--r-- | fuel/deploy/deploy_env.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/fuel/deploy/deploy_env.py b/fuel/deploy/deploy_env.py new file mode 100644 index 0000000..9bc8fbb --- /dev/null +++ b/fuel/deploy/deploy_env.py @@ -0,0 +1,87 @@ +import os +import io +import yaml +import glob + +from ssh_client import SSHClient +import common + +exec_cmd = common.exec_cmd +err = common.err +check_file_exists = common.check_file_exists +log = common.log + +CLOUD_DEPLOY_FILE = 'deploy.py' + + +class CloudDeploy(object): + + def __init__(self, dha, fuel_ip, fuel_username, fuel_password, dea_file, + work_dir): + self.dha = dha + self.fuel_ip = fuel_ip + self.fuel_username = fuel_username + self.fuel_password = fuel_password + self.dea_file = dea_file + self.work_dir = work_dir + self.file_dir = os.path.dirname(os.path.realpath(__file__)) + self.ssh = SSHClient(self.fuel_ip, self.fuel_username, + self.fuel_password) + self.macs_file = '%s/macs.yaml' % self.file_dir + self.node_ids = self.dha.get_node_ids() + + def upload_cloud_deployment_files(self): + dest ='~/%s/' % self.work_dir + + with self.ssh as s: + s.exec_cmd('rm -rf %s' % self.work_dir, check=False) + s.exec_cmd('mkdir ~/%s' % self.work_dir) + s.scp_put(self.dea_file, dest) + s.scp_put(self.macs_file, dest) + s.scp_put('%s/common.py' % self.file_dir, dest) + s.scp_put('%s/dea.py' % self.file_dir, dest) + for f in glob.glob('%s/cloud/*' % self.file_dir): + s.scp_put(f, dest) + + def power_off_nodes(self): + for node_id in self.node_ids: + self.dha.node_power_off(node_id) + + def power_on_nodes(self): + for node_id in self.node_ids: + self.dha.node_power_on(node_id) + + def set_boot_order(self, boot_order_list): + for node_id in self.node_ids: + self.dha.node_set_boot_order(node_id, boot_order_list) + + def get_mac_addresses(self): + macs_per_node = {} + for node_id in self.node_ids: + macs_per_node[node_id] = self.dha.get_node_pxe_mac(node_id) + with io.open(self.macs_file, 'w') as stream: + yaml.dump(macs_per_node, stream, default_flow_style=False) + + def run_cloud_deploy(self, deploy_app): + log('START CLOUD DEPLOYMENT') + deploy_app = '%s/%s' % (self.work_dir, deploy_app) + dea_file = '%s/%s' % (self.work_dir, os.path.basename(self.dea_file)) + macs_file = '%s/%s' % (self.work_dir, os.path.basename(self.macs_file)) + with self.ssh: + self.ssh.run('python %s %s %s' % (deploy_app, dea_file, macs_file)) + + def deploy(self): + + self.power_off_nodes() + + self.set_boot_order(['pxe', 'disk']) + + self.power_on_nodes() + + self.get_mac_addresses() + + check_file_exists(self.macs_file) + + self.upload_cloud_deployment_files() + + self.run_cloud_deploy(CLOUD_DEPLOY_FILE) |