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 }})
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})
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})
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}})
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}})
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 }})
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}})
def check_create_complete(self, *args): client = self.neutron() attributes = client.show_router(self.resource_id)['router'] if not neutron.NeutronResource.is_built(attributes): return False network_id = self.properties.get('VpcId') 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
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)
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
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)
def handle_create(self): client = self.neutron() # TODO(sbaker) Verify that this CidrBlock is within the vpc CidrBlock network_id = self.properties.get(self.VPC_ID) props = { 'network_id': network_id, 'cidr': self.properties.get(self.CIDR_BLOCK), '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'])
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'])
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
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}})
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
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)
def _router_for_subnet(self, subnet_id): client = self.neutron() subnet = client.show_subnet(subnet_id)['subnet'] network_id = subnet['network_id'] return VPC.router_for_vpc(client, network_id)