コード例 #1
0
    def exportgroup_list(self, project_name, tenant):
        """This function gives list of export group uris separated by comma.

        :param project_name: Name of the project path
        :param tenant: Name of the tenant
        :returns: list of export group ids separated by comma
        """
        if tenant is None:
            tenant = ""
        projobj = project.Project(self.ipaddr, self.port)
        fullproj = tenant + "/" + project_name
        projuri = projobj.project_query(fullproj)

        uri = self.URI_EXPORT_GROUP_SEARCH

        if '?' in uri:
            uri += '&project=' + projuri
        else:
            uri += '?project=' + projuri

        (s, h) = common.service_json_request(self.ipaddr, self.port, "GET",
                                             uri, None)
        o = common.json_decode(s)
        if not o:
            return []

        exportgroups = []
        resources = common.get_node_value(o, "resource")
        for resource in resources:
            exportgroups.append(resource["id"])

        return exportgroups
コード例 #2
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))
コード例 #3
0
    def list(self, project_name, tenant):
        """This function gives list of comma separated consistency group uris.

        :param project_name: Name of the project path
        :param tenant: Name of the tenant
        :returns: list of consistency group ids separated by comma
        """
        if tenant is None:
            tenant = ""
        projobj = project.Project(self.ipaddr, self.port)
        fullproj = tenant + "/" + project_name
        projuri = projobj.project_query(fullproj)

        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            self.URI_CONSISTENCY_GROUPS_SEARCH.format(projuri), None)
        o = common.json_decode(s)
        if not o:
            return []

        congroups = []
        resources = common.get_node_value(o, "resource")
        for resource in resources:
            congroups.append(resource["id"])

        return congroups
コード例 #4
0
    def search_volumes(self, project_name):

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

        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            Volume.URI_SEARCH_VOLUMES.format(project_uri), None)
        o = common.json_decode(s)
        if not o:
            return []

        volume_uris = []
        resources = common.get_node_value(o, "resource")
        for resource in resources:
            volume_uris.append(resource["id"])
        return volume_uris
コード例 #5
0
    def create(self, name, project_name, tenant):
        """This function will create consistency group with the given name.

        :param name : Name of the consistency group
        :param project_name: Name of the project path
        :param tenant: Container tenant name
        :returns: status of creation
        """
        # check for existence of consistency group.
        try:
            status = self.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
                projobj = project.Project(self.ipaddr, self.port)
                projuri = projobj.project_query(fullproj)

                parms = {
                    'name': name,
                    'project': projuri,
                }
                body = oslo_serialization.jsonutils.dumps(parms)

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

                o = common.json_decode(s)
                return o
            else:
                raise
        if status:
            common.format_err_msg_and_raise(
                "create", "consistency group",
                (_("consistency group with name: %s already exists") % name),
                common.CoprHdError.ENTRY_ALREADY_EXISTS_ERR)
コード例 #6
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