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


Python vpc.VPC类代码示例

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


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

示例1: _neutron_add_gateway_router

 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,代码行数:8,代码来源:eip.py

示例2: handle_create

    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,代码行数:55,代码来源:eip.py

示例3: handle_create

    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,代码行数:53,代码来源:eip.py

示例4: handle_create

    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,代码行数:48,代码来源:eip.py

示例5: check_create_complete

    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,代码行数:17,代码来源:route_table.py

示例6: handle_delete

    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,代码行数:18,代码来源:subnet.py

示例7: handle_create

    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,代码行数:19,代码来源:subnet.py

示例8: handle_delete

    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,代码行数:22,代码来源:subnet.py

示例9: handle_create

    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,代码行数:39,代码来源:eip.py

示例10: _router_for_subnet

 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,代码行数:6,代码来源:route_table.py


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