コード例 #1
0
    def _validate_node_exists(self, node_id):
        filterObj = [MongoObj(field='node_id', value=node_id)]
        projection = [MongoObj(field='_id', value=1)]

        err, matches = TargetAPI().get(filter=filterObj, projection=projection)
        if err or not len(matches):
            raise DriverError(StatusCode.NOT_FOUND,
                              'Could not find Node with id {}'.format(node_id))
コード例 #2
0
    def _validate_volume_exists(self, nvmesh_vol_name):
        filterObj = [MongoObj(field='_id', value=nvmesh_vol_name)]
        projection = [MongoObj(field='_id', value=1)]

        err, out = VolumeAPI().get(filter=filterObj, projection=projection)
        if err or not len(out):
            raise DriverError(
                StatusCode.NOT_FOUND,
                'Could not find Volume with id {}'.format(nvmesh_vol_name))
コード例 #3
0
    def _get_nvmesh_volume_capacity(self, nvmesh_vol_name):
        filterObj = [MongoObj(field='_id', value=nvmesh_vol_name)]
        projection = [
            MongoObj(field='_id', value=1),
            MongoObj(field='capacity', value=1)
        ]

        err, out = VolumeAPI().get(filter=filterObj, projection=projection)
        if err or not len(out):
            raise DriverError(StatusCode.INTERNAL, err)

        return out[0]['capacity']
コード例 #4
0
    def _get_nvmesh_volume_capacity(self, nvmesh_vol_name, log, zone=None):
        volume_api = VolumeAPIPool.get_volume_api_for_zone(zone, log)

        filterObj = [MongoObj(field='_id', value=nvmesh_vol_name)]
        projection = [
            MongoObj(field='_id', value=1),
            MongoObj(field='capacity', value=1)
        ]

        err, out = volume_api.get(filter=filterObj, projection=projection)
        if err or not len(out):
            raise DriverError(StatusCode.INTERNAL, err)

        return out[0].capacity
コード例 #5
0
 def get_nvmesh_volume_by_name(nvmesh_vol_name):
     filter_obj = [MongoObj(field='_id', value=nvmesh_vol_name)]
     err, out = VolumeAPI(NVMESH_MGMT_ADDRESS).get(filter=filter_obj)
     if len(out) == 0:
         return None
     else:
         return out[0]
コード例 #6
0
 def _get_volume_by_name(self, volume_id):
     filterObj = [MongoObj(field='_id', value=volume_id)]
     err, data = VolumeAPI().get(filter=filterObj)
     if err:
         return err, data
     else:
         if not len(data):
             return "Could Not Find Volume {}".format(volume_id), None
         else:
             return None, data[0]
コード例 #7
0
    def _get_volume_by_name(self, volume_id, zone, log):
        volume_api = VolumeAPIPool.get_volume_api_for_zone(zone, log)

        filterObj = [MongoObj(field='_id', value=volume_id)]
        err, data = volume_api.get(filter=filterObj)
        if err:
            return err, data
        else:
            if not len(data):
                return "Could Not Find Volume {}".format(volume_id), None
            else:
                return None, data[0]
コード例 #8
0
    def get_nvmesh_volume_by_name(nvmesh_vol_name, mgmt_addresses=None):
        if not mgmt_addresses:
            mgmt_addresses = TestConfig.ManagementServers

        for mgmt_address in mgmt_addresses:
            filter_obj = [MongoObj(field='_id', value=nvmesh_vol_name)]
            err, out = VolumeAPI(managementServers=mgmt_address).get(
                filter=filter_obj)
            if len(out) > 0:
                return out[0], mgmt_address

        return None, None
コード例 #9
0
    def ListVolumes(self, request, context):
        max_entries = request.max_entries
        starting_token = request.starting_token

        try:
            page = int(starting_token or 0)
        except ValueError:
            raise DriverError(StatusCode.ABORTED, "Invalid starting_token")

        if starting_token and not max_entries:
            raise DriverError(StatusCode.ABORTED, "Invalid starting_token")

        count = max_entries or 0

        projection = [
            MongoObj(field='_id', value=1),
            MongoObj(field='capacity', value=1)
        ]

        # TODO: we should probably iterate over all management servers and return all volumes while populating the volume.accessible_topology field
        zone = ''
        volume_api = VolumeAPIPool.get_volume_api_for_zone(zone, self.logger)
        err, nvmeshVolumes = volume_api.get(projection=projection,
                                            page=page,
                                            count=count)

        if err:
            raise DriverError(StatusCode.INTERNAL, err)

        def convertNVMeshVolumeToCSIVolume(volume):
            vol = Volume(volume_id=volume._id, capacity_bytes=volume.capacity)
            return ListVolumesResponse.Entry(volume=vol)

        entries = map(convertNVMeshVolumeToCSIVolume, nvmeshVolumes)
        next_token = str(page + 1)

        if not len(entries):
            DriverError(StatusCode.ABORTED, "No more Entries")

        return ListVolumesResponse(entries=entries, next_token=next_token)
コード例 #10
0
	def check_if_node_in_management(node_name, api_params, logger):
		logger.debug('Checking if node {} is in management server: {}'.format(node_name, api_params))
		try:
			client_api = NVMeshSDKHelper.get_client_api(logger, api_params)
			filter_by_node_id=[MongoObj(field='_id', value=node_name)]
			err, res = client_api.get(filter=filter_by_node_id)
			if err:
				raise err

			return len(res) > 0 and res[0]._id == node_name
		except Exception as ex:
			logger.warning('Failed to check if node {} is in management {}. Error: {}'.format(node_name, api_params, ex))
			return False
コード例 #11
0
    def get_nvmesh_volume(self, nvmesh_vol_name, minimalFields=False):
        filterObj = [MongoObj(field='_id', value=nvmesh_vol_name)]

        projection = None
        if minimalFields:
            projection = [
                MongoObj(field='_id', value=1),
                MongoObj(field='capacity', value=1),
                MongoObj(field='status', value=1),
                MongoObj(field='csi_metadata', value=1)
            ]

        err, out = VolumeAPI().get(filter=filterObj, projection=projection)
        if err:
            raise DriverError(StatusCode.INTERNAL, err)
        if not isinstance(out, list):
            raise DriverError(StatusCode.INTERNAL, out)
        if not len(out):
            raise DriverError(
                StatusCode.NOT_FOUND,
                'Volume {} Could not be found'.format(nvmesh_vol_name))

        return out[0]
コード例 #12
0
    def ListVolumes(self, request, context):
        max_entries = request.max_entries
        starting_token = request.starting_token

        try:
            page = int(starting_token or 0)
        except ValueError:
            raise DriverError(StatusCode.ABORTED, "Invalid starting_token")

        if starting_token and not max_entries:
            raise DriverError(StatusCode.ABORTED, "Invalid starting_token")

        count = max_entries or 0

        projection = [
            MongoObj(field='_id', value=1),
            MongoObj(field='capacity', value=1)
        ]

        err, nvmeshVolumes = VolumeAPI().get(projection=projection,
                                             page=page,
                                             count=count)

        if err:
            raise DriverError(StatusCode.INTERNAL, err)

        def convertNVMeshVolumeToCSIVolume(volume):
            vol = Volume(volume_id=volume._id, capacity_bytes=volume.capacity)
            return ListVolumesResponse.Entry(volume=vol)

        entries = map(convertNVMeshVolumeToCSIVolume, nvmeshVolumes)
        next_token = str(page + 1)

        if not len(entries):
            DriverError(StatusCode.ABORTED, "No more Entries")

        return ListVolumesResponse(entries=entries, next_token=next_token)
コード例 #13
0
    def delete_all_nvmesh_volumes():
        projection = [MongoObj(field='_id', value=1)]
        err, volume_list = VolumeAPI(NVMESH_MGMT_ADDRESS).get(
            projection=projection)
        if len(volume_list) != 0:
            err, out = VolumeAPI(NVMESH_MGMT_ADDRESS).delete(
                [vol._id for vol in volume_list])
            if err:
                raise TestError(
                    'Failed to delete NVMesh volumes. Error: {}'.format(err))

            for vol_res in out:
                if not vol_res['success']:
                    if 'Couldn\'t find the specified volume' not in vol_res[
                            'error']:
                        raise TestError(
                            'Failed to delete NVMesh volume {}. Error: {}'.
                            format(vol_res['_id'], vol_res['error']))
コード例 #14
0
    def get_nvmesh_volume(
        self,
        volume_api,
        nvmesh_vol_name,
    ):
        filterObj = [MongoObj(field='_id', value=nvmesh_vol_name)]

        err, out = volume_api.get(filter=filterObj)
        if err:
            raise DriverError(StatusCode.INTERNAL, err)
        if not isinstance(out, list):
            raise DriverError(StatusCode.INTERNAL, out)
        if not len(out):
            raise DriverError(
                StatusCode.NOT_FOUND,
                'Volume {} Could not be found'.format(nvmesh_vol_name))

        return out[0]
コード例 #15
0
    def getClusterName(self):
        """**Get Cluster Name**

            :return: tuple (err,out)

                **err**: HTTP error details or None if there were no errors

                **out**: list of cluster names
            :rtype: (dict, list)

            - Example::

                    from NVMeshSDK.APIs.GeneralSettingsAPI import GeneralSettingsAPI

                    generalSettingsAPI = GeneralSettingsAPI()

                    err, out = generalSettingsAPI.getClusterName()

                    >>> err
                    None
                    >>> for name in out: print name
                    {
                        "_id": "5f75d76e7a2828b50c08b76d",
                        "clusterName": "My cluster"
                    }

            - Expected HTTP Fail Response::

                >>> err
                {
                    'code': <Return Code>,
                    'content': <Failure Details>,
                    'message': <Failure Reason>
                }

                >>> out
                None
        """
        return self.get(
            projection=[MongoObj(field=GeneralSettings.ClusterName, value=1)])
コード例 #16
0
    def testZ_04_apply_to_hosts(self):

        newProfile = ConfigurationProfile(name="Test New Profile",
                                          hosts=[],
                                          description="new description !!!",
                                          labels=["updated"],
                                          version=3)

        err, apiRes = self.myAPI.save([newProfile])
        self.assertIsNone(err)

        newProfile.hosts = [
            "scale-{}.excelero.com".format(i) for i in range(1, 10)
        ]
        err, apiRes = self.myAPI.update([newProfile])
        self.assertIsNone(err)
        self.assertTrue(apiRes[0]['success'])

        err, apiRes = self.myAPI.get(
            filter=[MongoObj(field='_id', value='Test New Profile')])
        self.assertIsNone(err)
        self.assertListEqual(apiRes[0].hosts, newProfile.hosts)
コード例 #17
0
    def delete_all_nvmesh_volumes(mgmt_addresses=None):
        if not mgmt_addresses:
            mgmt_addresses = TestConfig.ManagementServers

        for mgmt_address in mgmt_addresses:
            projection = [MongoObj(field='_id', value=1)]
            err, volume_list = VolumeAPI(managementServers=mgmt_address).get(
                projection=projection)
            if len(volume_list) != 0:
                err, out = VolumeAPI(managementServers=mgmt_address).delete(
                    [vol._id for vol in volume_list])
                if err:
                    raise TestError(
                        'Failed to delete NVMesh volumes. Error: {}'.format(
                            err))

                for vol_res in out:
                    if not vol_res['success']:
                        if 'Couldn\'t find the specified volume' not in vol_res[
                                'error']:
                            raise TestError(
                                'Failed to delete NVMesh volume {}. Error: {}'.
                                format(vol_res['_id'], vol_res['error']))
コード例 #18
0
 def getClusterName(self):
     return self.get(
         projection=[MongoObj(field=GeneralSettings.ClusterName, value=1)])