示例#1
0
    def exportgroup_create(self,
                           name,
                           project_name,
                           tenant,
                           varray,
                           exportgrouptype,
                           export_destination=None):
        """This function creates the Export group with given name.

        :param name: Name of the export group
        :param project_name: Name of the project path
        :param tenant: Container tenant name
        :param varray: Name of the virtual array
        :param exportgrouptype: Type of the export group. Ex:Host etc
        :returns: status of creation
        """
        # check for existence of export group.
        try:
            status = self.exportgroup_show(name, project_name, tenant)
        except common.CoprHdError as e:
            if e.err_code == common.CoprHdError.NOT_FOUND_ERR:
                if tenant is None:
                    tenant = ""

                fullproj = tenant + "/" + project_name
                projObject = project.Project(self.ipaddr, self.port)
                projuri = projObject.project_query(fullproj)

                varrayObject = virtualarray.VirtualArray(
                    self.ipaddr, self.port)
                nhuri = varrayObject.varray_query(varray)

                parms = {
                    'name': name,
                    'project': projuri,
                    'varray': nhuri,
                    'type': exportgrouptype
                }

                if exportgrouptype and export_destination:
                    host_obj = host.Host(self.ipaddr, self.port)
                    host_uri = host_obj.query_by_name(export_destination)
                    parms['hosts'] = [host_uri]

                body = oslo_serialization.jsonutils.dumps(parms)
                (s, h) = common.service_json_request(self.ipaddr, self.port,
                                                     "POST",
                                                     self.URI_EXPORT_GROUP,
                                                     body)

                o = common.json_decode(s)
                return o
            else:
                raise

        if status:
            raise common.CoprHdError(
                common.CoprHdError.ENTRY_ALREADY_EXISTS_ERR,
                (_("Export group with name %s"
                   " already exists") % name))
示例#2
0
    def exportgroup_add_volumes(self,
                                sync,
                                exportgroupname,
                                tenantname,
                                maxpaths,
                                minpaths,
                                pathsperinitiator,
                                projectname,
                                volumenames,
                                cg=None,
                                synctimeout=0,
                                varray=None):
        """Add volume to export group.

        :param sync: synchronous request
        :param exportgroupname: Name/id of the export group
        :param tenantname: tenant name
        :param maxpaths: Maximum number of paths
        :param minpaths: Minimum number of paths
        :param pathsperinitiator: Paths per initiator
        :param projectname: name of project
        :param volumenames: names of volumes that needs
                            to be added to exportgroup
        :param cg: consistency group
        :param synctimeout: Query for task status for 'synctimeout' secs
                            If the task doesn't complete in synctimeout secs,
                            an exception is thrown
        :param varray: Name of varray
        :returns: action result
        """
        varrayuri = None
        if varray:
            varrayObject = virtualarray.VirtualArray(self.ipaddr, self.port)
            varrayuri = varrayObject.varray_query(varray)

        exportgroup_uri = self.exportgroup_query(exportgroupname, projectname,
                                                 tenantname, varrayuri)

        # get volume uri
        if tenantname is None:
            tenantname = ""
        # List of volumes
        volume_list = []

        if volumenames:
            volume_list = self._get_resource_lun_tuple(volumenames, "volumes",
                                                       None, tenantname,
                                                       projectname, None)

        parms = {}
        # construct the body

        volChanges = {}
        volChanges['add'] = volume_list
        parms['volume_changes'] = volChanges

        o = self.send_json_request(exportgroup_uri, parms)
        return self.check_for_sync(o, sync, synctimeout)
示例#3
0
    def exportgroup_show(self, name, project, tenant, varray=None):
        """This function displays the Export group with details.

        :param name: Name of the export group
        :param project: Name of the project
        :param tenant: Name of the tenant
        :returns: Details of export group
        """
        varrayuri = None
        if varray:
            varrayObject = virtualarray.VirtualArray(self.ipaddr, self.port)
            varrayuri = varrayObject.varray_query(varray)
        uri = self.exportgroup_query(name, project, tenant, varrayuri)
        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            self.URI_EXPORT_GROUPS_SHOW.format(uri), None)
        o = common.json_decode(s)
        if o['inactive']:
            return None

        return o
示例#4
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