Exemplo n.º 1
0
    def _get_path_by_region(self, region):
        absolute_cascading_patch_path = os.path.sep.join([utils.get_patches_tool_path(), PatchFilePath.PATCH_FOR_CASCADING])
        absolute_aws_proxy_patch_path = os.path.sep.join([utils.get_patches_tool_path(), PatchFilePath.PATCH_FOR_AWS_PROXY])
        absolute_vcloud_proxy_patch_path = os.path.sep.join([utils.get_patches_tool_path(), PatchFilePath.PATCH_FOR_VCLOUD_PROXY])

        if 'aws' in region:
            return absolute_aws_proxy_patch_path
        elif 'vcloud' in region:
            return absolute_vcloud_proxy_patch_path
        else:
            return absolute_cascading_patch_path
Exemplo n.º 2
0
    def _get_path_by_region(self, region):
        absolute_cascading_patch_path = os.path.sep.join(
            [utils.get_patches_tool_path(), PatchFilePath.PATCH_FOR_CASCADING])
        absolute_aws_proxy_patch_path = os.path.sep.join(
            [utils.get_patches_tool_path(), PatchFilePath.PATCH_FOR_AWS_PROXY])
        absolute_vcloud_proxy_patch_path = os.path.sep.join([
            utils.get_patches_tool_path(), PatchFilePath.PATCH_FOR_VCLOUD_PROXY
        ])

        if 'aws' in region:
            return absolute_aws_proxy_patch_path
        elif 'vcloud' in region:
            return absolute_vcloud_proxy_patch_path
        else:
            return absolute_cascading_patch_path
Exemplo n.º 3
0
    def _replace_neutron_l2_proxy_json(self, host_info):
        """
        TODO: to get host ip of proxies, and scp config file of json to these proxies.
        :return:
        """
        log.info('Start to replace neutron l2 proxy json in proxy nodes..')
        print('Start to replace neutron l2 proxy json..')
        for proxy in self.proxies:
            neutron_network_role = self._get_neutron_role_name(proxy)
            for host in host_info['hosts']:
                roles_list = host['roles']
                local_path_of_neutron_l2_proxy = os.path.join(
                    utils.get_patches_tool_path(),
                    CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                if neutron_network_role in roles_list:
                    proxy_host_ip = host['manageip']
                    log.info(
                        'Start remote copy neutron l2 proxy json to host: %s' %
                        proxy_host_ip)
                    try:
                        utils.remote_open_root_permit_for_host(proxy_host_ip)
                        ssh = SSHConnection(proxy_host_ip, SysUserInfo.ROOT,
                                            SysUserInfo.ROOT_PWD)
                        ssh.put(local_path_of_neutron_l2_proxy,
                                CfgFilePath.NEUTRON_L2_PROXY_PATH)
                        ssh.close()
                    except Exception, e:
                        log.error(
                            'Exception when remote copy neutron l2 proxy json to host: %s'
                            % proxy_host_ip)
                        log.error('Exception: %s' % traceback.format_exc())

                    log.info(
                        'Finish remote copy neutron l2 proxy json to host: %s'
                        % proxy_host_ip)
Exemplo n.º 4
0
    def _replace_neutron_l2_proxy_json(self, host_info):
        """
        TODO: to get host ip of proxies, and scp config file of json to these proxies.
        :return:
        """

        log.info('Start to replace neutron l2 proxy json in proxy nodes. self.proxies = %s' % self.proxies)
        log.info('Start to replace neutron l2 proxy json in proxy nodes. host_info = %s' % host_info)

        for proxy in self.proxies:
            log.info('Start to replace neutron l2 proxy json in proxy nodes. proxy = %s' % proxy)
            neutron_network_role = self._get_neutron_role_name(proxy)
            for host in host_info['hosts']:

                roles_list = host['roles']
                local_path_of_neutron_l2_proxy = os.path.join(
                    utils.get_patches_tool_path(), CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                if neutron_network_role in roles_list:
                    proxy_host_ip = host['manageip']
                    log.info('Start remote copy neutron l2 proxy json to host: %s' % proxy_host_ip)
                    try:
                        # utils.remote_open_root_permit_for_host(proxy_host_ip)
                        ssh = SSHConnection(proxy_host_ip, SysUserInfo.ROOT, SysUserInfo.ROOT_PWD)
                        ssh.put(local_path_of_neutron_l2_proxy, CfgFilePath.NEUTRON_L2_PROXY_PATH)
                        ssh.close()
                        log.info('Finish remote copy neutron l2 proxy json to host: %s' % proxy_host_ip)
                    except Exception, e:
                        log.error('Exception when remote copy neutron l2 proxy json to host: %s' % proxy_host_ip)
                        log.error('Exception: %s' % traceback.format_exc())
                    finally:
                        break
Exemplo n.º 5
0
    def tar_patches_tool(self):
        log.info('Start to tar patches_tool')
        patches_tool_path = utils.get_patches_tool_path()
        full_patch_of_patches_tool = os.path.join(patches_tool_path, SysPath.PATCHES_TOOL_TAR_GZ)
        if os.path.isfile(full_patch_of_patches_tool):
            self.remove_tar_patches_tool(full_patch_of_patches_tool)
        new_tar_of_patches_tool = os.path.join(patches_tool_path, SysPath.PATCHES_TOOL_TAR_GZ)
        utils.make_tarfile(new_tar_of_patches_tool, patches_tool_path)
        log.info('Success to tar patches_tool: <%s>' % full_patch_of_patches_tool)

        return full_patch_of_patches_tool
Exemplo n.º 6
0
    def config_big_l2_layer_in_proxy_node(self):
        host_list = None
        for i in range(3):
            try:
                host_list = RefCPSService.host_list()
                log.info("get host list success.")
                break
            except Exception as e:
                log.error("get host list error, try again. error: %s" % e.message)
                time.sleep(1)
                continue

        if host_list is None:
            log.error("config big l2 layer for proxies failed, get host list failed.")
            return False

        for proxy in self.proxies:
            # enable l2 remote port
            self.__enable_l2_remote_port_for_proxy__(proxy)

            # copy file
            host_id = self.proxy_match_host[proxy]
            host_ip = None
            for host in host_list["hosts"]:
                if host_id == host["id"]:
                    host_ip = host["manageip"]
                    break

            if host_ip is None:
                log.error("proxy not exist, proxy: %s, proxy id: %s" % (proxy, host_id))
                continue

            log.info('start to replace neutron l2 proxy json in proxy nodes. proxy: %s' % proxy)
            replace_result = False
            for i in range(3):
                try:
                    # utils.remote_open_root_permit_for_host(proxy_host_ip)
                    local_path_of_neutron_l2_proxy = os.path.join(
                        utils.get_patches_tool_path(),
                        CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                    ssh = SSHConnection(host_ip, SysUserInfo.ROOT, SysUserInfo.ROOT_PWD)
                    ssh.put(local_path_of_neutron_l2_proxy, CfgFilePath.NEUTRON_L2_PROXY_PATH)
                    ssh.close()
                    replace_result = True
                    log.info('replace neutron l2 proxy json success, proxy: %s' % proxy)
                    break
                except Exception, e:
                    log.error('replace neutron l2 proxy json error, try again, proxy: %s, error: %s' % (proxy, e.message))
                    time.sleep(1)
                    continue
                finally:
                    ssh.close()
Exemplo n.º 7
0
    def dispatch_patch_tool_to_host(self, host):
        path_of_patch_tool = utils.get_patches_tool_path()
        files_need_to_dispatch = utils.get_files(path_of_patch_tool, self.filter_for_dispatch)
        ssh = sshutils.SSH(host=host, user=SysUserInfo.FSP, password=SysUserInfo.FSP_PWD)
        try:
            for absolute_file, relative_path_of_file in files_need_to_dispatch:
                log.info('start to copy file <<%s>> to host <<%s>>' % (relative_path_of_file, host))
                file_copy_to = os.path.join(SysPath.HOME_FSP, SysPath.PATCHES_TOOL, relative_path_of_file)
                file_dir_copy_to = os.path.dirname(file_copy_to)
                ssh.run('mkdir -p %s' % file_dir_copy_to)
                ssh.put_file(absolute_file, file_copy_to)
                log.info('End to copy file <<%s>> to host <<%s>>' % (relative_path_of_file, host))

        except Exception, e:
            log.error('Exception occur when dispatch patches tool to host: <%s>, Exception: %s' % (host, traceback.format_exc()))
Exemplo n.º 8
0
    cfg.StrOpt(
        'OS_AUTH_URL',
        default="https://identity.cascading.hybrid.huawei.com:443/identity/v2.0"
    ),
    cfg.StrOpt('OS_USERNAME', default="cloud_admin"),
    cfg.StrOpt('OS_TENANT_NAME', default="admin"),
    cfg.StrOpt('NOVA_ENDPOINT_TYPE', default="publicURL"),
    cfg.StrOpt('CINDER_ENDPOINT_TYPE', default="publicURL"),
    cfg.StrOpt('OS_ENDPOINT_TYPE', default="publicURL"),
    cfg.StrOpt('OS_VOLUME_API_VERSION', default="2"),
    cfg.StrOpt('OS_PASSWORD', default=""),
]
CONF.register_group(env_group)
CONF.register_opts(env_opts, env_group)

absolute_config_file = os.path.join(utils.get_patches_tool_path(),
                                    FileName.PATCHES_TOOL_CONFIG_FILE)
CONF(['--config-file=%s' % absolute_config_file])


class ConfigCascading(object):
    def __init__(self):
        self.proxy_match_host = CONF.DEFAULT.proxy_match_host
        self.proxy_match_region = CONF.DEFAULT.proxy_match_region
        self.proxies = self.proxy_match_host.keys()
        self.current_proxy = CONF.DEFAULT.current_node

        # cascading.hybrid.huawei.com
        self.cascading_region = RefCPSService.get_local_domain()
        log.info('cascading region is: %s' % self.cascading_region)
        local_dc, local_az = RefFsUtils.get_local_dc_az()
Exemplo n.º 9
0
    def config_big_l2_layer_in_proxy_node(self):
        host_list = None
        for i in range(3):
            try:
                host_list = RefCPSService.host_list()
                log.info("get host list success.")
                break
            except Exception as e:
                log.error("get host list error, try again. error: %s" %
                          e.message)
                time.sleep(1)
                continue

        if host_list is None:
            log.error(
                "config big l2 layer for proxies failed, get host list failed."
            )
            return False

        for proxy in self.proxies:
            # enable l2 remote port
            self.__enable_l2_remote_port_for_proxy__(proxy)

            # copy file
            host_id = self.proxy_match_host[proxy]
            host_ip = None
            for host in host_list["hosts"]:
                if host_id == host["id"]:
                    host_ip = host["manageip"]
                    break

            if host_ip is None:
                log.error("proxy not exist, proxy: %s, proxy id: %s" %
                          (proxy, host_id))
                continue

            log.info(
                'start to replace neutron l2 proxy json in proxy nodes. proxy: %s'
                % proxy)
            replace_result = False
            for i in range(3):
                try:
                    # utils.remote_open_root_permit_for_host(proxy_host_ip)
                    local_path_of_neutron_l2_proxy = os.path.join(
                        utils.get_patches_tool_path(),
                        CfgFilePath.NEUTRON_L2_PROXY_PATH_TEMPLATE)
                    ssh = SSHConnection(host_ip, SysUserInfo.ROOT,
                                        SysUserInfo.ROOT_PWD)
                    ssh.put(local_path_of_neutron_l2_proxy,
                            CfgFilePath.NEUTRON_L2_PROXY_PATH)
                    ssh.close()
                    replace_result = True
                    log.info(
                        'replace neutron l2 proxy json success, proxy: %s' %
                        proxy)
                    break
                except Exception, e:
                    log.error(
                        'replace neutron l2 proxy json error, try again, proxy: %s, error: %s'
                        % (proxy, e.message))
                    time.sleep(1)
                    continue
                finally:
                    ssh.close()
Exemplo n.º 10
0
env_group = cfg.OptGroup(name='ENV',
                               title='environment for openstack')
env_opts = [
    cfg.StrOpt('OS_AUTH_URL', default="https://identity.cascading.hybrid.huawei.com:443/identity/v2.0"),
    cfg.StrOpt('OS_USERNAME', default="cloud_admin"),
    cfg.StrOpt('OS_TENANT_NAME', default="admin"),
    cfg.StrOpt('NOVA_ENDPOINT_TYPE', default="publicURL"),
    cfg.StrOpt('CINDER_ENDPOINT_TYPE', default="publicURL"),
    cfg.StrOpt('OS_ENDPOINT_TYPE', default="publicURL"),
    cfg.StrOpt('OS_VOLUME_API_VERSION', default="2"),
    cfg.StrOpt('OS_PASSWORD', default=""),
]
CONF.register_group(env_group)
CONF.register_opts(env_opts, env_group)

absolute_config_file = os.path.join(utils.get_patches_tool_path(), FileName.PATCHES_TOOL_CONFIG_FILE)
CONF(['--config-file=%s' % absolute_config_file])


class ConfigCascading(object):

    def __init__(self):
        self.proxy_match_host = CONF.DEFAULT.proxy_match_host
        self.proxy_match_region = CONF.DEFAULT.proxy_match_region
        self.proxies = self.proxy_match_host.keys()
        self.current_proxy = CONF.DEFAULT.current_node

        # cascading.hybrid.huawei.com
        self.cascading_region = RefCPSService.get_local_domain()
        log.info('cascading region is: %s' % self.cascading_region)
        local_dc, local_az = RefFsUtils.get_local_dc_az()