예제 #1
0
파일: deploy.py 프로젝트: baigk/genesis
class AutoDeploy(object):

    def __init__(self, without_fuel, iso_file, dea_file, dha_file):
        self.without_fuel = without_fuel
        self.iso_file = iso_file
        self.dea_file = dea_file
        self.dha_file = dha_file
        self.dea = DeploymentEnvironmentAdapter(dea_file)
        self.dha = DeploymentHardwareAdapter(dha_file)
        self.fuel_conf = {}
        self.fuel_node_id = self.dha.get_fuel_node_id()
        self.fuel_custom = self.dha.use_fuel_custom_install()
        self.fuel_username, self.fuel_password = self.dha.get_fuel_access()

    def setup_dir(self, dir):
        self.cleanup_dir(dir)
        os.makedirs(dir)

    def cleanup_dir(self, dir):
        if os.path.isdir(dir):
            shutil.rmtree(dir)

    def power_off_blades(self):
        node_ids = self.dha.get_all_node_ids()
        node_ids = list(set(node_ids) - set([self.fuel_node_id]))
        for node_id in node_ids:
            self.dha.node_power_off(node_id)

    def modify_ip(self, ip_addr, index, val):
        ip_str = str(netaddr.IPAddress(ip_addr))
        decimal_list = map(int, ip_str.split('.'))
        decimal_list[index] = val
        return '.'.join(map(str, decimal_list))

    def collect_fuel_info(self):
        self.fuel_conf['ip'] = self.dea.get_fuel_ip()
        self.fuel_conf['gw'] = self.dea.get_fuel_gateway()
        self.fuel_conf['dns1'] = self.dea.get_fuel_dns()
        self.fuel_conf['netmask'] = self.dea.get_fuel_netmask()
        self.fuel_conf['hostname'] = self.dea.get_fuel_hostname()
        self.fuel_conf['showmenu'] = 'yes'

    def install_fuel_master(self):
        if self.without_fuel:
            log('Not Installing Fuel Master')
            return
        log('Install Fuel Master')
        new_iso = '%s/deploy-%s' % (TMP_DIR, os.path.basename(self.iso_file))
        self.patch_iso(new_iso)
        self.iso_file = new_iso
        self.install_iso()

    def install_iso(self):
        fuel = InstallFuelMaster(self.dea_file, self.dha_file,
                                 self.fuel_conf['ip'], self.fuel_username,
                                 self.fuel_password, self.fuel_node_id,
                                 self.iso_file, WORK_DIR)
        if self.fuel_custom:
            log('Custom Fuel install')
            fuel.custom_install()
        else:
            log('Ordinary Fuel install')
            fuel.install()

    def patch_iso(self, new_iso):
        tmp_orig_dir = '%s/origiso' % TMP_DIR
        tmp_new_dir = '%s/newiso' % TMP_DIR
        self.copy(tmp_orig_dir, tmp_new_dir)
        self.patch(tmp_new_dir, new_iso)

    def copy(self, tmp_orig_dir, tmp_new_dir):
        log('Copying...')
        self.setup_dir(tmp_orig_dir)
        self.setup_dir(tmp_new_dir)
        exec_cmd('fuseiso %s %s' % (self.iso_file, tmp_orig_dir))
        with cd(tmp_orig_dir):
            exec_cmd('find . | cpio -pd %s' % tmp_new_dir)
        with cd(tmp_new_dir):
            exec_cmd('fusermount -u %s' % tmp_orig_dir)
        shutil.rmtree(tmp_orig_dir)
        exec_cmd('chmod -R 755 %s' % tmp_new_dir)

    def patch(self, tmp_new_dir, new_iso):
        log('Patching...')
        patch_dir = '%s/%s' % (os.getcwd(), PATCH_DIR)
        ks_path = '%s/ks.cfg.patch' % patch_dir

        with cd(tmp_new_dir):
            exec_cmd('cat %s | patch -p0' % ks_path)
            shutil.rmtree('.rr_moved')
            isolinux = 'isolinux/isolinux.cfg'
            log('isolinux.cfg before: %s'
                % exec_cmd('grep netmask %s' % isolinux))
            self.update_fuel_isolinux(isolinux)
            log('isolinux.cfg after: %s'
                % exec_cmd('grep netmask %s' % isolinux))

            iso_linux_bin = 'isolinux/isolinux.bin'
            exec_cmd('mkisofs -quiet -r -J -R -b %s '
                     '-no-emul-boot -boot-load-size 4 '
                     '-boot-info-table -hide-rr-moved '
                     '-x "lost+found:" -o %s .'
                     % (iso_linux_bin, new_iso))

    def update_fuel_isolinux(self, file):
        with io.open(file) as f:
            data = f.read()
        for key, val in self.fuel_conf.iteritems():
            pattern = r'%s=[^ ]\S+' % key
            replace = '%s=%s' % (key, val)
            data = re.sub(pattern, replace, data)
        with io.open(file, 'w') as f:
            f.write(data)

    def deploy_env(self):
        dep = CloudDeploy(self.dha, self.fuel_conf['ip'], self.fuel_username,
                          self.fuel_password, self.dea_file, WORK_DIR)
        dep.deploy()

    def deploy(self):
        check_if_root()
        self.setup_dir(TMP_DIR)
        self.collect_fuel_info()
        self.power_off_blades()
        self.install_fuel_master()
        self.cleanup_dir(TMP_DIR)
        self.deploy_env()
예제 #2
0
class AutoDeploy(object):
    def __init__(self, no_fuel, fuel_only, no_health_check, cleanup_only,
                 cleanup, storage_dir, pxe_bridge, iso_file, dea_file,
                 dha_file, fuel_plugins_dir, fuel_plugins_conf_dir, no_plugins,
                 deploy_timeout, no_deploy_environment, deploy_log):
        self.no_fuel = no_fuel
        self.fuel_only = fuel_only
        self.no_health_check = no_health_check
        self.cleanup_only = cleanup_only
        self.cleanup = cleanup
        self.storage_dir = storage_dir
        self.pxe_bridge = pxe_bridge
        self.iso_file = iso_file
        self.dea_file = dea_file
        self.dha_file = dha_file
        self.fuel_plugins_dir = fuel_plugins_dir
        self.fuel_plugins_conf_dir = fuel_plugins_conf_dir
        self.no_plugins = no_plugins
        self.deploy_timeout = deploy_timeout
        self.no_deploy_environment = no_deploy_environment
        self.deploy_log = deploy_log
        self.dea = (DeploymentEnvironmentAdapter(dea_file)
                    if not cleanup_only else None)
        self.dha = DeploymentHardwareAdapter(dha_file)
        self.fuel_conf = {}
        self.fuel_node_id = self.dha.get_fuel_node_id()
        self.fuel_username, self.fuel_password = self.dha.get_fuel_access()
        self.tmp_dir = None

    def modify_ip(self, ip_addr, index, val):
        ip_str = str(netaddr.IPAddress(ip_addr))
        decimal_list = map(int, ip_str.split('.'))
        decimal_list[index] = val
        return '.'.join(map(str, decimal_list))

    def collect_fuel_info(self):
        self.fuel_conf['ip'] = self.dea.get_fuel_ip()
        self.fuel_conf['gw'] = self.dea.get_fuel_gateway()
        self.fuel_conf['dns1'] = self.dea.get_fuel_dns()
        self.fuel_conf['netmask'] = self.dea.get_fuel_netmask()
        self.fuel_conf['hostname'] = self.dea.get_fuel_hostname()
        self.fuel_conf['showmenu'] = 'yes'

    def install_fuel_master(self):
        log('Install Fuel Master')
        new_iso = ('%s/deploy-%s' %
                   (self.tmp_dir, os.path.basename(self.iso_file)))
        self.patch_iso(new_iso)
        self.iso_file = new_iso
        self.install_iso()

    def delete_old_fuel_env(self):
        log('Delete old Fuel Master environments if present')
        try:
            old_dep = CloudDeploy(self.dea, self.dha, self.fuel_conf['ip'],
                                  self.fuel_username, self.fuel_password,
                                  self.dea_file, self.fuel_plugins_conf_dir,
                                  WORK_DIR, self.no_health_check,
                                  self.deploy_timeout,
                                  self.no_deploy_environment, self.deploy_log)
            with old_dep.ssh:
                old_dep.check_previous_installation()
        except Exception as e:
            log('Could not delete old env: %s' % str(e))

    def install_iso(self):
        fuel = InstallFuelMaster(self.dea_file, self.dha_file,
                                 self.fuel_conf['ip'], self.fuel_username,
                                 self.fuel_password, self.fuel_node_id,
                                 self.iso_file, WORK_DIR,
                                 self.fuel_plugins_dir, self.no_plugins)
        fuel.install()

    def patch_iso(self, new_iso):
        tmp_orig_dir = '%s/origiso' % self.tmp_dir
        tmp_new_dir = '%s/newiso' % self.tmp_dir
        try:
            self.copy(tmp_orig_dir, tmp_new_dir)
            self.patch(tmp_new_dir, new_iso)
        except Exception as e:
            exec_cmd('fusermount -u %s' % tmp_orig_dir, False)
            os.environ.pop(MOUNT_STATE_VAR, None)
            delete(self.tmp_dir)
            err(e)

    def copy(self, tmp_orig_dir, tmp_new_dir):
        log('Copying...')
        os.makedirs(tmp_orig_dir)
        os.makedirs(tmp_new_dir)
        exec_cmd('fuseiso %s %s' % (self.iso_file, tmp_orig_dir))
        os.environ[MOUNT_STATE_VAR] = tmp_orig_dir
        with cd(tmp_orig_dir):
            exec_cmd('find . | cpio -pd %s' % tmp_new_dir)
        exec_cmd('fusermount -u %s' % tmp_orig_dir)
        os.environ.pop(MOUNT_STATE_VAR, None)
        delete(tmp_orig_dir)
        exec_cmd('chmod -R 755 %s' % tmp_new_dir)

    def patch(self, tmp_new_dir, new_iso):
        log('Patching...')
        patch_dir = '%s/%s' % (CWD, PATCH_DIR)
        ks_path = '%s/ks.cfg.patch' % patch_dir

        with cd(tmp_new_dir):
            exec_cmd('cat %s | patch -p0' % ks_path)
            delete('.rr_moved')
            isolinux = 'isolinux/isolinux.cfg'
            log('isolinux.cfg before: %s' % exec_cmd('grep ip= %s' % isolinux))
            self.update_fuel_isolinux(isolinux)
            log('isolinux.cfg after: %s' % exec_cmd('grep ip= %s' % isolinux))

            iso_label = self.parse_iso_volume_label(self.iso_file)
            log('Volume label: %s' % iso_label)

            iso_linux_bin = 'isolinux/isolinux.bin'
            exec_cmd('mkisofs -quiet -r -J -R -b %s '
                     '-no-emul-boot -boot-load-size 4 '
                     '-boot-info-table -hide-rr-moved '
                     '-joliet-long '
                     '-x "lost+found:" -V %s -o %s .' %
                     (iso_linux_bin, iso_label, new_iso))

        delete(tmp_new_dir)

    def update_fuel_isolinux(self, file):
        with io.open(file) as f:
            data = f.read()
        for key, val in self.fuel_conf.iteritems():
            # skip replacing these keys, as the format is different
            if key in ['ip', 'gw', 'netmask', 'hostname']:
                continue

            pattern = r'%s=[^ ]\S+' % key
            replace = '%s=%s' % (key, val)
            data = re.sub(pattern, replace, data)

        # process networking parameters
        ip = ':'.join([
            self.fuel_conf['ip'], '', self.fuel_conf['gw'],
            self.fuel_conf['netmask'], self.fuel_conf['hostname'],
            'eth0:off:::'
        ])

        data = re.sub(r'ip=[^ ]\S+', 'ip=%s' % ip, data)

        with io.open(file, 'w') as f:
            f.write(data)

    def parse_iso_volume_label(self, iso_filename):
        label_line = exec_cmd('isoinfo -d -i %s | grep -i "Volume id: "' %
                              iso_filename)
        # cut leading text: 'Volume id: '
        return label_line[11:]

    def deploy_env(self):
        dep = CloudDeploy(self.dea, self.dha, self.fuel_conf['ip'],
                          self.fuel_username, self.fuel_password,
                          self.dea_file, self.fuel_plugins_conf_dir, WORK_DIR,
                          self.no_health_check, self.deploy_timeout,
                          self.no_deploy_environment, self.deploy_log)
        return dep.deploy()

    def setup_execution_environment(self):
        exec_env = ExecutionEnvironment(self.storage_dir, self.pxe_bridge,
                                        self.dha_file, self.dea)
        exec_env.setup_environment()

    def cleanup_execution_environment(self):
        exec_env = ExecutionEnvironment(self.storage_dir, self.pxe_bridge,
                                        self.dha_file, self.dea)
        exec_env.cleanup_environment()

    def create_tmp_dir(self):
        self.tmp_dir = '%s/fueltmp' % CWD
        delete(self.tmp_dir)
        create_dir_if_not_exists(self.tmp_dir)

    def deploy(self):
        self.collect_fuel_info()
        if not self.no_fuel:
            self.delete_old_fuel_env()
            self.setup_execution_environment()
            self.create_tmp_dir()
            self.install_fuel_master()
        if not self.fuel_only:
            return self.deploy_env()
        # Exit status
        return 0

    def run(self):
        check_if_root()
        if self.cleanup_only:
            self.cleanup_execution_environment()
        else:
            deploy_success = self.deploy()
            if self.cleanup:
                self.cleanup_execution_environment()
            return deploy_success
        # Exit status
        return 0
예제 #3
0
class AutoDeploy(object):

    def __init__(self, no_fuel, fuel_only, no_health_check, cleanup_only,
                 cleanup, storage_dir, pxe_bridge, iso_file, dea_file,
                 dha_file, fuel_plugins_dir, fuel_plugins_conf_dir,
                 no_plugins):
        self.no_fuel = no_fuel
        self.fuel_only = fuel_only
        self.no_health_check = no_health_check
        self.cleanup_only = cleanup_only
        self.cleanup = cleanup
        self.storage_dir = storage_dir
        self.pxe_bridge = pxe_bridge
        self.iso_file = iso_file
        self.dea_file = dea_file
        self.dha_file = dha_file
        self.fuel_plugins_dir = fuel_plugins_dir
        self.fuel_plugins_conf_dir = fuel_plugins_conf_dir
        self.no_plugins = no_plugins
        self.dea = (DeploymentEnvironmentAdapter(dea_file)
                    if not cleanup_only else None)
        self.dha = DeploymentHardwareAdapter(dha_file)
        self.fuel_conf = {}
        self.fuel_node_id = self.dha.get_fuel_node_id()
        self.fuel_username, self.fuel_password = self.dha.get_fuel_access()
        self.tmp_dir = None

    def modify_ip(self, ip_addr, index, val):
        ip_str = str(netaddr.IPAddress(ip_addr))
        decimal_list = map(int, ip_str.split('.'))
        decimal_list[index] = val
        return '.'.join(map(str, decimal_list))

    def collect_fuel_info(self):
        self.fuel_conf['ip'] = self.dea.get_fuel_ip()
        self.fuel_conf['gw'] = self.dea.get_fuel_gateway()
        self.fuel_conf['dns1'] = self.dea.get_fuel_dns()
        self.fuel_conf['netmask'] = self.dea.get_fuel_netmask()
        self.fuel_conf['hostname'] = self.dea.get_fuel_hostname()
        self.fuel_conf['showmenu'] = 'yes'

    def install_fuel_master(self):
        log('Install Fuel Master')
        new_iso = ('%s/deploy-%s'
                   % (self.tmp_dir, os.path.basename(self.iso_file)))
        self.patch_iso(new_iso)
        self.iso_file = new_iso
        self.install_iso()

    def install_iso(self):
        fuel = InstallFuelMaster(self.dea_file, self.dha_file,
                                 self.fuel_conf['ip'], self.fuel_username,
                                 self.fuel_password, self.fuel_node_id,
                                 self.iso_file, WORK_DIR,
                                 self.fuel_plugins_dir, self.no_plugins)
        fuel.install()

    def patch_iso(self, new_iso):
        tmp_orig_dir = '%s/origiso' % self.tmp_dir
        tmp_new_dir = '%s/newiso' % self.tmp_dir
        try:
            self.copy(tmp_orig_dir, tmp_new_dir)
            self.patch(tmp_new_dir, new_iso)
        except Exception as e:
            exec_cmd('fusermount -u %s' % tmp_orig_dir, False)
            delete(self.tmp_dir)
            err(e)

    def copy(self, tmp_orig_dir, tmp_new_dir):
        log('Copying...')
        os.makedirs(tmp_orig_dir)
        os.makedirs(tmp_new_dir)
        exec_cmd('fuseiso %s %s' % (self.iso_file, tmp_orig_dir))
        with cd(tmp_orig_dir):
            exec_cmd('find . | cpio -pd %s' % tmp_new_dir)
        exec_cmd('fusermount -u %s' % tmp_orig_dir)
        delete(tmp_orig_dir)
        exec_cmd('chmod -R 755 %s' % tmp_new_dir)

    def patch(self, tmp_new_dir, new_iso):
        log('Patching...')
        patch_dir = '%s/%s' % (CWD, PATCH_DIR)
        ks_path = '%s/ks.cfg.patch' % patch_dir

        with cd(tmp_new_dir):
            exec_cmd('cat %s | patch -p0' % ks_path)
            delete('.rr_moved')
            isolinux = 'isolinux/isolinux.cfg'
            log('isolinux.cfg before: %s'
                % exec_cmd('grep netmask %s' % isolinux))
            self.update_fuel_isolinux(isolinux)
            log('isolinux.cfg after: %s'
                % exec_cmd('grep netmask %s' % isolinux))

            iso_linux_bin = 'isolinux/isolinux.bin'
            exec_cmd('mkisofs -quiet -r -J -R -b %s '
                     '-no-emul-boot -boot-load-size 4 '
                     '-boot-info-table -hide-rr-moved '
                     '-x "lost+found:" -o %s .'
                     % (iso_linux_bin, new_iso))

    def update_fuel_isolinux(self, file):
        with io.open(file) as f:
            data = f.read()
        for key, val in self.fuel_conf.iteritems():
            pattern = r'%s=[^ ]\S+' % key
            replace = '%s=%s' % (key, val)
            data = re.sub(pattern, replace, data)
        with io.open(file, 'w') as f:
            f.write(data)

    def deploy_env(self):
        dep = CloudDeploy(self.dea, self.dha, self.fuel_conf['ip'],
                          self.fuel_username, self.fuel_password,
                          self.dea_file, self.fuel_plugins_conf_dir,
                          WORK_DIR, self.no_health_check)
        return dep.deploy()

    def setup_execution_environment(self):
        exec_env = ExecutionEnvironment(self.storage_dir, self.pxe_bridge,
                                        self.dha_file, self.dea)
        exec_env.setup_environment()

    def cleanup_execution_environment(self):
        exec_env = ExecutionEnvironment(self.storage_dir, self.pxe_bridge,
                                        self.dha_file, self.dea)
        exec_env.cleanup_environment()

    def create_tmp_dir(self):
        self.tmp_dir = '%s/fueltmp' % CWD
        delete(self.tmp_dir)
        create_dir_if_not_exists(self.tmp_dir)

    def deploy(self):
        self.collect_fuel_info()
        if not self.no_fuel:
            self.setup_execution_environment()
            self.create_tmp_dir()
            self.install_fuel_master()
        if not self.fuel_only:
            return self.deploy_env()
        return True

    def run(self):
        check_if_root()
        if self.cleanup_only:
            self.cleanup_execution_environment()
        else:
            deploy_success = self.deploy()
            if self.cleanup:
                self.cleanup_execution_environment()
            return deploy_success
        return True
예제 #4
0
class AutoDeploy(object):

    def __init__(self, no_fuel, fuel_only, no_health_check, cleanup_only,
                 cleanup, storage_dir, pxe_bridge, iso_file, dea_file,
                 dha_file, fuel_plugins_dir, fuel_plugins_conf_dir,
                 no_plugins, deploy_timeout, no_deploy_environment):
        self.no_fuel = no_fuel
        self.fuel_only = fuel_only
        self.no_health_check = no_health_check
        self.cleanup_only = cleanup_only
        self.cleanup = cleanup
        self.storage_dir = storage_dir
        self.pxe_bridge = pxe_bridge
        self.iso_file = iso_file
        self.dea_file = dea_file
        self.dha_file = dha_file
        self.fuel_plugins_dir = fuel_plugins_dir
        self.fuel_plugins_conf_dir = fuel_plugins_conf_dir
        self.no_plugins = no_plugins
        self.deploy_timeout = deploy_timeout
        self.no_deploy_environment = no_deploy_environment
        self.dea = (DeploymentEnvironmentAdapter(dea_file)
                    if not cleanup_only else None)
        self.dha = DeploymentHardwareAdapter(dha_file)
        self.fuel_conf = {}
        self.fuel_node_id = self.dha.get_fuel_node_id()
        self.fuel_username, self.fuel_password = self.dha.get_fuel_access()
        self.tmp_dir = None

    def modify_ip(self, ip_addr, index, val):
        ip_str = str(netaddr.IPAddress(ip_addr))
        decimal_list = map(int, ip_str.split('.'))
        decimal_list[index] = val
        return '.'.join(map(str, decimal_list))

    def collect_fuel_info(self):
        self.fuel_conf['ip'] = self.dea.get_fuel_ip()
        self.fuel_conf['gw'] = self.dea.get_fuel_gateway()
        self.fuel_conf['dns1'] = self.dea.get_fuel_dns()
        self.fuel_conf['netmask'] = self.dea.get_fuel_netmask()
        self.fuel_conf['hostname'] = self.dea.get_fuel_hostname()
        self.fuel_conf['showmenu'] = 'yes'

    def install_fuel_master(self):
        log('Install Fuel Master')
        new_iso = ('%s/deploy-%s'
                   % (self.tmp_dir, os.path.basename(self.iso_file)))
        self.patch_iso(new_iso)
        self.iso_file = new_iso
        self.install_iso()

    def install_iso(self):
        fuel = InstallFuelMaster(self.dea_file, self.dha_file,
                                 self.fuel_conf['ip'], self.fuel_username,
                                 self.fuel_password, self.fuel_node_id,
                                 self.iso_file, WORK_DIR,
                                 self.fuel_plugins_dir, self.no_plugins)
        fuel.install()

    def patch_iso(self, new_iso):
        tmp_orig_dir = '%s/origiso' % self.tmp_dir
        tmp_new_dir = '%s/newiso' % self.tmp_dir
        try:
            self.copy(tmp_orig_dir, tmp_new_dir)
            self.patch(tmp_new_dir, new_iso)
        except Exception as e:
            exec_cmd('fusermount -u %s' % tmp_orig_dir, False)
            os.environ.pop(MOUNT_STATE_VAR, None)
            delete(self.tmp_dir)
            err(e)

    def copy(self, tmp_orig_dir, tmp_new_dir):
        log('Copying...')
        os.makedirs(tmp_orig_dir)
        os.makedirs(tmp_new_dir)
        exec_cmd('fuseiso %s %s' % (self.iso_file, tmp_orig_dir))
        os.environ[MOUNT_STATE_VAR] = tmp_orig_dir
        with cd(tmp_orig_dir):
            exec_cmd('find . | cpio -pd %s' % tmp_new_dir)
        exec_cmd('fusermount -u %s' % tmp_orig_dir)
        os.environ.pop(MOUNT_STATE_VAR, None)
        delete(tmp_orig_dir)
        exec_cmd('chmod -R 755 %s' % tmp_new_dir)

    def patch(self, tmp_new_dir, new_iso):
        log('Patching...')
        patch_dir = '%s/%s' % (CWD, PATCH_DIR)
        ks_path = '%s/ks.cfg.patch' % patch_dir

        with cd(tmp_new_dir):
            exec_cmd('cat %s | patch -p0' % ks_path)
            delete('.rr_moved')
            isolinux = 'isolinux/isolinux.cfg'
            log('isolinux.cfg before: %s'
                % exec_cmd('grep ip= %s' % isolinux))
            self.update_fuel_isolinux(isolinux)
            log('isolinux.cfg after: %s'
                % exec_cmd('grep ip= %s' % isolinux))

            iso_label = self.parse_iso_volume_label(self.iso_file)
            log('Volume label: %s' % iso_label)

            iso_linux_bin = 'isolinux/isolinux.bin'
            exec_cmd('mkisofs -quiet -r -J -R -b %s '
                     '-no-emul-boot -boot-load-size 4 '
                     '-boot-info-table -hide-rr-moved '
                     '-x "lost+found:" -V %s -o %s .'
                     % (iso_linux_bin, iso_label, new_iso))

    def update_fuel_isolinux(self, file):
        with io.open(file) as f:
            data = f.read()
        for key, val in self.fuel_conf.iteritems():
            # skip replacing these keys, as the format is different
            if key in ['ip', 'gw', 'netmask', 'hostname']:
                continue

            pattern = r'%s=[^ ]\S+' % key
            replace = '%s=%s' % (key, val)
            data = re.sub(pattern, replace, data)

        # process networking parameters
        ip = ':'.join([self.fuel_conf['ip'],
                      '',
                      self.fuel_conf['gw'],
                      self.fuel_conf['netmask'],
                      self.fuel_conf['hostname'],
                      'eth0:off:::'])

        data = re.sub(r'ip=[^ ]\S+', 'ip=%s' % ip, data)

        with io.open(file, 'w') as f:
            f.write(data)

    def parse_iso_volume_label(self, iso_filename):
        label_line = exec_cmd('isoinfo -d -i %s | grep -i "Volume id: "' % iso_filename)
        # cut leading text: 'Volume id: '
        return label_line[11:]

    def deploy_env(self):
        dep = CloudDeploy(self.dea, self.dha, self.fuel_conf['ip'],
                          self.fuel_username, self.fuel_password,
                          self.dea_file, self.fuel_plugins_conf_dir,
                          WORK_DIR, self.no_health_check, self.deploy_timeout,
                          self.no_deploy_environment)
        return dep.deploy()

    def setup_execution_environment(self):
        exec_env = ExecutionEnvironment(self.storage_dir, self.pxe_bridge,
                                        self.dha_file, self.dea)
        exec_env.setup_environment()

    def cleanup_execution_environment(self):
        exec_env = ExecutionEnvironment(self.storage_dir, self.pxe_bridge,
                                        self.dha_file, self.dea)
        exec_env.cleanup_environment()

    def create_tmp_dir(self):
        self.tmp_dir = '%s/fueltmp' % CWD
        delete(self.tmp_dir)
        create_dir_if_not_exists(self.tmp_dir)

    def deploy(self):
        self.collect_fuel_info()
        if not self.no_fuel:
            self.setup_execution_environment()
            self.create_tmp_dir()
            self.install_fuel_master()
        if not self.fuel_only:
            return self.deploy_env()
        # Exit status
        return 0

    def run(self):
        check_if_root()
        if self.cleanup_only:
            self.cleanup_execution_environment()
        else:
            deploy_success = self.deploy()
            if self.cleanup:
                self.cleanup_execution_environment()
            return deploy_success
        # Exit status
        return 0