Beispiel #1
0
    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)
Beispiel #2
0
    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)
Beispiel #3
0
 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)
Beispiel #4
0
 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)