示例#1
0
    def update(self, prefix_path, name, vpool):
        """Makes REST API call to update a volume information.

        :param name: name of the volume to be updated
        :param vpool: name of vpool
        :returns: Created task details in JSON response payload
        """
        namelist = []

        if isinstance(name, list):
            namelist = name
        else:
            namelist.append(name)

        volumeurilist = []

        for item in namelist:
            volume_uri = self.volume_query(prefix_path, item)
            volumeurilist.append(volume_uri)

        vpool_obj = virtualpool.VirtualPool(self.ipaddr, self.port)
        vpool_uri = vpool_obj.vpool_query(vpool, "block")

        params = {'vpool': vpool_uri, 'volumes': volumeurilist}

        body = oslo_serialization.jsonutils.dumps(params)

        (s, h) = common.service_json_request(self.ipaddr, self.port, "POST",
                                             Volume.URI_VOLUME_CHANGE_VPOOL,
                                             body)

        o = common.json_decode(s)
        return o
示例#2
0
    def create(self,
               project_name,
               label,
               size,
               varray,
               vpool,
               sync,
               consistencygroup,
               synctimeout=0):
        """Makes REST API call to create volume under a project.

        :param project_name: name of the project under which the volume
                             will be created
        :param label: name of volume
        :param size: size of volume
        :param varray: name of varray
        :param vpool: name of vpool
        :param sync: synchronous request
        :param consistencygroup: To create volume under a consistencygroup
        :param synctimeout: Query for task status for 'synctimeout' secs.
                            If the task doesn't complete in synctimeout secs,
                            an exception is thrown
        :returns: Created task details in JSON response payload
        """

        proj_obj = project.Project(self.ipaddr, self.port)
        project_uri = proj_obj.project_query(project_name)

        vpool_obj = virtualpool.VirtualPool(self.ipaddr, self.port)
        vpool_uri = vpool_obj.vpool_query(vpool, "block")

        varray_obj = virtualarray.VirtualArray(self.ipaddr, self.port)
        varray_uri = varray_obj.varray_query(varray)

        request = {
            'name': label,
            'size': size,
            'varray': varray_uri,
            'project': project_uri,
            'vpool': vpool_uri,
            'count': 1
        }
        if consistencygroup:
            request['consistency_group'] = consistencygroup

        body = oslo_serialization.jsonutils.dumps(request)
        (s, h) = common.service_json_request(self.ipaddr, self.port, "POST",
                                             Volume.URI_VOLUMES, body)
        o = common.json_decode(s)

        if sync:
            # check task empty
            if len(o["task"]) > 0:
                task = o["task"][0]
                return self.check_for_sync(task, sync, synctimeout)
            else:
                raise common.CoprHdError(
                    common.CoprHdError.SOS_FAILURE_ERR,
                    _("error: task list is empty, no task response found"))
        else:
            return o