本文整理汇总了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})
示例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}})
示例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}})
示例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}})
示例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
示例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)
示例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'])
示例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
示例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}})
示例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)