Пример #1
0
    def _send_delete_port_request(self, context, id):
        """
        Send delete port request to VSM.

        Decrement the port count of the VM network after deleting the port.
        If the port count reaches zero, delete the VM network.
        :param context: neutron api request context
        :param id: UUID of the port to be deleted
        """
        LOG.debug(_('_send_delete_port_request: %s'), id)
        port = self.get_port(context, id)
        vm_network = n1kv_db_v2.get_vm_network(context.session,
                                               port[n1kv_profile.PROFILE_ID],
                                               port['network_id'])
        vm_network['port_count'] -= 1
        n1kv_db_v2.update_vm_network_port_count(context.session,
                                                vm_network['name'],
                                                vm_network['port_count'])
        n1kvclient = n1kv_client.Client()
        n1kvclient.delete_n1kv_port(vm_network['name'], id)
        if vm_network['port_count'] == 0:
            n1kv_db_v2.delete_vm_network(context.session,
                                         port[n1kv_profile.PROFILE_ID],
                                         port['network_id'])
            n1kvclient.delete_vm_network(vm_network['name'])
Пример #2
0
 def _poll_policies(self, event_type=None, epoch=None, tenant_id=None):
     """
     Poll for Policy Profiles from Cisco Nexus1000V for any update/delete.
     """
     LOG.debug(_('_poll_policies'))
     n1kvclient = n1kv_client.Client()
     policy_profiles = n1kvclient.list_events(event_type, epoch)
     if policy_profiles:
         for profile in policy_profiles['body'][c_const.SET]:
             if c_const.NAME in profile:
                 # Extract commands from the events XML.
                 cmd = profile[c_const.PROPERTIES]['cmd']
                 cmds = cmd.split(';')
                 cmdwords = cmds[1].split()
                 profile_name = profile[c_const.PROPERTIES][c_const.NAME]
                 # Delete the policy profile from db if it's deleted on VSM
                 if 'no' in cmdwords[0]:
                     p = self._get_policy_profile_by_name(profile_name)
                     if p:
                         self._delete_policy_profile(p['id'])
                 # Add policy profile to neutron DB idempotently
                 elif c_const.ID in profile[c_const.PROPERTIES]:
                     profile_id = profile[c_const.PROPERTIES][c_const.ID]
                     self._add_policy_profile(profile_name, profile_id,
                                              tenant_id)
         # Replace tenant-id for profile bindings with admin's tenant-id
         self._remove_all_fake_policy_profiles()
Пример #3
0
    def _send_delete_logical_network_request(self, network_profile):
        """
        Send delete logical network request to VSM.

        :param network_profile: network profile dictionary
        """
        LOG.debug('_send_delete_logical_network')
        n1kvclient = n1kv_client.Client()
        n1kvclient.delete_logical_network(network_profile)
Пример #4
0
    def _send_delete_network_profile_request(self, profile):
        """
        Send delete network profile request to VSM.

        :param profile: network profile dictionary
        """
        LOG.debug(_('_send_delete_network_profile_request: %s'),
                  profile['name'])
        n1kvclient = n1kv_client.Client()
        n1kvclient.delete_network_segment_pool(profile['name'])
Пример #5
0
    def _send_create_network_profile_request(self, context, profile):
        """
        Send create network profile request to VSM.

        :param context: neutron api request context
        :param profile: network profile dictionary
        """
        LOG.debug(_('_send_create_network_profile_request: %s'), profile['id'])
        n1kvclient = n1kv_client.Client()
        n1kvclient.create_network_segment_pool(profile)
Пример #6
0
    def _send_update_port_request(self, port_id, mac_address, vm_network_name):
        """
        Send update port request to VSM.

        :param port_id: UUID representing port to update
        :param mac_address: string representing the mac address
        :param vm_network_name: VM network name to which the port is bound
        """
        LOG.debug(_('_send_update_port_request: %s'), port_id)
        body = {'portId': port_id, 'macAddress': mac_address}
        n1kvclient = n1kv_client.Client()
        n1kvclient.update_n1kv_port(vm_network_name, port_id, body)
Пример #7
0
    def _send_delete_subnet_request(self, context, subnet):
        """
        Send delete subnet request to VSM.

        :param context: neutron api request context
        :param subnet: subnet dictionary
        """
        LOG.debug(_('_send_delete_subnet_request: %s'), subnet['name'])
        network = self.get_network(context, subnet['network_id'])
        body = {'ipPoolName': subnet['name'], 'deleteSubnet': True}
        n1kvclient = n1kv_client.Client()
        n1kvclient.update_network_segment(network['name'], body=body)
        n1kvclient.delete_ip_pool(subnet['name'])
Пример #8
0
    def _send_delete_network_request(self, network):
        """
        Send delete network request to VSM.

        Delete bridge domain if network is of type VXLAN.
        :param network: network dictionary
        """
        LOG.debug(_('_send_delete_network_request: %s'), network['id'])
        n1kvclient = n1kv_client.Client()
        if network[providernet.NETWORK_TYPE] == c_const.NETWORK_TYPE_VXLAN:
            name = network['name'] + '_bd'
            n1kvclient.delete_bridge_domain(name)
        n1kvclient.delete_network_segment(network['name'])
Пример #9
0
    def _send_create_port_request(self, context, port):
        """
        Send create port request to VSM.

        Create a VM network for a network and policy profile combination.
        If the VM network already exists, bind this port to the existing
        VM network and increment its port count.
        :param context: neutron api request context
        :param port: port dictionary
        """
        LOG.debug(_('_send_create_port_request: %s'), port)
        try:
            vm_network = n1kv_db_v2.get_vm_network(
                context.session, port[n1kv_profile.PROFILE_ID],
                port['network_id'])
        except cisco_exceptions.VMNetworkNotFound:
            policy_profile = n1kv_db_v2.get_policy_profile(
                context.session, port[n1kv_profile.PROFILE_ID])
            network = self.get_network(context, port['network_id'])
            vm_network_name = (c_const.VM_NETWORK_NAME_PREFIX +
                               str(port[n1kv_profile.PROFILE_ID]) + "_" +
                               str(port['network_id']))
            port_count = 1
            n1kv_db_v2.add_vm_network(context.session, vm_network_name,
                                      port[n1kv_profile.PROFILE_ID],
                                      port['network_id'], port_count)
            n1kvclient = n1kv_client.Client()
            n1kvclient.create_vm_network(port, vm_network_name, policy_profile,
                                         network['name'])
            n1kvclient.create_n1kv_port(port, vm_network_name)
        else:
            vm_network_name = vm_network['name']
            n1kvclient = n1kv_client.Client()
            n1kvclient.create_n1kv_port(port, vm_network_name)
            vm_network['port_count'] += 1
            n1kv_db_v2.update_vm_network_port_count(context.session,
                                                    vm_network_name,
                                                    vm_network['port_count'])
Пример #10
0
    def _send_create_network_request(self, context, network):
        """
        Send create network request to VSM.

        Create a bridge domain for network of type VXLAN.
        :param context: neutron api request context
        :param network: network dictionary
        """
        LOG.debug(_('_send_create_network_request: %s'), network['id'])
        profile = self.get_network_profile(context,
                                           network[n1kv_profile.PROFILE_ID])
        n1kvclient = n1kv_client.Client()
        if network[providernet.NETWORK_TYPE] == c_const.NETWORK_TYPE_VXLAN:
            n1kvclient.create_bridge_domain(network)
        n1kvclient.create_network_segment(network, profile)
Пример #11
0
    def _send_update_network_request(self, db_session, network):
        """
        Send update network request to VSM.

        :param network: network dictionary
        """
        LOG.debug(_('_send_update_network_request: %s'), network['id'])
        profile = n1kv_db_v2.get_network_profile(
            db_session, network[n1kv_profile.PROFILE_ID])
        body = {
            'name': network['name'],
            'id': network['id'],
            'networkDefinition': profile['name'],
            'vlan': network[providernet.SEGMENTATION_ID]
        }
        n1kvclient = n1kv_client.Client()
        n1kvclient.update_network_segment(network['name'], body)
Пример #12
0
    def _populate_policy_profiles(self):
        """
        Populate all the policy profiles from VSM.

        The tenant id is not available when the policy profiles are polled
        from the VSM. Hence we associate the policy profiles with fake
        tenant-ids.
        """
        LOG.debug(_('_populate_policy_profiles'))
        n1kvclient = n1kv_client.Client()
        policy_profiles = n1kvclient.list_port_profiles()
        LOG.debug(_('_populate_policy_profiles %s'), policy_profiles)
        if policy_profiles:
            for profile in policy_profiles['body'][c_const.SET]:
                if c_const.ID and c_const.NAME in profile:
                    profile_id = profile[c_const.PROPERTIES][c_const.ID]
                    profile_name = profile[c_const.PROPERTIES][c_const.NAME]
                    self._add_policy_profile(profile_name, profile_id)
        else:
            LOG.warning(_('No policy profile populated from VSM'))
        self._remove_all_fake_policy_profiles()