Example #1
0
    def exportgroup_query(self, name, project, tenant, varrayuri=None):
        """Makes REST API call to query the exportgroup by name.

        :param name: Name/id of the export group
        :param project: Name of the project
        :param tenant: Name of the tenant
        :param varrayuri: URI of the virtual array
        :returns: id of the export group
        """
        if common.is_uri(name):
            return name

        uris = self.exportgroup_list(project, tenant)
        for uri in uris:
            exportgroup = self.exportgroup_show(uri, project, tenant)
            if exportgroup and exportgroup['name'] == name:
                if varrayuri:
                    varrayobj = exportgroup['varray']
                    if varrayobj['id'] == varrayuri:
                        return exportgroup['id']
                    else:
                        continue
                else:
                    return exportgroup['id']
        raise common.CoprHdError(
            common.CoprHdError.NOT_FOUND_ERR,
            (_("Export Group %s: not found") % name))
Example #2
0
    def vpool_query(self, name, vpooltype):
        """Makes REST API call to query the vpool by name and type.

        This function will take the VPOOL name and type of VPOOL
        as input and get uri of the first occurrence of given VPOOL.

        :param name: Name of the VPOOL
        :param vpooltype: Type of the VPOOL {'block'}
        :returns: uri of the given vpool
        """
        if common.is_uri(name):
            return name

        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            self.URI_VPOOL_SEARCH.format(vpooltype, name), None)

        o = common.json_decode(s)
        if len(o['resource']) > 0:
            # Get the Active vpool ID.
            for vpool in o['resource']:
                if self.vpool_show_uri(vpooltype, vpool['id']) is not None:
                    return vpool['id']
        # Raise not found exception. as we did not find any active vpool.
        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("VPool %(name)s ( %(vpooltype)s ) :"
                                    " not found") %
                                  {'name': name,
                                   'vpooltype': vpooltype
                                   }))
Example #3
0
    def show(self, full_project_name, name):
        """Retrieves volume details based on volume name.

        :param full_project_name: project path of the volume
        :param name: name of the volume. If the volume is under a project,
                     then full XPath needs to be specified.
                     Example: If VOL1 is a volume under project PROJ1,
                     then the name of volume is PROJ1/VOL1
        :returns: Volume details in JSON response payload
        """
        if common.is_uri(name):
            return name
        if full_project_name is None:
            raise common.CoprHdError(
                common.CoprHdError.NOT_FOUND_ERR,
                (_("Volume %s : not found") % six.text_type(name)))

        uris = self.search_volumes(full_project_name)

        for uri in uris:
            volume = self.show_by_uri(uri)
            if volume and 'name' in volume and volume['name'] == name:
                return volume
        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("Volume"
                                    " %s : not found") % six.text_type(name)))
Example #4
0
    def exportgroup_query(self, name, project, tenant, varrayuri=None):
        """Makes REST API call to query the exportgroup by name.

        :param name: Name/id of the export group
        :param project: Name of the project
        :param tenant: Name of the tenant
        :param varrayuri: URI of the virtual array
        :returns: id of the export group
        """
        if common.is_uri(name):
            return name

        uris = self.exportgroup_list(project, tenant)
        for uri in uris:
            exportgroup = self.exportgroup_show(uri, project, tenant)
            if exportgroup and exportgroup['name'] == name:
                if varrayuri:
                    varrayobj = exportgroup['varray']
                    if varrayobj['id'] == varrayuri:
                        return exportgroup['id']
                    else:
                        continue
                else:
                    return exportgroup['id']
        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("Export Group %s: not found") % name))
Example #5
0
    def tenant_query(self, label):
        """Returns the UID of the tenant specified by the hierarchical name.

        (ex tenant1/tenant2/tenant3)
        """

        if common.is_uri(label):
            return label

        tenant_id = self.tenant_getid()

        if not label:
            return tenant_id

        subtenants = self.tenant_list(tenant_id)
        subtenants.append(self.tenant_show(None))

        for tenant in subtenants:
            if tenant['name'] == label:
                rslt = self.tenant_show_by_uri(tenant['id'])
                if rslt:
                    return tenant['id']

        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("Tenant %s: not found") % label))
Example #6
0
    def show(self, full_project_name, name):
        """Retrieves volume details based on volume name.

        :param full_project_name : project path of the volume
        :param name: name of the volume. If the volume is under a project,
            then full XPath needs to be specified.
            Example: If VOL1 is a volume under project PROJ1, then the name
            of volume is PROJ1/VOL1
        :returns: Volume details in JSON response payload
        """
        if common.is_uri(name):
            return name
        if full_project_name is None:
            raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                     (_("Volume %s : not found") %
                                      six.text_type(name)))

        uris = self.search_volumes(full_project_name)

        for uri in uris:
            volume = self.show_by_uri(uri)
            if volume and 'name' in volume and volume['name'] == name:
                return volume
        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("Volume"
                                    " %s : not found") % six.text_type(name)))
Example #7
0
    def project_query(self, name):
        """Retrieves UUID of project based on its name.

        :param name: name of project
        :returns: UUID of project
        :raises CoprHdError: - when project name is not found
        """
        if common.is_uri(name):
            return name
        (tenant_name, project_name) = common.get_parent_child_from_xpath(name)

        tenant_obj = tenant.Tenant(self.ipaddr, self.port)

        tenant_uri = tenant_obj.tenant_query(tenant_name)
        projects = self.project_list(tenant_uri)
        if projects:
            for project in projects:
                if project:
                    project_detail = self.project_show_by_uri(
                        project['id'])
                    if(project_detail and
                       project_detail['name'] == project_name):
                        return project_detail['id']
        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR, (_(
                                 "Project: %s not found") % project_name))
Example #8
0
 def get_tenant_by_name(self, tenant):
     uri = None
     if not tenant:
         uri = self.tenant_getid()
     else:
         if not common.is_uri(tenant):
             uri = self.tenant_query(tenant)
         else:
             uri = tenant
         if not uri:
             raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                      (_("Tenant %s: not found") % tenant))
     return uri
Example #9
0
    def varray_query(self, name):
        """Returns the UID of the varray specified by the name."""
        if common.is_uri(name):
            return name

        uris = self.varray_list()

        for uri in uris:
            varray = self.varray_show(uri)
            if varray and varray['name'] == name:
                return varray['id']

        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("varray %s: not found") % name))
Example #10
0
    def varray_query(self, name):
        """Returns the UID of the varray specified by the name."""
        if common.is_uri(name):
            return name

        uris = self.varray_list()

        for uri in uris:
            varray = self.varray_show(uri)
            if varray and varray['name'] == name:
                return varray['id']

        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("varray %s: not found") % name))
    def consistencygroup_query(self, name, project, tenant):
        """This function will return consistency group id.

        :param name: Name/id of the consistency group
        :param project: Name of the project
        :param tenant: Name of the tenant
        :returns: id of the consistency group
        """
        if common.is_uri(name):
            return name

        uris = self.list(project, tenant)
        for uri in uris:
            congroup = self.show(uri, project, tenant)
            if congroup and congroup['name'] == name:
                return congroup['id']
        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("Consistency Group %s: not found") % name))
Example #12
0
    def consistencygroup_query(self, name, project, tenant):
        """This function will return consistency group id.

        :param name : Name/id of the consistency group
        :param project: Name of the project
        :param tenant: Name of the tenant
        :returns: id of the consistency group
        """
        if common.is_uri(name):
            return name

        uris = self.list(project, tenant)
        for uri in uris:
            congroup = self.show(uri, project, tenant)
            if congroup and congroup['name'] == name:
                return congroup['id']
        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("Consistency Group %s: not found") % name))
Example #13
0
    def list_initiators(self, host_name):
        """Lists all initiators for the given host.

        :param host_name: The name of the host
        """
        if not common.is_uri(host_name):
            hostUri = self.query_by_name(host_name, None)
        else:
            hostUri = host_name

        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            Host.URI_HOST_LIST_INITIATORS.format(hostUri), None)
        o = common.json_decode(s)

        if not o or "initiator" not in o:
            return []

        return common.get_node_value(o, 'initiator')
Example #14
0
    def list_initiators(self, host_name):
        """Lists all initiators for the given host.

        :param host_name: The name of the host
        """
        if not common.is_uri(host_name):
            hostUri = self.query_by_name(host_name, None)
        else:
            hostUri = host_name

        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            Host.URI_HOST_LIST_INITIATORS.format(hostUri),
            None)
        o = common.json_decode(s)

        if not o or "initiator" not in o:
            return []

        return common.get_node_value(o, 'initiator')
Example #15
0
    def volume_query(self, full_project_name, volume_name):
        """Makes REST API call to query the volume by name.

        :param volume_name: name of volume
        :param full_project_name: Full project path
        :returns: Volume details in JSON response payload
        """
        if common.is_uri(volume_name):
            return volume_name

        if not full_project_name:
            raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                     _("Project name not specified"))
        uris = self.search_volumes(full_project_name)
        for uri in uris:
            volume = self.show_by_uri(uri)
            if volume and 'name' in volume and volume['name'] == volume_name:
                return volume['id']
        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("Volume"
                                    "%s: not found") % volume_name))
Example #16
0
    def volume_query(self, full_project_name, volume_name):
        """Makes REST API call to query the volume by name.

        :param volume_name: name of volume
        :param full_project_name: Full project path
        :returns: Volume details in JSON response payload
        """
        if common.is_uri(volume_name):
            return volume_name

        if not full_project_name:
            raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                     _("Project name not specified"))
        uris = self.search_volumes(full_project_name)
        for uri in uris:
            volume = self.show_by_uri(uri)
            if volume and 'name' in volume and volume['name'] == volume_name:
                return volume['id']
        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("Volume"
                                    "%s: not found") % volume_name))
Example #17
0
    def project_query(self, name):
        """Retrieves UUID of project based on its name.

        :param name: name of project
        :returns: UUID of project
        :raises CoprHdError: - when project name is not found
        """
        if common.is_uri(name):
            return name
        (tenant_name, project_name) = common.get_parent_child_from_xpath(name)

        tenant_obj = tenant.Tenant(self.ipaddr, self.port)

        tenant_uri = tenant_obj.tenant_query(tenant_name)
        projects = self.project_list(tenant_uri)
        if projects:
            for project in projects:
                if project:
                    project_detail = self.project_show_by_uri(project['id'])
                    if (project_detail
                            and project_detail['name'] == project_name):
                        return project_detail['id']
        raise common.CoprHdError(common.CoprHdError.NOT_FOUND_ERR,
                                 (_("Project: %s not found") % project_name))