예제 #1
0
    def _add_proxy_role(self, host, role_name):
        """
        Commands used to add role for host:
        cps role-host-add --host  **  nova-proxy001
        cps commit

        Commands used to check if add successful:
        cps template-instance-list --service nova nova-proxy001
        If get proxy info, then it is add successfully, no mater the status of proxy is fault.
        :param role_name:
        :return:
        """
        log.info('Start to add proxy role in host: %s, for role: %s' %
                 (host, role_name))
        for i in range(3):
            try:
                add_result = RefCPSService.role_host_add(role_name, [host])
                RefCPSService.cps_commit()
                log.info('add proxy role success, host: %s, role: %s' %
                         (host, role_name))
                return True
            except Exception as e:
                log.error(
                    "add proxy role error, try again, host: %s, role: %s, exception: %s"
                    % (host, role_name, e.message))
                time.sleep(1)
                continue

        log.error('add proxy role error, host: %s, role: %s' %
                  (host, role_name))
        return False
예제 #2
0
    def _add_proxy_role(self, host, role_name):
        """
        Commands used to add role for host:
        cps role-host-add --host  **  nova-proxy001
        cps commit

        Commands used to check if add successful:
        cps template-instance-list --service nova nova-proxy001
        If get proxy info, then it is add successfully, no mater the status of proxy is fault.
        :param role_name:
        :return:
        """
        log.info('Start to add proxy role in host: %s, for role: %s' % (host, role_name))
        for i in range(3):
            try:
                add_result = RefCPSService.role_host_add(role_name, [host])
                RefCPSService.cps_commit()
                log.info('add proxy role success, host: %s, role: %s'
                         % (host, role_name))
                return True
            except Exception as e:
                log.error("add proxy role error, try again, host: %s, role: %s, exception: %s"
                          % (host, role_name, e.message))
                time.sleep(1)
                continue

        log.error('add proxy role error, host: %s, role: %s' % (host, role_name))
        return False
예제 #3
0
    def add_role_for_cascading_node(self):
        start_info = 'Start to add role for cascading node. Include: nova-api, nova-scheduler, neutron-server, loadbalancer'
        print(start_info)
        log.info(start_info)
        host_name_of_cascading_node = socket.gethostname()
        log.info("host_name_of_cascading_node = %s" % host_name_of_cascading_node)

        RefCPSService.role_host_add('nova-api', [host_name_of_cascading_node])
        RefCPSService.role_host_add('nova-scheduler', [host_name_of_cascading_node])
        RefCPSService.role_host_add('neutron-server', [host_name_of_cascading_node])
        RefCPSService.role_host_add('loadbalancer', [host_name_of_cascading_node])
        RefCPSService.cps_commit()
        finish_info = 'Finish to add role for cascading node. Include: nova-api, nova-scheduler, neutron-server, loadbalancer'

        print(finish_info)
        log.info(finish_info)
예제 #4
0
 def add_role_for_cascading_node(self):
     start_info = 'Start to add role for cascading node. Include: nova-api, nova-scheduler, neutron-server, loadbalancer'
     print(start_info)
     log.info(start_info)
     host_name_of_cascading_node = socket.gethostname()
     RefCPSService.role_host_add('nova-api', [host_name_of_cascading_node])
     RefCPSService.role_host_add('nova-scheduler',
                                 [host_name_of_cascading_node])
     RefCPSService.role_host_add('neutron-server',
                                 [host_name_of_cascading_node])
     RefCPSService.role_host_add('loadbalancer',
                                 [host_name_of_cascading_node])
     RefCPSService.cps_commit()
     finish_info = 'Finish to add role for cascading node. Include: nova-api, nova-scheduler, neutron-server, loadbalancer'
     print(finish_info)
     log.info(finish_info)
예제 #5
0
 def __update_template_params_for_proxy__(service, template_name, dict_params):
     for i in range(3):
         try:
             RefCPSService.update_template_params(service, template_name, dict_params)
             RefCPSService.cps_commit()
             log.info("update template params success, service: %s, template_name: %s"
                      % (service, template_name))
             time.sleep(1)
             return True
         except Exception as e:
             log.error("update template params error, try again, service: %s, template_name: %s, exception: %s"
                       % (service, template_name, e.message))
             time.sleep(1)
             continue
     log.error("update template params failed, service: %s, template_name: %s."
               % (service, template_name))
     return False
예제 #6
0
    def _add_proxy_role(self, host, role_name):
        """
        Commands used to add role for host:
        cps role-host-add --host  **  nova-proxy001
        cps commit

        Commands used to check if add successful:
        cps template-instance-list --service nova nova-proxy001
        If get proxy info, then it is add successfully, no mater the status of proxy is fault.
        :param role_name:
        :return:
        """
        log.info('Start to add proxy role in host: %s, for role: %s' %
                 (host, role_name))
        add_result = RefCPSService.role_host_add(role_name, [host])
        RefCPSService.cps_commit()
        log.info('Finish to add proxy role in host: %s, for role: %s' %
                 (host, role_name))
예제 #7
0
 def __enable_l2_remote_port_for_proxy__(proxy_name):
     service = 'neutron'
     # e.g. 'neutron-l2-proxy003'
     template = '-'.join(['neutron-l2', proxy_name])
     updated_params = {
         'remote_port_enabled': 'True'
     }
     for i in range(3):
         try:
             RefCPSService.update_template_params(service, template, updated_params)
             RefCPSService.cps_commit()
             log.info("enable l2 remote port success, proxy: %s" % proxy_name)
             return True
         except Exception as e:
             log.error("enable l2 remote port error, try again, proxy: %s, exception: %s"
                       % (proxy_name, e.message))
             time.sleep(1)
             continue
     log.error("enable l2 remote port failed, proxy: %s" % proxy_name)
     return False
예제 #8
0
    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()
        # cascading.hybrid
        self.cascading_os_region_name = '.'.join([local_az, local_dc])
예제 #9
0
 def __enable_l2_remote_port_for_proxy__(proxy_name):
     service = 'neutron'
     # e.g. 'neutron-l2-proxy003'
     template = '-'.join(['neutron-l2', proxy_name])
     updated_params = {'remote_port_enabled': 'True'}
     for i in range(3):
         try:
             RefCPSService.update_template_params(service, template,
                                                  updated_params)
             RefCPSService.cps_commit()
             log.info("enable l2 remote port success, proxy: %s" %
                      proxy_name)
             return True
         except Exception as e:
             log.error(
                 "enable l2 remote port error, try again, proxy: %s, exception: %s"
                 % (proxy_name, e.message))
             time.sleep(1)
             continue
     log.error("enable l2 remote port failed, proxy: %s" % proxy_name)
     return False
예제 #10
0
    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()
        # cascading.hybrid
        self.cascading_os_region_name = '.'.join([local_az, local_dc])
예제 #11
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()
예제 #12
0
 def patch_for_cascading_and_proxy_node(self):
     host_list = RefCPSService.host_list()
     for host in host_list['hosts']:
         roles_list = host['roles']
         proxy_host_ip = host['manageip']
         region = self._get_region_by_roles_list(roles_list)
         if region is not None:
             print('Start to patch for region - <%s>' % region)
             absolute_patch_path = self._get_path_by_region(region)
             PatchInstaller(absolute_patch_path, utils.get_openstack_installed_path(), ['.py'], proxy_host_ip).install()
             print('Finish to patch for region - <%s>' % region)
         else:
             print('Region of ip <%s> is None, can not patch for this proxy' % proxy_host_ip)
예제 #13
0
 def __update_template_params_for_proxy__(service, template_name,
                                          dict_params):
     for i in range(3):
         try:
             RefCPSService.update_template_params(service, template_name,
                                                  dict_params)
             RefCPSService.cps_commit()
             log.info(
                 "update template params success, service: %s, template_name: %s"
                 % (service, template_name))
             time.sleep(1)
             return True
         except Exception as e:
             log.error(
                 "update template params error, try again, service: %s, template_name: %s, exception: %s"
                 % (service, template_name, e.message))
             time.sleep(1)
             continue
     log.error(
         "update template params failed, service: %s, template_name: %s." %
         (service, template_name))
     return False
예제 #14
0
 def patch_for_cascading_and_proxy_node(self):
     host_list = RefCPSService.host_list()
     for host in host_list['hosts']:
         roles_list = host['roles']
         proxy_host_ip = host['manageip']
         region = self._get_region_by_roles_list(roles_list)
         if region is not None:
             print('Start to patch for region - <%s>' % region)
             absolute_patch_path = self._get_path_by_region(region)
             PatchInstaller(absolute_patch_path,
                            utils.get_openstack_installed_path(), ['.py'],
                            proxy_host_ip).install()
             print('Finish to patch for region - <%s>' % region)
         else:
             print(
                 'Region of ip <%s> is None, can not patch for this proxy' %
                 proxy_host_ip)
예제 #15
0
    def create_aggregate_in_cascaded_node(self):
        """
        nova aggregate-create az31.singapore--aws az31.singapore--aws
        nova host-list
        nova aggregate-add-host az31.singapore--aws 42114FD9-D446-9248-3A05-23CF474E3C68

        :return:
        """
        ref_service = RefServices()
        host_id = socket.gethostname()
        region = RefCPSService.get_local_domain()
        os_region_name = '.'.join([RefFsSystemUtils.get_az_by_domain(region), RefFsSystemUtils.get_dc_by_domain(region)])
        if not ref_service.nova_aggregate_exist(os_region_name, os_region_name):
            create_result = ref_service.nova_aggregate_create(os_region_name, os_region_name)
            if create_result is not None:
                ref_service.nova_aggregate_add_host(create_result, host_id)
        print('Success to create region<%s> for host<%s>' % (os_region_name, host_id))
예제 #16
0
    def create_aggregate_in_cascaded_node(self):
        """
        nova aggregate-create az31.singapore--aws az31.singapore--aws
        nova host-list
        nova aggregate-add-host az31.singapore--aws 42114FD9-D446-9248-3A05-23CF474E3C68

        :return:
        """
        ref_service = RefServices()
        host_id = socket.gethostname()
        region = RefCPSService.get_local_domain()
        os_region_name = '.'.join([
            RefFsSystemUtils.get_az_by_domain(region),
            RefFsSystemUtils.get_dc_by_domain(region)
        ])
        if not ref_service.nova_aggregate_exist(os_region_name,
                                                os_region_name):
            create_result = ref_service.nova_aggregate_create(
                os_region_name, os_region_name)
            if create_result is not None:
                ref_service.nova_aggregate_add_host(create_result, host_id)
        print('Success to create region<%s> for host<%s>' %
              (os_region_name, host_id))
예제 #17
0
 def _commit_config(self):
     RefCPSService.cps_commit()
예제 #18
0
    def _update_template_params_for_proxy(self, service, template_name,
                                          dict_params):
        result = RefCPSService.update_template_params(service, template_name,
                                                      dict_params)

        return result
예제 #19
0
 def config_big_l2_layer_in_proxy_node(self):
     self._config_big_l2_layer_in_proxy(self.current_proxy)
     host_list = RefCPSService.host_list()
     if host_list is not None:
         self._replace_neutron_l2_proxy_json(host_list)
예제 #20
0
 def _commit_config(self):
     RefCPSService.cps_commit()
예제 #21
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()