Exemple #1
0
    def volume_clone_detach(self,
                            resource_uri,
                            full_project_name,
                            name,
                            sync,
                            synctimeout=0):

        volume_uri = self.volume_query(full_project_name, name)

        # consistency group
        if resource_uri.find("BlockConsistencyGroup") > 0:
            (s, h) = common.service_json_request(
                self.ipaddr, self.port, "POST",
                Volume.URI_CG_CLONE_DETACH.format(resource_uri, volume_uri),
                None)
        else:
            (s, h) = common.service_json_request(
                self.ipaddr, self.port, "POST",
                Volume.URI_VOLUME_CLONE_DETACH.format(volume_uri), None)

        o = common.json_decode(s)
        if sync:
            task = o["task"][0]
            return self.check_for_sync(task, sync, synctimeout)
        else:
            return o
Exemple #2
0
    def volume_clone_detach(self, resource_uri, full_project_name,
                            name, sync, synctimeout=0):

        volume_uri = self.volume_query(full_project_name, name)

        # consistency group
        if resource_uri.find("BlockConsistencyGroup") > 0:
            (s, h) = common.service_json_request(
                self.ipaddr, self.port,
                "POST",
                Volume.URI_CG_CLONE_DETACH.format(
                    resource_uri,
                    volume_uri), None)
        else:
            (s, h) = common.service_json_request(
                self.ipaddr, self.port,
                "POST",
                Volume.URI_VOLUME_CLONE_DETACH.format(volume_uri), None)

        o = common.json_decode(s)
        if sync:
            task = o["task"][0]
            return self.check_for_sync(task, sync, synctimeout)
        else:
            return o
Exemple #3
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
    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
                                   }))
Exemple #5
0
    def expand(self, full_project_name, volume_name, new_size,
               sync=False, synctimeout=0):

        volume_detail = self.show(full_project_name, volume_name)
        from decimal import Decimal
        new_size_in_gb = Decimal(Decimal(new_size) / (units.Gi))
        current_size = Decimal(volume_detail["provisioned_capacity_gb"])
        if new_size_in_gb <= current_size:
            raise common.CoprHdError(
                common.CoprHdError.VALUE_ERR,
                (_("error: Incorrect value of new size: %(new_size_in_gb)s"
                   " GB\nNew size must be greater than current size: "
                   "%(current_size)s GB") % {'new_size_in_gb': new_size_in_gb,
                                             'current_size': current_size}))

        body = oslo_serialization.jsonutils.dumps({
            "new_size": new_size
        })

        (s, h) = common.service_json_request(self.ipaddr, self.port,
                                             "POST",
                                             Volume.URI_EXPAND.format(
                                                 volume_detail["id"]),
                                             body)
        if not s:
            return None
        o = common.json_decode(s)

        if sync:
            return self.check_for_sync(o, sync, synctimeout)
        return o
Exemple #6
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
Exemple #7
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))
Exemple #8
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
Exemple #9
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
Exemple #10
0
    def expand(self,
               full_project_name,
               volume_name,
               new_size,
               sync=False,
               synctimeout=0):

        volume_detail = self.show(full_project_name, volume_name)
        from decimal import Decimal
        new_size_in_gb = Decimal(Decimal(new_size) / (units.Gi))
        current_size = Decimal(volume_detail["provisioned_capacity_gb"])
        if new_size_in_gb <= current_size:
            raise common.CoprHdError(
                common.CoprHdError.VALUE_ERR,
                (_("error: Incorrect value of new size: %(new_size_in_gb)s"
                   " GB\nNew size must be greater than current size: "
                   "%(current_size)s GB") % {
                       'new_size_in_gb': new_size_in_gb,
                       'current_size': current_size
                   }))

        body = oslo_serialization.jsonutils.dumps({"new_size": new_size})

        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "POST",
            Volume.URI_EXPAND.format(volume_detail["id"]), body)
        if not s:
            return None
        o = common.json_decode(s)

        if sync:
            return self.check_for_sync(o, sync, synctimeout)
        return o
    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
    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)
Exemple #13
0
    def clone(self, new_vol_name, resource_uri,
              sync, synctimeout=0):
        """Makes REST API call to clone volume.

        :param new_vol_name: name of volume
        :param resource_uri: uri of source volume
        :param sync        : synchronous request
        :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
        """
        from cinder.volume.drivers.coprhd.helpers import snapshot
        snap_obj = snapshot.Snapshot(self.ipaddr, self.port)
        is_snapshot_clone = False
        clone_full_uri = None

        # consistency group
        if resource_uri.find("BlockConsistencyGroup") > 0:
            clone_full_uri = Volume.URI_CG_CLONE.format(resource_uri)
        elif resource_uri.find("BlockSnapshot") > 0:
            is_snapshot_clone = True
            clone_full_uri = (
                Volume.URI_SNAPSHOT_PROTECTION_FULLCOPIES.format(resource_uri))
        else:
            clone_full_uri = (
                Volume.URI_VOLUME_PROTECTION_FULLCOPIES.format(resource_uri))

        request = {
            'name': new_vol_name,
            'type': None,
            'count': 1
        }

        request["count"] = 1

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

        if sync:
            task = o["task"][0]

            if is_snapshot_clone:
                return (
                    snap_obj.block_until_complete(
                        "block",
                        task["resource"]["id"],
                        task["id"])
                )
            else:
                return self.check_for_sync(task, sync, synctimeout)
        else:
            return o
Exemple #14
0
 def search_by_name(self, host_name):
     """Search host by its name."""
     (s, h) = common.service_json_request(
         self.ipaddr, self.port, "GET",
         self.URI_HOSTS_SEARCH_BY_NAME.format(host_name), None)
     o = common.json_decode(s)
     if not o:
         return []
     return common.get_node_value(o, "resource")
Exemple #15
0
    def tag_resource(self, uri, resource_id, add, remove):
        params = {'add': add, 'remove': remove}

        body = oslo_serialization.jsonutils.dumps(params)

        (s, h) = common.service_json_request(self.ipaddr, self.port, "PUT",
                                             uri.format(resource_id), body)
        o = common.json_decode(s)
        return o
Exemple #16
0
    def update(self,
               uri,
               project,
               tenant,
               add_volumes,
               remove_volumes,
               sync,
               synctimeout=0):
        """Function used to add or remove volumes from consistency group.

        It will update the consistency group with given volumes

        :param uri           : URI of the consistency group
        :param project       : Name of the project path
        :param tenant        : Container tenant name
        :param add_volumes   : volumes to be added to the consistency group
        :param remove_volumes: volumes to be removed from CG
        :param sync          : synchronous request
        :param synctimeout   : Query for task status for "synctimeout" secs.
                               If the task doesn't complete in synctimeout
                               secs, an exception is thrown
        :returns: status of creation
        """
        if tenant is None:
            tenant = ""

        parms = []
        add_voluris = []
        remove_voluris = []
        from cinder.volume.drivers.coprhd.helpers.volume import Volume
        volobj = Volume(self.ipaddr, self.port)
        if add_volumes:
            for volname in add_volumes:
                full_project_name = tenant + "/" + project
                add_voluris.append(
                    volobj.volume_query(full_project_name, volname))
            volumes = {'volume': add_voluris}
            parms = {'add_volumes': volumes}

        if remove_volumes:
            for volname in remove_volumes:
                full_project_name = tenant + "/" + project
                remove_voluris.append(
                    volobj.volume_query(full_project_name, volname))
            volumes = {'volume': remove_voluris}
            parms = {'remove_volumes': volumes}

        body = oslo_serialization.jsonutils.dumps(parms)
        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "PUT",
            self.URI_CONSISTENCY_GROUPS_INSTANCE.format(uri), body)

        o = common.json_decode(s)
        if sync:
            return self.check_for_sync(o, sync, synctimeout)
        else:
            return o
Exemple #17
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
Exemple #18
0
    def get_exports_by_uri(self, uri):
        """Makes REST API call to get exports info of a volume.

        :param uri: URI of the volume
        :returns: Exports details in JSON response payload
        """
        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            Volume.URI_VOLUME_EXPORTS.format(uri), None)
        return common.json_decode(s)
Exemple #19
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))
Exemple #20
0
    def snapshot_delete_uri(self, otype, resource_uri,
                            suri, sync, synctimeout=0):
        """Delete a snapshot by uri.

        :param otype : block
        :param resource_uri: uri of the source resource
        :param suri : Uri of the Snapshot
        :param sync : To perform operation synchronously
        :param synctimeout : Query for task status for "synctimeout" secs. If
                          the task doesn't complete in synctimeout secs, an
                          exception is thrown
        """
        s = None
        if resource_uri.find("Volume") > 0:

            (s, h) = common.service_json_request(
                self.ipaddr, self.port,
                "POST",
                Snapshot.URI_RESOURCE_DEACTIVATE.format(
                    Snapshot.URI_BLOCK_SNAPSHOTS.format(suri)),
                None)
        elif resource_uri.find("BlockConsistencyGroup") > 0:

            (s, h) = common.service_json_request(
                self.ipaddr, self.port,
                "POST",
                Snapshot.URI_CONSISTENCY_GROUPS_SNAPSHOT_DEACTIVATE.format(
                    resource_uri,
                    suri),
                None)
        o = common.json_decode(s)
        task = o["task"][0]

        if sync:
            return (
                common.block_until_complete(
                    otype,
                    task['resource']['id'],
                    task["id"], self.ipaddr, self.port, synctimeout)
            )
        else:
            return o
Exemple #21
0
    def snapshot_show_uri(self, otype, resource_uri, suri):
        """Retrieves snapshot details based on snapshot Name or Label.

        :param otype : block
        :param suri : uri of the Snapshot.
        :param resource_uri: uri of the source resource
        :returns: Snapshot details in JSON response payload
        """
        if (resource_uri is not None
                and resource_uri.find('BlockConsistencyGroup') > 0):
            (s, h) = common.service_json_request(
                self.ipaddr, self.port, "GET",
                Snapshot.URI_CONSISTENCY_GROUPS_SNAPSHOT_INSTANCE.format(
                    resource_uri, suri), None)
        else:
            (s, h) = common.service_json_request(
                self.ipaddr, self.port, "GET",
                Snapshot.URI_SNAPSHOTS.format(otype, suri), None)

        return common.json_decode(s)
Exemple #22
0
    def show_by_uri(self, uri):
        """Makes REST API call to retrieve Host details based on its UUID."""
        (s, h) = common.service_json_request(self.ipaddr, self.port, "GET",
                                             Host.URI_HOST_DETAILS.format(uri),
                                             None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')

        if inactive:
            return None
        return o
Exemple #23
0
    def tenant_show_by_uri(self, uri):
        """Makes REST API call to retrieve tenant details based on UUID."""
        (s, h) = common.service_json_request(self.ipaddr, self.port, "GET",
                                             Tenant.URI_TENANTS.format(uri),
                                             None)

        o = common.json_decode(s)
        if 'inactive' in o and o['inactive']:
            return None

        return o
Exemple #24
0
    def show_by_uri(self, uri):
        """Makes REST API call to retrieve Host details based on its UUID."""
        (s, h) = common.service_json_request(self.ipaddr, self.port, "GET",
                                             Host.URI_HOST_DETAILS.format(uri),
                                             None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')

        if inactive:
            return None
        return o
Exemple #25
0
    def tag_resource(self, uri, resource_id, add, remove):
        params = {
            'add': add,
            'remove': remove
        }

        body = oslo_serialization.jsonutils.dumps(params)

        (s, h) = common.service_json_request(self.ipaddr, self.port, "PUT",
                                             uri.format(resource_id), body)
        o = common.json_decode(s)
        return o
Exemple #26
0
    def get_exports_by_uri(self, uri):
        """Makes REST API call to get exports info of a volume.

        :param uri: URI of the volume
        :returns: Exports details in JSON response payload
        """
        (s, h) = common.service_json_request(self.ipaddr, self.port,
                                             "GET",
                                             Volume.URI_VOLUME_EXPORTS.format(
                                                 uri),
                                             None)
        return common.json_decode(s)
    def update(self, uri, project, tenant, add_volumes, remove_volumes,
               sync, synctimeout=0):
        """Function used to add or remove volumes from consistency group.

        It will update the consistency group with given volumes

        :param uri: URI of the consistency group
        :param project: Name of the project path
        :param tenant: Container tenant name
        :param add_volumes: volumes to be added to the consistency group
        :param remove_volumes: volumes to be removed from CG
        :param sync: synchronous request
        :param synctimeout: Query for task status for 'synctimeout' secs.
                            If the task doesn't complete in synctimeout
                            secs, an exception is thrown
        :returns: status of creation
        """
        if tenant is None:
            tenant = ""

        parms = []
        add_voluris = []
        remove_voluris = []
        from cinder.volume.drivers.coprhd.helpers.volume import Volume
        volobj = Volume(self.ipaddr, self.port)
        if add_volumes:
            for volname in add_volumes:
                full_project_name = tenant + "/" + project
                add_voluris.append(
                    volobj.volume_query(full_project_name, volname))
            volumes = {'volume': add_voluris}
            parms = {'add_volumes': volumes}

        if remove_volumes:
            for volname in remove_volumes:
                full_project_name = tenant + "/" + project
                remove_voluris.append(
                    volobj.volume_query(full_project_name, volname))
            volumes = {'volume': remove_voluris}
            parms = {'remove_volumes': volumes}

        body = oslo_serialization.jsonutils.dumps(parms)
        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "PUT",
            self.URI_CONSISTENCY_GROUPS_INSTANCE.format(uri),
            body)

        o = common.json_decode(s)
        if sync:
            return self.check_for_sync(o, sync, synctimeout)
        else:
            return o
Exemple #28
0
    def varray_show(self, label):
        """Makes REST API call to retrieve varray details based on name."""
        uri = self.varray_query(label)

        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            VirtualArray.URI_VIRTUALARRAY_URI.format(uri), None)

        o = common.json_decode(s)
        if 'inactive' in o and o['inactive'] is True:
            return None
        else:
            return o
Exemple #29
0
    def list_tags(self, resource_uri):
        if resource_uri.__contains__("tag") is False:
            raise common.CoprHdError(common.CoprHdError.VALUE_ERR,
                                     _("URI should end with /tag"))

        (s, h) = common.service_json_request(self.ipaddr, self.port, "GET",
                                             resource_uri, None)

        allTags = []
        o = common.json_decode(s)
        allTags = o['tag']

        return allTags
Exemple #30
0
    def snapshot_delete_uri(self,
                            otype,
                            resource_uri,
                            suri,
                            sync,
                            synctimeout=0):
        """Delete a snapshot by uri.

        :param otype : block
        :param resource_uri: uri of the source resource
        :param suri : Uri of the Snapshot
        :param sync : To perform operation synchronously
        :param synctimeout : Query for task status for "synctimeout" secs. If
                          the task doesn't complete in synctimeout secs, an
                          exception is thrown
        """
        s = None
        if resource_uri.find("Volume") > 0:

            (s, h) = common.service_json_request(
                self.ipaddr, self.port, "POST",
                Snapshot.URI_RESOURCE_DEACTIVATE.format(
                    Snapshot.URI_BLOCK_SNAPSHOTS.format(suri)), None)
        elif resource_uri.find("BlockConsistencyGroup") > 0:

            (s, h) = common.service_json_request(
                self.ipaddr, self.port, "POST",
                Snapshot.URI_CONSISTENCY_GROUPS_SNAPSHOT_DEACTIVATE.format(
                    resource_uri, suri), None)
        o = common.json_decode(s)
        task = o["task"][0]

        if sync:
            return (common.block_until_complete(otype, task['resource']['id'],
                                                task["id"], self.ipaddr,
                                                self.port, synctimeout))
        else:
            return o
Exemple #31
0
    def list_all(self, tenant_name):
        """Gets the ids and self links for all compute elements."""
        restapi = self.URI_COMPUTE_HOST
        tenant_obj = tenant.Tenant(self.ipaddr, self.port)
        if tenant_name is None:
            tenant_uri = tenant_obj.tenant_getid()
        else:
            tenant_uri = tenant_obj.tenant_query(tenant_name)
        restapi = restapi + "?tenant=" + tenant_uri

        (s, h) = common.service_json_request(self.ipaddr, self.port, "GET",
                                             restapi, None)
        o = common.json_decode(s)
        return o['host']
Exemple #32
0
    def snapshot_list_uri(self, otype, otypename, ouri):
        """Makes REST API call to list snapshots under a volume.

        :param otype     : block
        :param otypename : either volume or consistency-group should be
                           provided
        :param ouri      : uri of volume or consistency-group
        :returns: list of snapshots
        """
        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            Snapshot.URI_SNAPSHOT_LIST.format(otype, otypename, ouri), None)
        o = common.json_decode(s)
        return o['snapshot']
Exemple #33
0
    def varray_show(self, label):
        """Makes REST API call to retrieve varray details based on name."""
        uri = self.varray_query(label)

        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            VirtualArray.URI_VIRTUALARRAY_URI.format(uri),
            None)

        o = common.json_decode(s)
        if 'inactive' in o and o['inactive'] is True:
            return None
        else:
            return o
Exemple #34
0
    def snapshot_list_uri(self, otype, otypename, ouri):
        """Makes REST API call to list snapshots under a volume.

        :param otype     : block
        :param otypename : either volume or consistency-group should be
                           provided
        :param ouri      : uri of volume or consistency-group
        :returns: list of snapshots
        """
        (s, h) = common.service_json_request(
            self.ipaddr, self.port,
            "GET",
            Snapshot.URI_SNAPSHOT_LIST.format(otype, otypename, ouri), None)
        o = common.json_decode(s)
        return o['snapshot']
Exemple #35
0
    def snapshot_show_uri(self, otype, resource_uri, suri):
        """Retrieves snapshot details based on snapshot Name or Label.

        :param otype : block
        :param suri : uri of the Snapshot.
        :param resource_uri: uri of the source resource
        :returns: Snapshot details in JSON response payload
        """
        if(resource_uri is not None and
           resource_uri.find('BlockConsistencyGroup') > 0):
            (s, h) = common.service_json_request(
                self.ipaddr, self.port,
                "GET",
                Snapshot.URI_CONSISTENCY_GROUPS_SNAPSHOT_INSTANCE.format(
                    resource_uri,
                    suri),
                None)
        else:
            (s, h) = common.service_json_request(
                self.ipaddr, self.port,
                "GET",
                Snapshot.URI_SNAPSHOTS.format(otype, suri), None)

        return common.json_decode(s)
Exemple #36
0
    def show_by_uri(self, uri):
        """Makes REST API call and retrieves volume details based on UUID.

        :param uri: UUID of volume
        :returns: Volume details in JSON response payload
        """

        (s, h) = common.service_json_request(self.ipaddr, self.port, "GET",
                                             Volume.URI_VOLUME.format(uri),
                                             None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')
        if inactive:
            return None
        return o
Exemple #37
0
    def show_by_uri(self, uri):
        """Makes REST API call and retrieves volume details based on UUID.

        :param uri: UUID of volume
        :returns: Volume details in JSON response payload
        """

        (s, h) = common.service_json_request(self.ipaddr, self.port,
                                             "GET",
                                             Volume.URI_VOLUME.format(uri),
                                             None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')
        if inactive:
            return None
        return o
Exemple #38
0
    def project_show_by_uri(self, uri):
        """Makes REST API call and retrieves project derails based on UUID.

        :param uri: UUID of project
        :returns: Project details in JSON response payload
        """

        (s, h) = common.service_json_request(self.ipaddr, self.port, "GET",
                                             Project.URI_PROJECT.format(uri),
                                             None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')
        if inactive:
            return None

        return o
Exemple #39
0
    def show(self, name, project, tenant):
        """This function will display the consistency group with details.

        :param name : Name of the consistency group
        :param project: Name of the project
        :param tenant: Name of the tenant
        :returns: details of consistency group
        """
        uri = self.consistencygroup_query(name, project, tenant)
        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            self.URI_CONSISTENCY_GROUPS_INSTANCE.format(uri), None)
        o = common.json_decode(s)
        if o['inactive']:
            return None
        return o
Exemple #40
0
    def list_tags(self, resource_uri):
        if resource_uri.__contains__("tag") is False:
            raise common.CoprHdError(
                common.CoprHdError.VALUE_ERR, _("URI should end with /tag"))

        (s, h) = common.service_json_request(self.ipaddr,
                                             self.port,
                                             "GET",
                                             resource_uri,
                                             None)

        allTags = []
        o = common.json_decode(s)
        allTags = o['tag']

        return allTags
Exemple #41
0
    def project_list(self, tenant_name):
        """Makes REST API call and retrieves projects based on tenant UUID.

        :param tenant_name: Name of the tenant
        :returns: List of project UUIDs in JSON response payload
        """
        tenant_obj = tenant.Tenant(self.ipaddr, self.port)
        tenant_uri = tenant_obj.tenant_query(tenant_name)
        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            Project.URI_PROJECT_LIST.format(tenant_uri), None)
        o = common.json_decode(s)

        if "project" in o:
            return common.get_list(o, 'project')
        return []
    def show(self, name, project, tenant):
        """This function will display the consistency group with details.

        :param name: Name of the consistency group
        :param project: Name of the project
        :param tenant: Name of the tenant
        :returns: details of consistency group
        """
        uri = self.consistencygroup_query(name, project, tenant)
        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            self.URI_CONSISTENCY_GROUPS_INSTANCE.format(uri), None)
        o = common.json_decode(s)
        if o['inactive']:
            return None
        return o
Exemple #43
0
    def clone(self, new_vol_name, resource_uri, sync, synctimeout=0):
        """Makes REST API call to clone volume.

        :param new_vol_name: name of volume
        :param resource_uri: uri of source volume
        :param sync: synchronous request
        :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
        """
        is_snapshot_clone = False
        clone_full_uri = None

        # consistency group
        if resource_uri.find("BlockConsistencyGroup") > 0:
            clone_full_uri = Volume.URI_CG_CLONE.format(resource_uri)
        elif resource_uri.find("BlockSnapshot") > 0:
            is_snapshot_clone = True
            clone_full_uri = (
                Volume.URI_SNAPSHOT_PROTECTION_FULLCOPIES.format(resource_uri))
        else:
            clone_full_uri = (
                Volume.URI_VOLUME_PROTECTION_FULLCOPIES.format(resource_uri))

        request = {'name': new_vol_name, 'type': None, 'count': 1}

        request["count"] = 1

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

        if sync:
            task = o["task"][0]

            if is_snapshot_clone:
                return (common.block_until_complete("block",
                                                    task["resource"]["id"],
                                                    task["id"], self.ipaddr,
                                                    self.port))
            else:
                return self.check_for_sync(task, sync, synctimeout)
        else:
            return o
Exemple #44
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
Exemple #45
0
    def list_all(self, tenant_name):
        """Gets the ids and self links for all compute elements."""
        restapi = self.URI_COMPUTE_HOST
        tenant_obj = tenant.Tenant(self.ipaddr, self.port)
        if tenant_name is None:
            tenant_uri = tenant_obj.tenant_getid()
        else:
            tenant_uri = tenant_obj.tenant_query(tenant_name)
        restapi = restapi + "?tenant=" + tenant_uri

        (s, h) = common.service_json_request(
            self.ipaddr, self.port,
            "GET",
            restapi,
            None)
        o = common.json_decode(s)
        return o['host']
Exemple #46
0
    def delete(self, name, project, tenant, coprhdonly=False):
        """This function marks a particular consistency group as delete.

        :param name: Name of the consistency group
        :param project: Name of the project
        :param tenant: Name of the tenant
        :returns: status of the delete operation
            false, incase it fails to do delete
        """
        params = ''
        if coprhdonly is True:
            params += "?type=" + 'CoprHD_ONLY'
        uri = self.consistencygroup_query(name, project, tenant)
        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "POST",
            self.URI_CONSISTENCY_GROUPS_DEACTIVATE.format(uri) + params, None)
        return
Exemple #47
0
    def project_list(self, tenant_name):
        """Makes REST API call and retrieves projects based on tenant UUID.

        :param tenant_name: Name of the tenant
        :returns: List of project UUIDs in JSON response payload
        """
        tenant_obj = tenant.Tenant(self.ipaddr, self.port)
        tenant_uri = tenant_obj.tenant_query(tenant_name)
        (s, h) = common.service_json_request(self.ipaddr, self.port, "GET",
                                             Project.URI_PROJECT_LIST.format(
                                                 tenant_uri),
                                             None)
        o = common.json_decode(s)

        if "project" in o:
            return common.get_list(o, 'project')
        return []
Exemple #48
0
    def project_show_by_uri(self, uri):
        """Makes REST API call and retrieves project derails based on UUID.

        :param uri: UUID of project
        :returns: Project details in JSON response payload
        """

        (s, h) = common.service_json_request(self.ipaddr, self.port,
                                             "GET",
                                             Project.URI_PROJECT.format(uri),
                                             None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')
        if inactive:
            return None

        return o
Exemple #49
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')
    def delete(self, name, project, tenant, coprhdonly=False):
        """This function marks a particular consistency group as delete.

        :param name: Name of the consistency group
        :param project: Name of the project
        :param tenant: Name of the tenant
        :returns: status of the delete operation
            false, incase it fails to do delete
        """
        params = ''
        if coprhdonly is True:
            params += "?type=" + 'CoprHD_ONLY'
        uri = self.consistencygroup_query(name, project, tenant)
        (s, h) = common.service_json_request(
            self.ipaddr, self.port,
            "POST",
            self.URI_CONSISTENCY_GROUPS_DEACTIVATE.format(uri) + params,
            None)
        return
Exemple #51
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
Exemple #52
0
    def vpool_show_uri(self, vpooltype, uri):
        """Makes REST API call and retrieves vpool details based on UUID.

        This function will take uri as input and returns with
        all parameters of VPOOL like label, urn and type.

        :param vpooltype : Type of virtual pool {'block'}
        :param uri : unique resource identifier of the vpool
        :returns: object containing all the details of vpool
        """

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

        o = common.json_decode(s)
        if o["inactive"]:
            return None

        return o
    def vpool_show_uri(self, vpooltype, uri):
        """Makes REST API call and retrieves vpool details based on UUID.

        This function will take uri as input and returns with
        all parameters of VPOOL like label, urn and type.

        :param vpooltype : Type of virtual pool {'block'}
        :param uri : unique resource identifier of the vpool
        :returns: object containing all the details of vpool
        """

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

        o = common.json_decode(s)
        if o['inactive']:
            return None

        return o
Exemple #54
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')
Exemple #55
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
Exemple #56
0
    def delete_by_uri(self, uri, sync=False,
                      force_delete=False, coprhdonly=False, synctimeout=0):
        """Deletes a volume based on volume uri."""
        params = ''
        if force_delete:
            params += '&' if ('?' in params) else '?'
            params += "force=" + "true"
        if coprhdonly is True:
            params += '&' if ('?' in params) else '?'
            params += "type=" + 'CoprHD_ONLY'

        (s, h) = common.service_json_request(self.ipaddr, self.port,
                                             "POST",
                                             Volume.URI_DEACTIVATE.format(
                                                 uri) + params,
                                             None)
        if not s:
            return None
        o = common.json_decode(s)
        if sync:
            return self.check_for_sync(o, sync, synctimeout)
        return o
Exemple #57
0
    def varray_list(self, vdcname=None):
        """Returns all the varrays in a vdc.

        :param vdcname: Name of the Virtual Data Center
        :returns: JSON payload of varray list
        """
        vdcrestapi = None
        if vdcname is not None:
            vdcrestapi = VirtualArray.URI_VIRTUALARRAY_BY_VDC_ID.format(
                vdcname)
        else:
            vdcrestapi = VirtualArray.URI_VIRTUALARRAY
        (s, h) = common.service_json_request(self.ipaddr, self.port, "GET",
                                             vdcrestapi, None)

        o = common.json_decode(s)

        returnlst = []
        for item in o['varray']:
            returnlst.append(item['id'])

        return returnlst
Exemple #58
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)
Exemple #59
0
    def varray_list(self, vdcname=None):
        """Returns all the varrays in a vdc.

        :param vdcname: Name of the Virtual Data Center
        :returns: JSON payload of varray list
        """
        vdcrestapi = None
        if vdcname is not None:
            vdcrestapi = VirtualArray.URI_VIRTUALARRAY_BY_VDC_ID.format(
                vdcname)
        else:
            vdcrestapi = VirtualArray.URI_VIRTUALARRAY
        (s, h) = common.service_json_request(
            self.ipaddr, self.port, "GET",
            vdcrestapi, None)

        o = common.json_decode(s)

        returnlst = []
        for item in o['varray']:
            returnlst.append(item['id'])

        return returnlst