当前位置: 首页>>代码示例>>Python>>正文


Python vnc_api.VncApi类代码示例

本文整理汇总了Python中vnc_api.vnc_api.VncApi的典型用法代码示例。如果您正苦于以下问题:Python VncApi类的具体用法?Python VncApi怎么用?Python VncApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了VncApi类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: restart_dhcp_server

 def restart_dhcp_server(cls, file_name, fabric_name, job_ctx):
     vnc_api = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
                      auth_token=job_ctx.get('auth_token'))
     headers = {
         'fabric_name': fabric_name,
         'file_name': file_name,
         'action': 'delete'
     }
     vnc_api.amqp_publish(exchange=cls.ZTP_EXCHANGE,
         exchange_type=cls.ZTP_EXCHANGE_TYPE,
         routing_key=cls.ZTP_REQUEST_ROUTING_KEY, headers=headers,
         payload={})
     return { 'status': 'success' }
开发者ID:Juniper,项目名称:contrail-controller,代码行数:13,代码来源:ztp_filters.py

示例2: _publish_file

 def _publish_file(cls, name, contents, action, routing_key,
                   fabric_name, job_ctx):
     vnc_api = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
                      auth_token=job_ctx.get('auth_token'))
     headers = {
         'fabric_name': fabric_name,
         'file_name': name,
         'action': action
     }
     vnc_api.amqp_publish(exchange=cls.ZTP_EXCHANGE,
         exchange_type=cls.ZTP_EXCHANGE_TYPE,
         routing_key=routing_key, headers=headers,
         payload=contents)
     return { 'status': 'success' }
开发者ID:Juniper,项目名称:contrail-controller,代码行数:14,代码来源:ztp_filters.py

示例3: __init__

    def __init__(self):
        admin_user = cfg.CONF.keystone_authtoken.admin_user
        admin_password = cfg.CONF.keystone_authtoken.admin_password
        admin_tenant_name = cfg.CONF.keystone_authtoken.admin_tenant_name
        api_srvr_ip = cfg.CONF.APISERVER.api_server_ip
        api_srvr_port = cfg.CONF.APISERVER.api_server_port
        api_srvr_use_ssl= cfg.CONF.APISERVER.use_ssl
        try:
            auth_host = cfg.CONF.keystone_authtoken.auth_host
        except cfg.NoSuchOptError:
            auth_host = "127.0.0.1"

        try:
            auth_protocol = cfg.CONF.keystone_authtoken.auth_protocol
        except cfg.NoSuchOptError:
            auth_protocol = "http"

        try:
            auth_port = cfg.CONF.keystone_authtoken.auth_port
        except cfg.NoSuchOptError:
            auth_port = "35357"

        try:
            auth_url = cfg.CONF.keystone_authtoken.auth_url
        except cfg.NoSuchOptError:
            auth_url = "/v2.0/tokens"

        try:
            auth_type = cfg.CONF.keystone_authtoken.auth_type
        except cfg.NoSuchOptError:
            auth_type = "keystone"

        try:
            api_server_url = cfg.CONF.APISERVER.api_server_url
        except cfg.NoSuchOptError:
            api_server_url = "/"

        # Retry till a api-server is up
        connected = False
        while not connected:
            try:
                self._api = VncApi(admin_user, admin_password, admin_tenant_name,
                                   api_srvr_ip, api_srvr_port, api_server_url,
                                   auth_host=auth_host, auth_port=auth_port,
                                   auth_protocol=auth_protocol, auth_url=auth_url,
                                   auth_type=auth_type, wait_for_connect=True,
                                   api_server_use_ssl=api_srvr_use_ssl)
                connected = True
            except requests.exceptions.RequestException:
                time.sleep(3)

        self._pool_manager = \
            loadbalancer_pool.LoadbalancerPoolManager(self._api)
        self._vip_manager = virtual_ip.VirtualIpManager(self._api)
        self._member_manager = \
            loadbalancer_member.LoadbalancerMemberManager(self._api)
        self._monitor_manager = \
            loadbalancer_healthmonitor.LoadbalancerHealthmonitorManager(
                self._api)
开发者ID:tcpcloud,项目名称:contrail-neutron-plugin,代码行数:59,代码来源:loadbalancer_db.py

示例4: read_dhcp_leases

 def read_dhcp_leases(cls, ipam_subnets, file_name, fabric_name, job_ctx,
                      payload_key, payload_value, action='create'):
     vnc_api = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
                      auth_token=job_ctx.get('auth_token'))
     headers = {
         'fabric_name': fabric_name,
         'file_name': file_name,
         'action': action
     }
     payload = {
         'ipam_subnets': ipam_subnets
     }
     payload[payload_key] = payload_value
     return vnc_api.amqp_request(exchange=cls.ZTP_EXCHANGE,
         exchange_type=cls.ZTP_EXCHANGE_TYPE,
         routing_key=cls.ZTP_REQUEST_ROUTING_KEY,
         response_key=cls.ZTP_RESPONSE_ROUTING_KEY + fabric_name,
         headers=headers, payload=payload)
开发者ID:Juniper,项目名称:contrail-controller,代码行数:18,代码来源:ztp_filters.py

示例5: __init__

 def __init__(self, user, passwd, project_name, inputs, domain='default-domain'):
     self.inputs = inputs
     self.user = user
     self.passwd = passwd
     self.domain = domain
     self.project_name = project_name
     self.vnc = VncApi(username=user, password=passwd,
                       tenant_name=project_name,
                       api_server_host=self.inputs.cfgm_ip,
                       api_server_port=self.inputs.api_server_port)
开发者ID:aswanikumar90,项目名称:contrail-test,代码行数:10,代码来源:vcenter.py

示例6: get_ztp_dhcp_config

    def get_ztp_dhcp_config(cls, job_ctx, fabric_uuid):
        dhcp_config = {}
        try:
            vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
                            auth_token=job_ctx.get('auth_token'))
            fabric = vncapi.fabric_read(id=fabric_uuid)
            fabric_dict = vncapi.obj_to_dict(fabric)

            # From here we get the 'management' type virtual network
            vn_uuid = None
            virtual_network_refs = fabric_dict.get('virtual_network_refs') or []
            for virtual_net_ref in virtual_network_refs:
                if 'management' in virtual_net_ref['attr']['network_type']:
                    vn_uuid = virtual_net_ref['uuid']
                    break
            if vn_uuid is None:
                raise NoIdError("Cannot find mgmt virtual network on fabric")

            virtual_net = vncapi.virtual_network_read(id=vn_uuid)
            virtual_net_dict = vncapi.obj_to_dict(virtual_net)

            # Get the IPAM attached to the virtual network
            ipam_refs = virtual_net_dict.get('network_ipam_refs')
            if ipam_refs:
                ipam_ref = ipam_refs[0]
                ipam = vncapi.network_ipam_read(id=ipam_ref['uuid'])
                ipam_dict = vncapi.obj_to_dict(ipam)
                ipam_subnets = ipam_dict.get('ipam_subnets')
                if ipam_subnets:
                    dhcp_config['ipam_subnets'] = ipam_subnets.get('subnets')

            # Get static ip configuration for physical routers
            pr_refs = fabric.get_physical_router_back_refs()
            pr_uuids = [ref['uuid'] for ref in pr_refs]
            static_ips = {}
            for pr_uuid in pr_uuids:
                pr = vncapi.physical_router_read(id=pr_uuid)
                pr_dict = vncapi.obj_to_dict(pr)
                mac = pr_dict.get('physical_router_management_mac')
                ip = pr_dict.get('physical_router_management_ip')
                if mac and ip:
                    static_ips[ip] = mac
            if static_ips:
                dhcp_config['static_ips'] = static_ips
        except Exception as ex:
            logging.error("Error getting ZTP DHCP configuration: {}".format(ex))

        return dhcp_config
开发者ID:Juniper,项目名称:contrail-controller,代码行数:48,代码来源:ztp_filters.py

示例7: __init__

 def __init__(self):
     # TODO: parse configuration for api-server:port and auth
     self._api = VncApi()
     self._pool_manager = \
         loadbalancer_pool.LoadbalancerPoolManager(self._api)
     self._vip_manager = virtual_ip.VirtualIpManager(self._api)
     self._member_manager = \
         loadbalancer_member.LoadbalancerMemberManager(self._api)
     self._monitor_manager = \
         loadbalancer_healthmonitor.LoadbalancerHealthmonitorManager(
             self._api)
开发者ID:achanda,项目名称:contrail-neutron-plugin,代码行数:11,代码来源:loadbalancer_db.py

示例8: get_pr_subnet

    def get_pr_subnet(cls, job_ctx, fabric_uuid, device_fq_name):
        api = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
                     auth_token=job_ctx.get('auth_token'))
        fabric = api.fabric_read(id=fabric_uuid)
        fabric_dict = api.obj_to_dict(fabric)

        vn_uuid = None
        virtual_network_refs = fabric_dict.get('virtual_network_refs') or []
        for virtual_net_ref in virtual_network_refs:
            if 'management' in virtual_net_ref['attr']['network_type']:
                vn_uuid = virtual_net_ref['uuid']
                break
        if vn_uuid is None:
            raise NoIdError("Cannot find mgmt virtual network on fabric")

        virtual_net = api.virtual_network_read(id=vn_uuid)
        virtual_net_dict = api.obj_to_dict(virtual_net)

        subnets = None
        ipam_refs = virtual_net_dict.get('network_ipam_refs')
        if ipam_refs:
            ipam_ref = ipam_refs[0]
            ipam = api.network_ipam_read(id=ipam_ref['uuid'])
            ipam_dict = api.obj_to_dict(ipam)
            ipam_subnets = ipam_dict.get('ipam_subnets')
            if ipam_subnets:
                subnets = ipam_subnets.get('subnets')

        gateway = None
        cidr = None
        if subnets:
            pr = api.physical_router_read(fq_name=device_fq_name)
            pr_dict = api.obj_to_dict(pr)
            ip = pr_dict.get('physical_router_management_ip')
            ip_addr = IPAddress(ip)
            for subnet in subnets:
                inner_subnet = subnet.get('subnet')
                cidr = inner_subnet.get('ip_prefix') + '/' + str(inner_subnet.get('ip_prefix_len'))
                if ip_addr in IPNetwork(cidr) and subnet.get('default_gateway'):
                    gateway = subnet.get('default_gateway')
                    break
        if cidr and gateway:
            return { 'cidr': cidr, 'gateway': gateway }

        raise Error("Cannot find cidr and gateway for device: %s" % str(device_fq_name))
开发者ID:Juniper,项目名称:contrail-controller,代码行数:45,代码来源:physical_router_filters.py

示例9: get_ztp_tftp_config

    def get_ztp_tftp_config(cls, job_ctx, fabric_uuid):
        tftp_config = {}
        try:
            vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
                            auth_token=job_ctx.get('auth_token'))
            fabric = vncapi.fabric_read(id=fabric_uuid)
            fabric_dict = vncapi.obj_to_dict(fabric)
            fabric_creds = fabric_dict.get('fabric_credentials')
            if fabric_creds:
                device_creds = fabric_creds.get('device_credential')
                if device_creds:
                    dev_cred = device_creds[0]
                    password = JobVncApi.decrypt_password(
                        encrypted_password=dev_cred['credential']['password'],
                        admin_password=job_ctx.get(
                            'vnc_api_init_params').get(
                            'admin_password'))
                    tftp_config['password'] = password
        except Exception as ex:
            logging.error("Error getting ZTP TFTP configuration: {}".format(ex))

        return tftp_config
开发者ID:Juniper,项目名称:contrail-controller,代码行数:22,代码来源:ztp_filters.py

示例10: __init__

 def __init__(self):
     admin_user = cfg.CONF.keystone_authtoken.admin_user
     admin_password = cfg.CONF.keystone_authtoken.admin_password
     admin_tenant_name = cfg.CONF.keystone_authtoken.admin_tenant_name
     api_srvr_ip = cfg.CONF.APISERVER.api_server_ip
     api_srvr_port = cfg.CONF.APISERVER.api_server_port
     self._api = VncApi(admin_user, admin_password, admin_tenant_name,
                        api_srvr_ip, api_srvr_port,api_auth_protocol="https")
     self._pool_manager = \
         loadbalancer_pool.LoadbalancerPoolManager(self._api)
     self._vip_manager = virtual_ip.VirtualIpManager(self._api)
     self._member_manager = \
         loadbalancer_member.LoadbalancerMemberManager(self._api)
     self._monitor_manager = \
         loadbalancer_healthmonitor.LoadbalancerHealthmonitorManager(
             self._api)
开发者ID:CodeWire,项目名称:Standup-a-3-node-OpenStack-HA-Controller-Cluster-with-Contrail-SDN,代码行数:16,代码来源:loadbalancer_db.py

示例11: main

def main():
    client=VncApi()
    virtual_networks=client.virtual_networks_list()
    virtual_machine_interfaces=client.virtual_machine_interfaces_list()
    virtual_machines=client.virtual_machines_list()
    instance_ips=client.instance_ips_list()
    projects=client.projects_list()
    domains=client.domains_list()
    floating_ip_pools=client.floating_ip_pools_list()
    access_control_lists=client.access_control_lists_list()
    print domains
    for project in projects['projects']:
        id=project['uuid']
        name=project['fq_name']
        print id,name
    print projects
    print virtual_networks
    print virtual_machine_interfaces
    print virtual_machines
    print instance_ips
    print  access_control_lists
    print  floating_ip_pools
开发者ID:Doude,项目名称:contrail-installer,代码行数:22,代码来源:test_domainlist.py

示例12: __init__

    def __init__(self, cfg, name):
        if cfg is None:
            raise KeyError("Missing required args: cfg")
        if name is None:
            raise KeyError("Missing required args: name")

        self._name = name
        self._timeout = cfg['wait_for_job']['timeout']
        self._max_retries = cfg['wait_for_job']['max_retries']
        self._logger = SanityBase._init_logging(cfg['log'], name)
        self._api_server = cfg['api_server']
        self._analytics = cfg['analytics']
        self._api = VncApi(
            api_server_host=self._api_server['host'],
            api_server_port=self._api_server['port'],
            username=self._api_server['username'],
            password=self._api_server['password'],
            tenant_name=self._api_server['tenant'])
开发者ID:Juniper,项目名称:contrail-controller,代码行数:18,代码来源:sanity_base.py

示例13: VcenterAuth

class VcenterAuth(OrchestratorAuth):

    def __init__(self, user, passwd, project_name, inputs, domain='default-domain'):
        self.inputs = inputs
        self.user = user
        self.passwd = passwd
        self.domain = domain
        self.project_name = project_name
        use_ssl = self.inputs.api_protocol == 'https'
        self.vnc = VncApi(username=user, password=passwd,
                          tenant_name=project_name,
                          api_server_host=self.inputs.cfgm_ip,
                          api_server_port=self.inputs.api_server_port,
                          api_server_use_ssl=use_ssl)

    def get_project_id(self, project_name=None, domain_id=None):
       if not project_name:
           project_name = self.project_name
       fq_name = [unicode(self.domain), unicode(project_name)]
       obj = self.vnc.project_read(fq_name=fq_name)
       if obj:
           return obj.get_uuid()
       return None

    def reauth(self):
        raise Exception('Unimplemented interface')

    def create_project(self, name):
        raise Exception('Unimplemented interface')

    def delete_project(self, name):
        raise Exception('Unimplemented interface')

    def create_user(self, user, passwd):
        raise Exception('Unimplemented interface')

    def delete_user(self, user):
        raise Exception('Unimplemented interface')

    def add_user_to_project(self, user, project):
        raise Exception('Unimplemented interface')
开发者ID:Ankitja,项目名称:contrail-test,代码行数:41,代码来源:vcenter.py

示例14: get_ztp_config

    def get_ztp_config(cls, job_ctx, fabric_uuid):
        ztp_config = {}
        try:
            vncapi = VncApi(auth_type=VncApi._KEYSTONE_AUTHN_STRATEGY,
                            auth_token=job_ctx.get('auth_token'))
            fabric = vncapi.fabric_read(id=fabric_uuid)
            fabric_dict = vncapi.obj_to_dict(fabric)
            fabric_creds = fabric_dict.get('fabric_credentials')
            if fabric_creds:
                device_creds = fabric_creds.get('device_credential')
                if device_creds:
                    dev_cred = device_creds[0]
                    ztp_config['password'] = dev_cred['credential']['password']

            # From here we get the 'management' type virtual network
            vn_uuid = None
            virtual_network_refs = fabric_dict.get('virtual_network_refs') or []
            for virtual_net_ref in virtual_network_refs:
                if "management" in virtual_net_ref['attr']['network_type']:
                    vn_uuid = virtual_net_ref['uuid']
                    break
            if vn_uuid is None:
                raise NoIdError("Cannot find mgmt virtual network on fabric")

            virtual_net = vncapi.virtual_network_read(id=vn_uuid)
            virtual_net_dict = vncapi.obj_to_dict(virtual_net)

            # Get the IPAM attached to the virtual network
            ipam_refs = virtual_net_dict.get('network_ipam_refs')
            if ipam_refs:
                ipam_ref = ipam_refs[0]
                ipam = vncapi.network_ipam_read(id=ipam_ref['uuid'])
                ipam_dict = vncapi.obj_to_dict(ipam)
                ipam_subnets = ipam_dict.get('ipam_subnets')
                if ipam_subnets:
                    ztp_config['ipam_subnets'] = ipam_subnets.get('subnets')
        except NoIdError:
            logging.error("Cannot find mgmt virtual network")
        except Exception as ex:
            logging.error("Error getting ZTP configuration: {}".format(ex))

        return ztp_config
开发者ID:rombie,项目名称:contrail-controller,代码行数:42,代码来源:ztp_filters.py

示例15: SanityBase

class SanityBase(object):
    """Base class for fabric ansible sanity tests"""

    @staticmethod
    def _init_logging(cfg, name):
        logger = logging.getLogger('sanity_test')
        logger.setLevel(cfg['level'])

        file_handler = logging.FileHandler(
            '%s/fabric_ansibile_%s.log' % (cfg['file']['dir'], name), mode='w')
        file_handler.setLevel(cfg['file']['level'])
        console_handler = logging.StreamHandler()
        console_handler.setLevel(cfg['console'])

        formatter = logging.Formatter(
            '%(asctime)s %(levelname)-8s %(message)s',
            datefmt='%Y/%m/%d %H:%M:%S')
        file_handler.setFormatter(formatter)
        console_handler.setFormatter(formatter)
        logger.addHandler(file_handler)
        logger.addHandler(console_handler)

        return logger
    # end _init_logging

    def test(self):
        """Override this method in the derived class"""
        pass

    def __init__(self, cfg, name):
        if cfg is None:
            raise KeyError("Missing required args: cfg")
        if name is None:
            raise KeyError("Missing required args: name")

        self._name = name
        self._timeout = cfg['wait_for_job']['timeout']
        self._max_retries = cfg['wait_for_job']['max_retries']
        self._logger = SanityBase._init_logging(cfg['log'], name)
        self._api_server = cfg['api_server']
        self._analytics = cfg['analytics']
        self._api = VncApi(
            api_server_host=self._api_server['host'],
            api_server_port=self._api_server['port'],
            username=self._api_server['username'],
            password=self._api_server['password'],
            tenant_name=self._api_server['tenant'])
    # end __init__

    def create_fabric(self, fab_name, prouter_passwords):
        """create fabric with list of device passwords"""
        self._logger.info('Creating fabric: %s', fab_name)
        fq_name = ['default-global-system-config', fab_name]
        fab = Fabric(
            name=fab_name,
            fq_name=fq_name,
            parent_type='global-system-config',
            fabric_credentials={
                'device_credential': [{
                    'credential': {
                        'username': 'root', 'password': passwd
                    },
                    'vendor': 'Juniper',
                    'device_family': None
                } for passwd in prouter_passwords]
            }
        )
        try:
            fab_uuid = self._api.fabric_create(fab)
            fab = self._api.fabric_read(id=fab_uuid)
        except RefsExistError:
            self._logger.warn("Fabric '%s' already exists", fab_name)
            fab = self._api.fabric_read(fq_name=fq_name)

        self._logger.debug(
            "Fabric created:\n%s",
            pprint.pformat(self._api.obj_to_dict(fab), indent=4))
        return fab
    # end _create_fabric

    def add_mgmt_ip_namespace(self, fab, name, cidrs):
        """add management ip prefixes as fabric namespace"""
        ns_name = 'mgmt_ip-' + name
        self._logger.info(
            'Adding management ip namespace "%s" to fabric "%s" ...',
            ns_name, fab.name)

        subnets = []
        for cidr in cidrs:
            ip_prefix = cidr.split('/')
            subnets.append({
                'ip_prefix': ip_prefix[0],
                'ip_prefix_len': ip_prefix[1]
            })
        ns_fq_name = fab.fq_name + [ns_name]
        namespace = FabricNamespace(
            name=ns_name,
            fq_name=ns_fq_name,
            parent_type='fabric',
            fabric_namespace_type='IPV4-CIDR',
#.........这里部分代码省略.........
开发者ID:Juniper,项目名称:contrail-controller,代码行数:101,代码来源:sanity_base.py


注:本文中的vnc_api.vnc_api.VncApi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。