def update_port(self, context, id, port): p = port['port'] if p.get('device_owner', '').startswith(constants.NOVA_PORT_OWNER_PREF): session = context.session with session.begin(subtransactions=True): port = self._get_port(context, id) port.update(p) if 'fixed_ips' not in port or len(port['fixed_ips']) == 0: return self._make_port_dict(port) subnet_id = port['fixed_ips'][0]['subnet_id'] subnet_mapping = nuagedb.get_subnet_l2dom_by_id( session, subnet_id) if not subnet_mapping: msg = (_("Subnet %s not found on VSD") % subnet_id) raise q_exc.BadRequest(resource='port', msg=msg) port_mapping = nuagedb.get_port_mapping_by_id(session, id) if not port_mapping: msg = (_("Port-Mapping for port %s not " " found on VSD") % id) raise q_exc.BadRequest(resource='port', msg=msg) if not port_mapping['nuage_vport_id']: self._create_update_port(context, port, port_mapping, subnet_mapping) updated_port = self._make_port_dict(port) else: updated_port = super(NuagePlugin, self).update_port(context, id, port) return updated_port
def delete_port(self, context, id, l3_port_check=True): if l3_port_check: self.prevent_l3_port_deletion(context, id) port = self._get_port(context, id) port_mapping = nuagedb.get_port_mapping_by_id(context.session, id) # This is required for to pass ut test_floatingip_port_delete self.disassociate_floatingips(context, id) if not port['fixed_ips']: return super(NuagePlugin, self).delete_port(context, id) sub_id = port['fixed_ips'][0]['subnet_id'] subnet_mapping = nuagedb.get_subnet_l2dom_by_id( context.session, sub_id) if not subnet_mapping: return super(NuagePlugin, self).delete_port(context, id) netpart_id = subnet_mapping['net_partition_id'] net_partition = nuagedb.get_net_partition_by_id( context.session, netpart_id) # Need to call this explicitly to delete vport_vporttag_mapping if constants.NOVA_PORT_OWNER_PREF in port['device_owner']: # This was a VM Port filters = {'device_id': [port['device_id']]} ports = self.get_ports(context, filters) params = { 'no_of_ports': len(ports), 'net_partition': net_partition, 'tenant': port['tenant_id'], 'mac': port['mac_address'], 'nuage_vif_id': port_mapping['nuage_vif_id'], 'id': port['device_id'] } self.nuageclient.delete_vms(params) super(NuagePlugin, self).delete_port(context, id)
def delete_port(self, context, id, l3_port_check=True): if l3_port_check: self.prevent_l3_port_deletion(context, id) port = self._get_port(context, id) port_mapping = nuagedb.get_port_mapping_by_id(context.session, id) # This is required for to pass ut test_floatingip_port_delete self.disassociate_floatingips(context, id) if not port['fixed_ips']: return super(NuagePlugin, self).delete_port(context, id) sub_id = port['fixed_ips'][0]['subnet_id'] subnet_mapping = nuagedb.get_subnet_l2dom_by_id(context.session, sub_id) if not subnet_mapping: return super(NuagePlugin, self).delete_port(context, id) netpart_id = subnet_mapping['net_partition_id'] net_partition = nuagedb.get_net_partition_by_id(context.session, netpart_id) # Need to call this explicitly to delete vport_vporttag_mapping if constants.NOVA_PORT_OWNER_PREF in port['device_owner']: # This was a VM Port filters = {'device_id': [port['device_id']]} ports = self.get_ports(context, filters) params = { 'no_of_ports': len(ports), 'net_partition': net_partition, 'tenant': port['tenant_id'], 'mac': port['mac_address'], 'nuage_vif_id': port_mapping['nuage_vif_id'], 'id': port['device_id'] } self.nuageclient.delete_vms(params) super(NuagePlugin, self).delete_port(context, id)
def update_floatingip(self, context, id, floatingip): fip = floatingip['floatingip'] orig_fip = self._get_floatingip(context, id) port_id = orig_fip['fixed_port_id'] with context.session.begin(subtransactions=True): neutron_fip = super(NuagePlugin, self).update_floatingip( context, id, floatingip) if fip['port_id'] is not None: if not neutron_fip['router_id']: ret_msg = 'floating-ip is not associated yet' raise n_exc.BadRequest(resource='floatingip', msg=ret_msg) try: self._create_update_floatingip(context, neutron_fip, fip['port_id']) except nuage_exc.OperationNotSupported: with excutils.save_and_reraise_exception(): super(NuagePlugin, self).disassociate_floatingips( context, fip['port_id']) except n_exc.BadRequest: with excutils.save_and_reraise_exception(): super(NuagePlugin, self).delete_floatingip(context, id) else: port_mapping = nuagedb.get_port_mapping_by_id( context.session, port_id) if port_mapping: params = { 'nuage_vport_id': port_mapping['nuage_vport_id'], 'nuage_fip_id': None } self.nuageclient.update_nuage_vm_vport(params) return neutron_fip
def update_port(self, context, id, port): p = port['port'] if p.get('device_owner', '').startswith( constants.NOVA_PORT_OWNER_PREF): session = context.session with session.begin(subtransactions=True): port = self._get_port(context, id) port.update(p) if 'fixed_ips' not in port or len(port['fixed_ips']) == 0: return self._make_port_dict(port) subnet_id = port['fixed_ips'][0]['subnet_id'] subnet_mapping = nuagedb.get_subnet_l2dom_by_id(session, subnet_id) if not subnet_mapping: msg = (_("Subnet %s not found on VSD") % subnet_id) raise n_exc.BadRequest(resource='port', msg=msg) port_mapping = nuagedb.get_port_mapping_by_id(session, id) if not port_mapping: msg = (_("Port-Mapping for port %s not " " found on VSD") % id) raise n_exc.BadRequest(resource='port', msg=msg) if not port_mapping['nuage_vport_id']: self._create_update_port(context, port, port_mapping, subnet_mapping) updated_port = self._make_port_dict(port) else: updated_port = super(NuagePlugin, self).update_port(context, id, port) return updated_port
def delete_port(self, context, id, l3_port_check=True): if l3_port_check: self.prevent_l3_port_deletion(context, id) port = self._get_port(context, id) port_mapping = nuagedb.get_port_mapping_by_id(context.session, id) # This is required for to pass ut test_floatingip_port_delete self.disassociate_floatingips(context, id) if not port["fixed_ips"]: return super(NuagePlugin, self).delete_port(context, id) sub_id = port["fixed_ips"][0]["subnet_id"] subnet_mapping = nuagedb.get_subnet_l2dom_by_id(context.session, sub_id) if not subnet_mapping: return super(NuagePlugin, self).delete_port(context, id) netpart_id = subnet_mapping["net_partition_id"] net_partition = nuagedb.get_net_partition_by_id(context.session, netpart_id) # Need to call this explicitly to delete vport_vporttag_mapping if constants.NOVA_PORT_OWNER_PREF in port["device_owner"]: # This was a VM Port filters = {"device_id": [port["device_id"]]} ports = self.get_ports(context, filters) params = { "no_of_ports": len(ports), "net_partition": net_partition, "tenant": port["tenant_id"], "mac": port["mac_address"], "nuage_vif_id": port_mapping["nuage_vif_id"], "id": port["device_id"], } self.nuageclient.delete_vms(params) super(NuagePlugin, self).delete_port(context, id)
def disassociate_floatingips(self, context, port_id): super(NuagePlugin, self).disassociate_floatingips(context, port_id) port_mapping = nuagedb.get_port_mapping_by_id(context.session, port_id) if port_mapping: params = { 'nuage_vport_id': port_mapping['nuage_vport_id'], 'nuage_fip_id': None } self.nuageclient.update_nuage_vm_vport(params)
def disassociate_floatingips(self, context, port_id, do_notify=True): router_ids = super(NuagePlugin, self).disassociate_floatingips( context, port_id, do_notify=do_notify) port_mapping = nuagedb.get_port_mapping_by_id(context.session, port_id) if port_mapping: params = { 'nuage_vport_id': port_mapping['nuage_vport_id'], 'nuage_fip_id': None } self.nuageclient.update_nuage_vm_vport(params) return router_ids
def disassociate_floatingips(self, context, port_id, do_notify=True): router_ids = super(NuagePlugin, self).disassociate_floatingips(context, port_id, do_notify=do_notify) port_mapping = nuagedb.get_port_mapping_by_id(context.session, port_id) if port_mapping: params = { 'nuage_vport_id': port_mapping['nuage_vport_id'], 'nuage_fip_id': None } self.nuageclient.update_nuage_vm_vport(params) return router_ids
def _create_update_floatingip(self, context, neutron_fip, port_id): rtr_id = neutron_fip['router_id'] net_id = neutron_fip['floating_network_id'] fip_pool_mapping = nuagedb.get_fip_pool_from_netid(context.session, net_id) fip_mapping = nuagedb.get_fip_mapping_by_id(context.session, neutron_fip['id']) if not fip_mapping: ent_rtr_mapping = nuagedb.get_ent_rtr_mapping_by_rtrid( context.session, rtr_id) if not ent_rtr_mapping: msg = _('router %s is not associated with ' 'any net-partition') % rtr_id raise n_exc.BadRequest(resource='floatingip', msg=msg) params = { 'nuage_rtr_id': ent_rtr_mapping['nuage_router_id'], 'nuage_fippool_id': fip_pool_mapping['fip_pool_id'], 'neutron_fip_ip': neutron_fip['floating_ip_address'] } nuage_fip_id = self.nuageclient.create_nuage_floatingip(params) nuagedb.add_fip_mapping(context.session, neutron_fip['id'], rtr_id, nuage_fip_id) else: if rtr_id != fip_mapping['router_id']: msg = _('Floating IP can not be associated to VM in ' 'different router context') raise nuage_exc.OperationNotSupported(msg=msg) nuage_fip_id = fip_mapping['nuage_fip_id'] fip_pool_dict = {'router_id': neutron_fip['router_id']} nuagedb.update_fip_pool_mapping(fip_pool_mapping, fip_pool_dict) # Update VM if required port_mapping = nuagedb.get_port_mapping_by_id(context.session, port_id) if port_mapping: params = { 'nuage_vport_id': port_mapping['nuage_vport_id'], 'nuage_fip_id': nuage_fip_id } self.nuageclient.update_nuage_vm_vport(params)
def delete_floatingip(self, context, id): fip = self._get_floatingip(context, id) port_id = fip['fixed_port_id'] with context.session.begin(subtransactions=True): if port_id: port_mapping = nuagedb.get_port_mapping_by_id( context.session, port_id) if (port_mapping and port_mapping['nuage_vport_id'] is not None): params = { 'nuage_vport_id': port_mapping['nuage_vport_id'], 'nuage_fip_id': None } self.nuageclient.update_nuage_vm_vport(params) fip_mapping = nuagedb.get_fip_mapping_by_id(context.session, id) if fip_mapping: self.nuageclient.delete_nuage_floatingip( fip_mapping['nuage_fip_id']) nuagedb.delete_fip_mapping(context.session, fip_mapping) super(NuagePlugin, self).delete_floatingip(context, id)
def update_floatingip(self, context, id, floatingip): fip = floatingip['floatingip'] orig_fip = self._get_floatingip(context, id) port_id = orig_fip['fixed_port_id'] router_ids = [] with context.session.begin(subtransactions=True): neutron_fip = super(NuagePlugin, self).update_floatingip( context, id, floatingip) if fip['port_id'] is not None: if not neutron_fip['router_id']: ret_msg = 'floating-ip is not associated yet' raise n_exc.BadRequest(resource='floatingip', msg=ret_msg) try: self._create_update_floatingip(context, neutron_fip, fip['port_id']) except nuage_exc.OperationNotSupported: with excutils.save_and_reraise_exception(): router_ids = super( NuagePlugin, self).disassociate_floatingips( context, fip['port_id'], do_notify=False) except n_exc.BadRequest: with excutils.save_and_reraise_exception(): super(NuagePlugin, self).delete_floatingip(context, id) else: port_mapping = nuagedb.get_port_mapping_by_id(context.session, port_id) if port_mapping: params = { 'nuage_vport_id': port_mapping['nuage_vport_id'], 'nuage_fip_id': None } self.nuageclient.update_nuage_vm_vport(params) # now that we've left db transaction, we are safe to notify self.notify_routers_updated(context, router_ids) return neutron_fip
def delete_floatingip(self, context, id): fip = self._get_floatingip(context, id) port_id = fip['fixed_port_id'] with context.session.begin(subtransactions=True): if port_id: port_mapping = nuagedb.get_port_mapping_by_id(context.session, port_id) if (port_mapping and port_mapping['nuage_vport_id'] is not None): params = { 'nuage_vport_id': port_mapping['nuage_vport_id'], 'nuage_fip_id': None } self.nuageclient.update_nuage_vm_vport(params) fip_mapping = nuagedb.get_fip_mapping_by_id(context.session, id) if fip_mapping: self.nuageclient.delete_nuage_floatingip( fip_mapping['nuage_fip_id']) nuagedb.delete_fip_mapping(context.session, fip_mapping) super(NuagePlugin, self).delete_floatingip(context, id)