Esempio n. 1
0
    def __init__(self, virtapi, read_only=False, scheme="https"):
        super(VMwareESXDriver, self).__init__(virtapi)

        self._do_deprecation_warning()

        self._host_ip = CONF.vmware.host_ip
        if not (self._host_ip or CONF.vmware.host_username is None or
                        CONF.vmware.host_password is None):
            raise Exception(_("Must specify host_ip, "
                              "host_username "
                              "and host_password to use "
                              "compute_driver=vmwareapi.VMwareESXDriver or "
                              "vmwareapi.VMwareVCDriver"))

        self._datastore_regex = None
        if CONF.vmware.datastore_regex:
            try:
                self._datastore_regex = re.compile(CONF.vmware.datastore_regex)
            except re.error:
                raise exception.InvalidInput(reason=
                    _("Invalid Regular Expression %s")
                    % CONF.vmware.datastore_regex)

        self._session = VMwareAPISession(scheme=scheme)
        self._volumeops = volumeops.VMwareVolumeOps(self._session)
        self._vmops = vmops.VMwareVMOps(self._session, self.virtapi,
                                        self._volumeops,
                                        datastore_regex=self._datastore_regex)
        self._host = host.Host(self._session)
        self._host_state = None

        #TODO(hartsocks): back-off into a configuration test module.
        if CONF.vmware.use_linked_clone is None:
            raise error_util.UseLinkedCloneConfigurationFault()
Esempio n. 2
0
    def __init__(self, virtapi, read_only=False, scheme="https"):
        super(VMwareESXDriver, self).__init__(virtapi)

        self._do_quality_warnings()

        self._host_ip = CONF.vmware.host_ip
        if not (self._host_ip or CONF.vmware.host_username is None
                or CONF.vmware.host_password is None):
            raise Exception(
                _("Must specify host_ip, "
                  "host_username "
                  "and host_password to use "
                  "compute_driver=vmwareapi.VMwareESXDriver or "
                  "vmwareapi.VMwareVCDriver"))

        self._session = VMwareAPISession(scheme=scheme)
        self._volumeops = volumeops.VMwareVolumeOps(self._session)
        self._vmops = vmops.VMwareVMOps(self._session, self.virtapi,
                                        self._volumeops)
        self._host = host.Host(self._session)
        self._host_state = None

        #TODO(hartsocks): back-off into a configuration test module.
        if CONF.vmware.use_linked_clone is None:
            raise error_util.UseLinkedCloneConfigurationFault()
Esempio n. 3
0
    def __init__(self, virtapi, read_only=False, scheme="https"):
        super(VMwareESXDriver, self).__init__(virtapi)

        self._host_ip = CONF.vmwareapi_host_ip
        host_username = CONF.vmwareapi_host_username
        host_password = CONF.vmwareapi_host_password
        api_retry_count = CONF.vmwareapi_api_retry_count
        if not self._host_ip or host_username is None or host_password is None:
            raise Exception(
                _("Must specify vmwareapi_host_ip,"
                  "vmwareapi_host_username "
                  "and vmwareapi_host_password to use"
                  "compute_driver=vmwareapi.VMwareESXDriver or "
                  "vmwareapi.VMwareVCDriver"))

        self._session = VMwareAPISession(self._host_ip,
                                         host_username,
                                         host_password,
                                         api_retry_count,
                                         scheme=scheme)
        self._volumeops = volumeops.VMwareVolumeOps(self._session)
        self._vmops = vmops.VMwareVMOps(self._session, self.virtapi,
                                        self._volumeops)
        self._host = host.Host(self._session)
        self._host_state = None
Esempio n. 4
0
    def test_spawn_disk_invalid_disk_size(self,
                                          mock_get_datacenter_ref_and_name,
                                          mock_get_datastore,
                                          mock_get_res_pool_ref):
        image = {
            'id': 'c1c8ce3d-c2e0-4247-890c-ccf5cc1c004c',
            'disk_format': 'vmdk',
            'size': 999999999 * units.Gi,
        }
        self._context = context.RequestContext('fake_user', 'fake_project')
        instance = fake_instance.fake_instance_obj(
            self._context,
            image_ref=nova.tests.image.fake.get_valid_image_id(),
            uuid='fake_uuid',
            root_gb=1,
            node='respool-1001(MyResPoolName)')

        ops = vmops.VMwareVMOps(mock.Mock(), mock.Mock(), mock.Mock())
        self.assertRaises(exception.InstanceUnacceptable,
                          ops.spawn,
                          mock.Mock(),
                          instance,
                          image,
                          injected_files=[],
                          admin_password=None,
                          network_info=None,
                          block_device_info=None)
Esempio n. 5
0
 def __init__(self, virtapi, read_only=False, scheme="https"):
     super(VMwareVCDriver, self).__init__(virtapi)
     self._cluster_name = CONF.vmware.cluster_name
     if not self._cluster_name:
         self._cluster = None
     else:
         self._cluster = vm_util.get_cluster_ref_from_name(
                         self._session, self._cluster_name)
         if self._cluster is None:
             raise exception.NotFound(_("VMware Cluster %s is not found")
                                        % self._cluster_name)
     self._datastore_regex = None
     if CONF.vmware.datastore_regex:
         try:
             self._datastore_regex = re.compile(CONF.vmware.datastore_regex)
         except re.error:
             raise exception.InvalidInput(reason=
             _("Invalid Regular Expression %s")
             % CONF.vmware.datastore_regex)
     self._volumeops = volumeops.VMwareVolumeOps(self._session,
                                                 self._cluster)
     self._vmops = vmops.VMwareVMOps(self._session, self.virtapi,
                                     self._volumeops, self._cluster,
                                     self._datastore_regex)
     self._vc_state = None
Esempio n. 6
0
 def test_check_if_folder_file_exists_no_existing(self):
     ops = vmops.VMwareVMOps(mock.Mock(), mock.Mock(), mock.Mock())
     ops.create_cache_folder = mock.Mock()
     ops._file_exists = mock.Mock()
     ops._file_exists.return_value = True
     ops._check_if_folder_file_exists(mock.Mock(), "datastore", "folder",
                                      "some_file")
     ops.create_cache_folder.assert_called_once()
Esempio n. 7
0
 def _setup_create_cache_mocks(self):
     ops = vmops.VMwareVMOps(mock.Mock(), mock.Mock(), mock.Mock())
     base_name = ops._base_folder
     ds_name = "datastore"
     ds_ref = mock.Mock()
     path = vm_util.build_datastore_path(ds_name, base_name)
     ops._mkdir = mock.Mock()
     return ds_name, ds_ref, ops, path
Esempio n. 8
0
 def test_get_valid_vms_from_retrieve_result(self):
     ops = vmops.VMwareVMOps(mock.Mock(), mock.Mock(), mock.Mock())
     fake_objects = vmwareapi_fake.FakeRetrieveResult()
     fake_objects.add_object(vmwareapi_fake.VirtualMachine())
     fake_objects.add_object(vmwareapi_fake.VirtualMachine())
     fake_objects.add_object(vmwareapi_fake.VirtualMachine())
     vms = ops._get_valid_vms_from_retrieve_result(fake_objects)
     self.assertEqual(3, len(vms))
Esempio n. 9
0
 def test_check_if_folder_file_exists_no_existing(self, mock_exists):
     ops = vmops.VMwareVMOps(mock.Mock(), mock.Mock(), mock.Mock())
     ops._create_folder_if_missing = mock.Mock()
     mock_ds_ref = mock.Mock()
     ops._check_if_folder_file_exists(mock.Mock(), mock_ds_ref, "datastore",
                                      "folder", "some_file")
     ops._create_folder_if_missing.assert_called_once_with(
         'datastore', mock_ds_ref, 'vmware_base')
Esempio n. 10
0
    def __init__(self, virtapi, scheme="https"):
        super(VMwareVCDriver, self).__init__(virtapi)

        if (CONF.vmware.host_ip is None or
            CONF.vmware.host_username is None or
            CONF.vmware.host_password is None):
            raise Exception(_("Must specify host_ip, host_username and "
                              "host_password to use vmwareapi.VMwareVCDriver"))

        if CONF.vnc.keymap:
            LOG.warning('The option "[vnc] keymap" has been deprecated in '
                        'favor of the VMWare-specific "[vmware] vnc_keymap" '
                        'option. Please update nova.conf to address this '
                        'change')

        self._datastore_regex = None
        if CONF.vmware.datastore_regex:
            try:
                self._datastore_regex = re.compile(CONF.vmware.datastore_regex)
            except re.error:
                raise exception.InvalidInput(reason=
                    _("Invalid Regular Expression %s")
                    % CONF.vmware.datastore_regex)

        self._session = VMwareAPISession(scheme=scheme)

        self._check_min_version()

        # Update the PBM location if necessary
        if CONF.vmware.pbm_enabled:
            self._update_pbm_location()

        self._validate_configuration()
        self._cluster_name = CONF.vmware.cluster_name
        self._cluster_ref = vm_util.get_cluster_ref_by_name(self._session,
                                                            self._cluster_name)
        if self._cluster_ref is None:
            raise exception.NotFound(_("The specified cluster '%s' was not "
                                       "found in vCenter")
                                     % self._cluster_name)
        self._vcenter_uuid = self._get_vcenter_uuid()
        self._nodename = self._create_nodename(self._cluster_ref.value)
        self._volumeops = volumeops.VMwareVolumeOps(self._session,
                                                    self._cluster_ref)
        self._vmops = vmops.VMwareVMOps(self._session,
                                        virtapi,
                                        self._volumeops,
                                        self._cluster_ref,
                                        datastore_regex=self._datastore_regex)
        self._vc_state = host.VCState(self._session,
                                      self._nodename,
                                      self._cluster_ref,
                                      self._datastore_regex)

        # Register the OpenStack extension
        self._register_openstack_extension()
Esempio n. 11
0
    def setUp(self):
        super(VMwareVMOpsTestCase, self).setUp()
        vmwareapi_fake.reset()
        stubs.set_stubs(self.stubs)
        self._session = driver.VMwareAPISession()

        self._vmops = vmops.VMwareVMOps(self._session, None, None)
        self._instance = {'name': 'fake_name', 'uuid': 'fake_uuid'}

        subnet_4 = network_model.Subnet(
            cidr='192.168.0.1/24',
            dns=[network_model.IP('192.168.0.1')],
            gateway=network_model.IP('192.168.0.1'),
            ips=[network_model.IP('192.168.0.100')],
            routes=None)
        subnet_6 = network_model.Subnet(
            cidr='dead:beef::1/64',
            dns=None,
            gateway=network_model.IP('dead:beef::1'),
            ips=[network_model.IP('dead:beef::dcad:beff:feef:0')],
            routes=None)
        network = network_model.Network(id=0,
                                        bridge='fa0',
                                        label='fake',
                                        subnets=[subnet_4, subnet_6],
                                        vlan=None,
                                        bridge_interface=None,
                                        injected=True)
        self.network_info = network_model.NetworkInfo([
            network_model.VIF(id=None,
                              address='DE:AD:BE:EF:00:00',
                              network=network,
                              type=None,
                              devname=None,
                              ovs_interfaceid=None,
                              rxtx_cap=3)
        ])
        pure_IPv6_network = network_model.Network(id=0,
                                                  bridge='fa0',
                                                  label='fake',
                                                  subnets=[subnet_6],
                                                  vlan=None,
                                                  bridge_interface=None,
                                                  injected=True)
        self.pure_IPv6_network_info = network_model.NetworkInfo([
            network_model.VIF(id=None,
                              address='DE:AD:BE:EF:00:00',
                              network=pure_IPv6_network,
                              type=None,
                              devname=None,
                              ovs_interfaceid=None,
                              rxtx_cap=3)
        ])
        utils.reset_is_neutron()
Esempio n. 12
0
 def _setup_create_folder_mocks(self):
     ops = vmops.VMwareVMOps(mock.Mock(), mock.Mock(), mock.Mock())
     base_name = 'folder'
     ds_name = "datastore"
     ds_ref = mock.Mock()
     ds_ref.value = 1
     dc_ref = mock.Mock()
     ops._datastore_dc_mapping[ds_ref.value] = vmops.DcInfo(
         ref=dc_ref, name='fake-name', vmFolder='fake-folder')
     path = ds_util.build_datastore_path(ds_name, base_name)
     ds_util.mkdir = mock.Mock()
     return ds_name, ds_ref, ops, path, dc_ref
Esempio n. 13
0
 def test_get_valid_vms_from_retrieve_result_with_invalid(self):
     ops = vmops.VMwareVMOps(mock.Mock(), mock.Mock(), mock.Mock())
     fake_objects = vmwareapi_fake.FakeRetrieveResult()
     fake_objects.add_object(vmwareapi_fake.VirtualMachine())
     invalid_vm1 = vmwareapi_fake.VirtualMachine()
     invalid_vm1.set('runtime.connectionState', 'orphaned')
     invalid_vm2 = vmwareapi_fake.VirtualMachine()
     invalid_vm2.set('runtime.connectionState', 'inaccessible')
     fake_objects.add_object(invalid_vm1)
     fake_objects.add_object(invalid_vm2)
     vms = ops._get_valid_vms_from_retrieve_result(fake_objects)
     self.assertEqual(1, len(vms))
Esempio n. 14
0
 def __init__(self, virtapi, read_only=False, scheme="https"):
     super(VMwareVCDriver, self).__init__(virtapi)
     self._cluster_name = CONF.vmwareapi_cluster_name
     if not self._cluster_name:
         self._cluster = None
     else:
         self._cluster = vm_util.get_cluster_ref_from_name(
             self._session, self._cluster_name)
         if self._cluster is None:
             raise exception.NotFound(
                 _("VMware Cluster %s is not found") % self._cluster_name)
     self._volumeops = volumeops.VMwareVolumeOps(self._session,
                                                 self._cluster)
     self._vmops = vmops.VMwareVMOps(self._session, self.virtapi,
                                     self._volumeops, self._cluster)
     self._vc_state = None
Esempio n. 15
0
    def _update_resources(self):
        """This method creates a dictionary of VMOps, VolumeOps and VCState.

        The VMwareVMOps, VMwareVolumeOps and VCState object is for each
        cluster/rp. The dictionary is of the form
        {
            domain-1000 : {'vmops': vmops_obj,
                          'volumeops': volumeops_obj,
                          'vcstate': vcstate_obj,
                          'name': MyCluster},
            resgroup-1000 : {'vmops': vmops_obj,
                              'volumeops': volumeops_obj,
                              'vcstate': vcstate_obj,
                              'name': MyRP},
        }
        """

        # TODO(kirankv) we can avoid creating multiple vmops and volumeops
        # if we make them utility class so that cluster is passed as a
        # parameter to the method
        added_nodes = set(self.dict_mors.keys()) - set(self._resources.keys())
        for node in added_nodes:
            _volumeops = volumeops.VMwareVolumeOps(
                self._session,
                self.dict_mors[node]['cluster_mor'],
                vc_support=True)
            _vmops = vmops.VMwareVMOps(self._session, self._virtapi,
                                       _volumeops,
                                       self.dict_mors[node]['cluster_mor'])
            name = self.dict_mors.get(node)['name']
            _vc_state = host.VCState(self._session,
                                     self._create_nodename(node, name),
                                     self.dict_mors.get(node)['cluster_mor'])
            self._resources[node] = {
                'vmops': _vmops,
                'volumeops': _volumeops,
                'vcstate': _vc_state,
                'name': name,
            }
        deleted_nodes = (set(self._resources.keys()) -
                         set(self.dict_mors.keys()))
        for node in deleted_nodes:
            LOG.debug(
                _("Removing node %s since its removed from"
                  " nova.conf") % node)
            del self._resources[node]
Esempio n. 16
0
    def _update_resources(self):
        """This method creates a dictionary of VMOps, VolumeOps and VCState.

        The VMwareVMOps, VMwareVolumeOps and VCState object is for each
        cluster/rp. The dictionary is of the form
        {
            'domain-1000.497c514c-ef5e-4e7f-8d93-ec921993b93a' : {
                'vmops': vmops_obj,
                'volumeops': volumeops_obj,
                'vcstate': vcstate_obj,
                'name': MyCluster},
            'resgroup-1000.497c514c-ef5e-4e7f-8d93-ec921993b93a' : {
                'vmops': vmops_obj,
                'volumeops': volumeops_obj,
                'vcstate': vcstate_obj,
                'name': MyRP},
        }
        """
        added_nodes = set(self.dict_mors.keys()) - set(self._resource_keys)
        for node in added_nodes:
            _volumeops = volumeops.VMwareVolumeOps(
                self._session, self.dict_mors[node]['cluster_mor'])
            _vmops = vmops.VMwareVMOps(self._session,
                                       self._virtapi,
                                       _volumeops,
                                       self.dict_mors[node]['cluster_mor'],
                                       datastore_regex=self._datastore_regex)
            name = self.dict_mors.get(node)['name']
            nodename = self._create_nodename(node)
            _vc_state = host.VCState(self._session, nodename,
                                     self.dict_mors.get(node)['cluster_mor'],
                                     self._datastore_regex)
            self._resources[nodename] = {
                'vmops': _vmops,
                'volumeops': _volumeops,
                'vcstate': _vc_state,
                'name': name,
            }
            self._resource_keys.add(node)

        deleted_nodes = (set(self._resource_keys) - set(self.dict_mors.keys()))
        for node in deleted_nodes:
            nodename = self._create_nodename(node)
            del self._resources[nodename]
            self._resource_keys.discard(node)
Esempio n. 17
0
    def setUp(self):
        super(VMwareVMOpsTestCase, self).setUp()
        vmwareapi_fake.reset()
        stubs.set_stubs(self.stubs)
        self.flags(image_cache_subdirectory_name='vmware_base', my_ip='')
        self._context = context.RequestContext('fake_user', 'fake_project')
        self._session = driver.VMwareAPISession()

        self._virtapi = mock.Mock()
        self._vmops = vmops.VMwareVMOps(self._session, self._virtapi, None)
        self._image_id = nova.tests.image.fake.get_valid_image_id()
        values = {
            'name': 'fake_name',
            'uuid': 'fake_uuid',
            'vcpus': 1,
            'memory_mb': 512,
            'image_ref': self._image_id,
            'root_gb': 1,
            'node': 'respool-1001(MyResPoolName)',
        }
        self._context = context.RequestContext('fake_user', 'fake_project')
        self._instance = fake_instance.fake_instance_obj(
            self._context, **values)

        subnet_4 = network_model.Subnet(
            cidr='192.168.0.1/24',
            dns=[network_model.IP('192.168.0.1')],
            gateway=network_model.IP('192.168.0.1'),
            ips=[network_model.IP('192.168.0.100')],
            routes=None)
        subnet_6 = network_model.Subnet(
            cidr='dead:beef::1/64',
            dns=None,
            gateway=network_model.IP('dead:beef::1'),
            ips=[network_model.IP('dead:beef::dcad:beff:feef:0')],
            routes=None)
        network = network_model.Network(id=0,
                                        bridge='fa0',
                                        label='fake',
                                        subnets=[subnet_4, subnet_6],
                                        vlan=None,
                                        bridge_interface=None,
                                        injected=True)
        self.network_info = network_model.NetworkInfo([
            network_model.VIF(id=None,
                              address='DE:AD:BE:EF:00:00',
                              network=network,
                              type=None,
                              devname=None,
                              ovs_interfaceid=None,
                              rxtx_cap=3)
        ])
        pure_IPv6_network = network_model.Network(id=0,
                                                  bridge='fa0',
                                                  label='fake',
                                                  subnets=[subnet_6],
                                                  vlan=None,
                                                  bridge_interface=None,
                                                  injected=True)
        self.pure_IPv6_network_info = network_model.NetworkInfo([
            network_model.VIF(id=None,
                              address='DE:AD:BE:EF:00:00',
                              network=pure_IPv6_network,
                              type=None,
                              devname=None,
                              ovs_interfaceid=None,
                              rxtx_cap=3)
        ])
Esempio n. 18
0
 def test_is_neutron_quantum(self):
     self.flags(network_api_class='nova.network.quantumv2.api.API')
     ops = vmops.VMwareVMOps(None, None, None)
     self.assertTrue(ops._is_neutron)
Esempio n. 19
0
 def test_check_if_folder_file_exists_no_existing(self, mock_exists):
     ops = vmops.VMwareVMOps(mock.Mock(), mock.Mock(), mock.Mock())
     ops._create_folder_if_missing = mock.Mock()
     ops._check_if_folder_file_exists(mock.Mock(), mock.Mock(), "datastore",
                                      "folder", "some_file")
     ops._create_folder_if_missing.assert_called_once()
Esempio n. 20
0
 def test_is_neutron_nova(self):
     self.flags(network_api_class='nova.network.api.API')
     ops = vmops.VMwareVMOps(None, None, None)
     self.assertFalse(ops._is_neutron)
Esempio n. 21
0
    def __init__(self, virtapi, scheme="https"):
        super(VMwareVCDriver, self).__init__(virtapi)

        if (CONF.vmware.host_ip is None or
            CONF.vmware.host_username is None or
            CONF.vmware.host_password is None):
            raise Exception(_("Must specify host_ip, host_username and "
                              "host_password to use vmwareapi.VMwareVCDriver"))

        # Begin Pf9 change
        # Get the list of datastores, and convert to a regex - Pf9 UI passes this in as a comma-separated list
        self._datastore_regex = None
        ds_list = CONF.vmware.datastore_regex

        if ds_list:
            # Convert 'ds1, ds2,ds3,   ds4' => 'ds1|ds2|ds3|ds4'
            regex_string = "|".join([item.rstrip().lstrip() for item in ds_list.split(',')])
            if regex_string != '':
                try:
                    self._datastore_regex = re.compile(regex_string)
                except re.error:
                    raise exception.InvalidInput(reason=
                    _("Invalid Regular Expression %s")
                    % regex_string)

        self._pf9_hostid = CONF.host
        # End Pf9 change

        self._session = VMwareAPISession(scheme=scheme)

        self._check_min_version()

        # Update the PBM location if necessary
        if CONF.vmware.pbm_enabled:
            self._update_pbm_location()

        self._validate_configuration()
        self._cluster_name = CONF.vmware.cluster_name
        self._cluster_ref = vm_util.get_cluster_ref_by_name(self._session,
                                                            self._cluster_name)
        if self._cluster_ref is None:
            raise exception.NotFound(_("The specified cluster '%s' was not "
                                       "found in vCenter")
                                     % self._cluster_name)
        self._vcenter_uuid = self._get_vcenter_uuid()
        self._nodename = self._create_nodename(self._cluster_ref.value,
                                               self._cluster_name)
        self._volumeops = volumeops.VMwareVolumeOps(self._session,
                                                    self._cluster_ref)
        self._vmops = vmops.VMwareVMOps(self._session,
                                        virtapi,
                                        self._volumeops,
                                        self._cluster_ref,
                                        datastore_regex=self._datastore_regex)
        self._vc_state = host.VCState(self._session,
                                      self._nodename,
                                      self._cluster_ref,
                                      self._datastore_regex)

        # Register the OpenStack extension
        self._register_openstack_extension()