示例#1
0
    def _delete_nuage_vm(self, params):
        nuage_vm_id = self._get_nuage_vm(params, isdelete=True)
        if not nuage_vm_id:
            # It might already be deleted from the VSD
            return
        req_params = {
            'id': nuage_vm_id,
        }

        extra_params = {
            'tenant': params['tenant'],
            'net_partition_name': params['netpart_name']
        }

        nuagevm = nuagelib.NuageVM(create_params=req_params,
                                   extra_params=extra_params)
        resp = self.restproxy.rest_call(
            'DELETE',
            nuagevm.delete_resource(), '',
            extra_headers=nuagevm.extra_headers_delete())
        if not nuagevm.delete_validate(resp):
            raise restproxy.RESTProxyError(nuagevm.error_msg,
                                           nuagevm.vsd_error_code)
        if (not params['portOnSharedSubn'] and
                (params['subn_tenant'] != params['tenant'])):
            self._delete_extra_perm_attached(params['tenant'],
                                             params.get('l2dom_id'),
                                             params.get('l3dom_id'))
示例#2
0
 def delete_vm_by_external_id(self, params):
     req_params = {'externalID': params['externalID']}
     extra_params = {
         'tenant': params['tenant'],
         'net_partition_name': params['netpart_name']
     }
     nuagevm = nuagelib.NuageVM(create_params=req_params,
                                extra_params=extra_params)
     response = self.restproxy.get(
         nuagevm.get_resource(),
         extra_headers=nuagevm.extra_headers_get_by_externalID())
     if response:
         req_params = {'id': response[0]['ID']}
         vm = nuagelib.NuageVM(create_params=req_params,
                               extra_params=extra_params)
         self.restproxy.delete(vm.delete_resource(),
                               extra_headers=vm.extra_headers_delete())
示例#3
0
 def delete_vm_by_id(self, params):
     req_params = {'id': params['id']}
     extra_params = {
         'tenant': params['tenant'],
         'net_partition_name': params['netpart_name']
     }
     vm = nuagelib.NuageVM(create_params=req_params,
                           extra_params=extra_params)
     self.restproxy.delete(vm.delete_resource(),
                           extra_headers=vm.extra_headers_delete())
示例#4
0
    def _create_nuage_vm(self, params):
        vsd_subnet = params['vsd_subnet']
        req_params = {
            'id': params['id'],
            'mac': params['mac'],
            'ipv4': params['ipv4'],
            'ipv6': params['ipv6'],
            'externalID': get_vsd_external_id(params['port_id'])
        }
        # if vport_id passed in VMInterface and attachedNetworkId is not set,
        # VM create associates the passed vport to the VMInterface
        if params.get('vport_id') and not params.get('attached_network'):
            req_params['vport_id'] = params.get('vport_id')
        elif params.get('attached_network'):
            req_params['attachedNetworkID'] = vsd_subnet['ID']

        if vsd_subnet['type'] == constants.SUBNET:
            if not params['portOnSharedSubn']:
                self._attach_reqd_perm_for_vm_boot(params,
                                                   vsd_subnet['parentID'],
                                                   on_l2=False)
        elif vsd_subnet['type'] == constants.L2DOMAIN:
            self._clear_vsd_unmanaged_l2_domain_vm_ip(vsd_subnet, req_params)
            if not params['portOnSharedSubn']:
                self._attach_reqd_perm_for_vm_boot(params,
                                                   vsd_subnet['ID'],
                                                   on_l2=True)
        extra_params = {
            'tenant': params['tenant'],
            'net_partition_name': params['netpart_name']
        }
        nuagevm = nuagelib.NuageVM(create_params=req_params,
                                   extra_params=extra_params)
        response = self.restproxy.post(
            nuagevm.post_resource(),
            nuagevm.post_data(),
            extra_headers=nuagevm.extra_headers_post(),
            on_res_exists=self.restproxy.retrieve_by_external_id,
            ignore_err_codes=[
                restproxy.REST_EXISTS_INTERNAL_ERR_CODE,
                restproxy.REST_VM_UUID_IN_USE_ERR_CODE
            ])

        vm_dict = {}
        new_vmif = nuagevm.get_new_vmif(response)
        if new_vmif:
            vm_dict['ip'] = nuagevm.get_vmif_ip(new_vmif)
            vm_dict['vport_id'] = nuagevm.get_vmif_vportid(new_vmif)
            vm_dict['vif_id'] = nuagevm.get_vmif_id(new_vmif)

        return vm_dict
示例#5
0
    def _get_nuage_vm(self, params, isdelete=False):
        req_params = {'id': params['id']}

        extra_params = {
            'tenant': params['tenant'],
            'net_partition_name': params['netpart_name']
        }
        nuagevm = nuagelib.NuageVM(create_params=req_params,
                                   extra_params=extra_params)
        vms = self.restproxy.get(nuagevm.get_resource(),
                                 extra_headers=nuagevm.extra_headers_get())
        if not vms:
            if isdelete:
                return None
            else:
                msg = ('VM with uuid {} not found on '
                       'VSD').format(req_params['id'])
                raise restproxy.ResourceNotFoundException(msg)
        return vms[0]['ID']
示例#6
0
    def _get_nuage_vm(self, params, isdelete=False):
        req_params = {'id': params['id']}

        extra_params = {
            'tenant': params['tenant'],
            'net_partition_name': params['netpart_name']
        }
        nuagevm = nuagelib.NuageVM(create_params=req_params,
                                   extra_params=extra_params)
        try:
            vm = self.restproxy.get(nuagevm.get_resource(),
                                    extra_headers=nuagevm.extra_headers_get(),
                                    required=True)[0]
            vm_id = vm['ID']
        except restproxy.ResourceNotFoundException as e:
            if isdelete:
                vm_id = None
            else:
                e.msg = 'VM with uuid %s not found on VSD' % params['id']
                raise
        return vm_id
示例#7
0
    def _delete_nuage_vm(self, params):
        nuage_vm_id = self._get_nuage_vm(params, isdelete=True)
        if not nuage_vm_id:
            # It might already be deleted from the VSD
            return
        req_params = {
            'id': nuage_vm_id,
        }

        extra_params = {
            'tenant': params['tenant'],
            'net_partition_name': params['netpart_name']
        }

        nuagevm = nuagelib.NuageVM(create_params=req_params,
                                   extra_params=extra_params)
        self.restproxy.delete(nuagevm.delete_resource(),
                              extra_headers=nuagevm.extra_headers_delete())
        if (not params['portOnSharedSubn']
                and (params['subn_tenant'] != params['tenant'])):
            self._delete_extra_perm_attached(params['tenant'],
                                             params.get('l2dom_id'),
                                             params.get('l3dom_id'))
示例#8
0
    def _get_nuage_vm(self, params, isdelete=False):
        req_params = {
            'id': params['id']
        }

        extra_params = {
            'tenant': params['tenant'],
            'net_partition_name': params['netpart_name']
        }
        nuagevm = nuagelib.NuageVM(create_params=req_params,
                                   extra_params=extra_params)
        response = self.restproxy.rest_call(
            'GET',
            nuagevm.get_resource(), '',
            extra_headers=nuagevm.extra_headers_get())
        if nuagevm.get_validate(response):
            vm_id = nuagevm.get_response_objid(response)
        else:
            if isdelete:
                vm_id = None
            else:
                msg = 'VM with uuid %s not found on VSD' % params['id']
                raise restproxy.RESTProxyError(msg)
        return vm_id