當前位置: 首頁>>代碼示例>>Python>>正文


Python VPC.router_for_vpc方法代碼示例

本文整理匯總了Python中heat.engine.resources.vpc.VPC.router_for_vpc方法的典型用法代碼示例。如果您正苦於以下問題:Python VPC.router_for_vpc方法的具體用法?Python VPC.router_for_vpc怎麽用?Python VPC.router_for_vpc使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在heat.engine.resources.vpc.VPC的用法示例。


在下文中一共展示了VPC.router_for_vpc方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _neutron_add_gateway_router

# 需要導入模塊: from heat.engine.resources.vpc import VPC [as 別名]
# 或者: from heat.engine.resources.vpc.VPC import router_for_vpc [as 別名]
 def _neutron_add_gateway_router(self, float_id, network_id):
     router = VPC.router_for_vpc(self.neutron(), network_id)
     if router is not None:
         floatingip = self.neutron().show_floatingip(float_id)
         floating_net_id = \
             floatingip['floatingip']['floating_network_id']
         self.neutron().add_gateway_router(
             router['id'], {'network_id': floating_net_id})
開發者ID:andrew2king,項目名稱:heat,代碼行數:10,代碼來源:eip.py

示例2: handle_create

# 需要導入模塊: from heat.engine.resources.vpc import VPC [as 別名]
# 或者: from heat.engine.resources.vpc.VPC import router_for_vpc [as 別名]
    def handle_create(self):
        """Add a floating IP address to a server."""
        if self.properties[self.EIP] is not None \
                and self.properties[self.ALLOCATION_ID] is not None:
                    raise exception.ResourcePropertyConflict(
                        self.EIP,
                        self.ALLOCATION_ID)

        if self.properties[self.EIP]:
            if not self.properties[self.INSTANCE_ID]:
                logger.warn(_('Skipping association, InstanceId not '
                            'specified'))
                return
            server = self.nova().servers.get(self.properties[self.INSTANCE_ID])
            server.add_floating_ip(self.properties[self.EIP])
            self.resource_id_set(self.properties[self.EIP])
            logger.debug(_('ElasticIpAssociation '
                           '%(instance)s.add_floating_ip(%(eip)s)'),
                         {'instance': self.properties[self.INSTANCE_ID],
                          'eip': self.properties[self.EIP]})
        elif self.properties[self.ALLOCATION_ID]:
            assert clients.neutronclient, "Neutron required for VPC operations"
            port_id = None
            port_rsrc = None
            if self.properties[self.NETWORK_INTERFACE_ID]:
                port_id = self.properties[self.NETWORK_INTERFACE_ID]
                port_rsrc = self.neutron().list_ports(id=port_id)['ports'][0]
            elif self.properties[self.INSTANCE_ID]:
                instance_id = self.properties[self.INSTANCE_ID]
                ports = self.neutron().list_ports(device_id=instance_id)
                port_rsrc = ports['ports'][0]
                port_id = port_rsrc['id']
            else:
                logger.warn(_('Skipping association, resource not specified'))
                return

            float_id = self.properties[self.ALLOCATION_ID]
            self.resource_id_set(float_id)

            # assuming only one fixed_ip
            subnet_id = port_rsrc['fixed_ips'][0]['subnet_id']
            subnets = self.neutron().list_subnets(id=subnet_id)
            subnet_rsrc = subnets['subnets'][0]
            netid = subnet_rsrc['network_id']

            router = VPC.router_for_vpc(self.neutron(), netid)
            if router is not None:
                floatingip = self.neutron().show_floatingip(float_id)
                floating_net_id = \
                    floatingip['floatingip']['floating_network_id']
                self.neutron().add_gateway_router(
                    router['id'], {'network_id': floating_net_id})

            self.neutron().update_floatingip(
                float_id, {'floatingip': {'port_id': port_id}})
開發者ID:arimus,項目名稱:heat,代碼行數:57,代碼來源:eip.py

示例3: handle_create

# 需要導入模塊: from heat.engine.resources.vpc import VPC [as 別名]
# 或者: from heat.engine.resources.vpc.VPC import router_for_vpc [as 別名]
    def handle_create(self):
        """Add a floating IP address to a server."""
        if self.properties['EIP'] is not None \
                and self.properties['AllocationId'] is not None:
                    raise exception.ResourcePropertyConflict('EIP',
                                                             'AllocationId')

        if self.properties['EIP']:
            if not self.properties['InstanceId']:
                logger.warn(_('Skipping association, InstanceId not '
                            'specified'))
                return
            server = self.nova().servers.get(self.properties['InstanceId'])
            server.add_floating_ip(self.properties['EIP'])
            self.resource_id_set(self.properties['EIP'])
            logger.debug('ElasticIpAssociation %s.add_floating_ip(%s)' %
                         (self.properties['InstanceId'],
                          self.properties['EIP']))
        elif self.properties['AllocationId']:
            assert clients.neutronclient, "Neutron required for VPC operations"
            port_id = None
            port_rsrc = None
            if self.properties['NetworkInterfaceId']:
                port_id = self.properties['NetworkInterfaceId']
                port_rsrc = self.neutron().list_ports(id=port_id)['ports'][0]
            elif self.properties['InstanceId']:
                instance_id = self.properties['InstanceId']
                ports = self.neutron().list_ports(device_id=instance_id)
                port_rsrc = ports['ports'][0]
                port_id = port_rsrc['id']
            else:
                logger.warn(_('Skipping association, resource not specified'))
                return

            float_id = self.properties['AllocationId']
            self.resource_id_set(float_id)

            # assuming only one fixed_ip
            subnet_id = port_rsrc['fixed_ips'][0]['subnet_id']
            subnets = self.neutron().list_subnets(id=subnet_id)
            subnet_rsrc = subnets['subnets'][0]
            netid = subnet_rsrc['network_id']

            router = VPC.router_for_vpc(self.neutron(), netid)
            if router is not None:
                floatingip = self.neutron().show_floatingip(float_id)
                floating_net_id = \
                    floatingip['floatingip']['floating_network_id']
                self.neutron().add_gateway_router(
                    router['id'], {'network_id': floating_net_id})

            self.neutron().update_floatingip(
                float_id, {'floatingip': {'port_id': port_id}})
開發者ID:cmukai,項目名稱:heat,代碼行數:55,代碼來源:eip.py

示例4: handle_create

# 需要導入模塊: from heat.engine.resources.vpc import VPC [as 別名]
# 或者: from heat.engine.resources.vpc.VPC import router_for_vpc [as 別名]
    def handle_create(self):
        """Add a floating IP address to a server."""
        if self.properties[self.EIP] is not None and self.properties[self.ALLOCATION_ID] is not None:
            raise exception.ResourcePropertyConflict(self.EIP, self.ALLOCATION_ID)

        if self.properties[self.EIP]:
            if not self.properties[self.INSTANCE_ID]:
                LOG.warn(_("Skipping association, InstanceId not specified"))
                return
            server = self.nova().servers.get(self.properties[self.INSTANCE_ID])
            server.add_floating_ip(self.properties[self.EIP])
            self.resource_id_set(self.properties[self.EIP])
            LOG.debug(
                "ElasticIpAssociation " "%(instance)s.add_floating_ip(%(eip)s)",
                {"instance": self.properties[self.INSTANCE_ID], "eip": self.properties[self.EIP]},
            )
        elif self.properties[self.ALLOCATION_ID]:
            assert clients.neutronclient, "Neutron required for VPC operations"
            port_id = None
            port_rsrc = None
            if self.properties[self.NETWORK_INTERFACE_ID]:
                port_id = self.properties[self.NETWORK_INTERFACE_ID]
                port_rsrc = self.neutron().list_ports(id=port_id)["ports"][0]
            elif self.properties[self.INSTANCE_ID]:
                instance_id = self.properties[self.INSTANCE_ID]
                ports = self.neutron().list_ports(device_id=instance_id)
                port_rsrc = ports["ports"][0]
                port_id = port_rsrc["id"]
            else:
                LOG.warn(_("Skipping association, resource not specified"))
                return

            float_id = self.properties[self.ALLOCATION_ID]
            self.resource_id_set(float_id)

            # assuming only one fixed_ip
            subnet_id = port_rsrc["fixed_ips"][0]["subnet_id"]
            subnets = self.neutron().list_subnets(id=subnet_id)
            subnet_rsrc = subnets["subnets"][0]
            netid = subnet_rsrc["network_id"]

            router = VPC.router_for_vpc(self.neutron(), netid)
            if router is not None:
                floatingip = self.neutron().show_floatingip(float_id)
                floating_net_id = floatingip["floatingip"]["floating_network_id"]
                self.neutron().add_gateway_router(router["id"], {"network_id": floating_net_id})

            self.neutron().update_floatingip(float_id, {"floatingip": {"port_id": port_id}})
開發者ID:nttdata-osscloud,項目名稱:heat,代碼行數:50,代碼來源:eip.py

示例5: check_create_complete

# 需要導入模塊: from heat.engine.resources.vpc import VPC [as 別名]
# 或者: from heat.engine.resources.vpc.VPC import router_for_vpc [as 別名]
    def check_create_complete(self, *args):
        client = self.client()
        attributes = client.show_router(
            self.resource_id)['router']
        if not neutron.NeutronResource.is_built(attributes):
            return False

        network_id = self.properties.get(self.VPC_ID)
        default_router = VPC.router_for_vpc(client, network_id)
        if default_router and default_router.get('external_gateway_info'):
            # the default router for the VPC is connected
            # to the external router, so do it for this too.
            external_network_id = default_router[
                'external_gateway_info']['network_id']
            client.add_gateway_router(self.resource_id, {
                'network_id': external_network_id})
        return True
開發者ID:adrienverge,項目名稱:heat,代碼行數:19,代碼來源:route_table.py

示例6: handle_delete

# 需要導入模塊: from heat.engine.resources.vpc import VPC [as 別名]
# 或者: from heat.engine.resources.vpc.VPC import router_for_vpc [as 別名]
    def handle_delete(self):
        client = self.neutron()
        network_id = self.properties.get(self.VPC_ID)
        subnet_id = self.resource_id

        try:
            router = VPC.router_for_vpc(self.neutron(), network_id)
            if router:
                client.remove_interface_router(
                    router['id'],
                    {'subnet_id': subnet_id})
        except Exception as ex:
            self.client_plugin().ignore_not_found(ex)

        try:
            client.delete_subnet(subnet_id)
        except Exception as ex:
            self.client_plugin().ignore_not_found(ex)
開發者ID:COSHPC,項目名稱:heat,代碼行數:20,代碼來源:subnet.py

示例7: handle_create

# 需要導入模塊: from heat.engine.resources.vpc import VPC [as 別名]
# 或者: from heat.engine.resources.vpc.VPC import router_for_vpc [as 別名]
    def handle_create(self):
        client = self.neutron()
        # TODO(sbaker) Verify that this CidrBlock is within the vpc CidrBlock
        network_id = self.properties.get('VpcId')

        props = {
            'network_id': network_id,
            'cidr': self.properties.get('CidrBlock'),
            'name': self.physical_resource_name(),
            'ip_version': 4
        }
        subnet = client.create_subnet({'subnet': props})['subnet']

        router = VPC.router_for_vpc(self.neutron(), network_id)
        if router:
            client.add_interface_router(
                router['id'],
                {'subnet_id': subnet['id']})
        self.resource_id_set(subnet['id'])
開發者ID:AsherBond,項目名稱:heat,代碼行數:21,代碼來源:subnet.py

示例8: handle_delete

# 需要導入模塊: from heat.engine.resources.vpc import VPC [as 別名]
# 或者: from heat.engine.resources.vpc.VPC import router_for_vpc [as 別名]
    def handle_delete(self):
        from neutronclient.common.exceptions import NeutronClientException

        client = self.neutron()
        network_id = self.properties.get('VpcId')
        subnet_id = self.resource_id

        try:
            router = VPC.router_for_vpc(self.neutron(), network_id)
            if router:
                client.remove_interface_router(
                    router['id'],
                    {'subnet_id': subnet_id})
        except NeutronClientException as ex:
            if ex.status_code != 404:
                raise ex

        try:
            client.delete_subnet(subnet_id)
        except NeutronClientException as ex:
            if ex.status_code != 404:
                raise ex
開發者ID:AsherBond,項目名稱:heat,代碼行數:24,代碼來源:subnet.py

示例9: handle_create

# 需要導入模塊: from heat.engine.resources.vpc import VPC [as 別名]
# 或者: from heat.engine.resources.vpc.VPC import router_for_vpc [as 別名]
    def handle_create(self):
        """Add a floating IP address to a server."""
        if self.properties[self.EIP]:
            server = self.nova().servers.get(self.properties[self.INSTANCE_ID])
            server.add_floating_ip(self.properties[self.EIP])
            self.resource_id_set(self.properties[self.EIP])
            LOG.debug('ElasticIpAssociation '
                      '%(instance)s.add_floating_ip(%(eip)s)',
                      {'instance': self.properties[self.INSTANCE_ID],
                       'eip': self.properties[self.EIP]})
        elif self.properties[self.ALLOCATION_ID]:
            port_id = None
            port_rsrc = None
            if self.properties[self.NETWORK_INTERFACE_ID]:
                port_id = self.properties[self.NETWORK_INTERFACE_ID]
                port_rsrc = self.neutron().list_ports(id=port_id)['ports'][0]
            elif self.properties[self.INSTANCE_ID]:
                instance_id = self.properties[self.INSTANCE_ID]
                ports = self.neutron().list_ports(device_id=instance_id)
                port_rsrc = ports['ports'][0]
                port_id = port_rsrc['id']
            else:
                LOG.debug('Skipping association, resource not specified')
                return

            float_id = self.properties[self.ALLOCATION_ID]
            self.resource_id_set(float_id)

            network_id = port_rsrc['network_id']
            router = VPC.router_for_vpc(self.neutron(), network_id)
            if router is not None:
                floatingip = self.neutron().show_floatingip(float_id)
                floating_net_id = \
                    floatingip['floatingip']['floating_network_id']
                self.neutron().add_gateway_router(
                    router['id'], {'network_id': floating_net_id})

            self.neutron().update_floatingip(
                float_id, {'floatingip': {'port_id': port_id}})
開發者ID:Ishan20,項目名稱:heat,代碼行數:41,代碼來源:eip.py

示例10: _router_for_subnet

# 需要導入模塊: from heat.engine.resources.vpc import VPC [as 別名]
# 或者: from heat.engine.resources.vpc.VPC import router_for_vpc [as 別名]
 def _router_for_subnet(self, subnet_id):
     client = self.client()
     subnet = client.show_subnet(
         subnet_id)['subnet']
     network_id = subnet['network_id']
     return VPC.router_for_vpc(client, network_id)
開發者ID:adrienverge,項目名稱:heat,代碼行數:8,代碼來源:route_table.py


注:本文中的heat.engine.resources.vpc.VPC.router_for_vpc方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。