Exemplo n.º 1
0
    def assign(self, name, varray=None):
        '''
        Retrieves network details based on network name
        Parameters:
            name: name of the network.
            varray: varray to be assigned
        Returns:
            Network details in JSON response payload
        '''

        turi = self.query_by_name(name)
        nuri = None
        nlst = []
        if (varray):
            varray_obj = VirtualArray(self.__ipAddr, self.__port)
            for item in varray:
                nuri = varray_obj.varray_query(item)
                nlst.append(nuri)

        if (len(nlst) > 0):
            parms = {'varrays': nlst}
        else:
            parms = {'varrays': []}

        body = json.dumps(parms)
        common.service_json_request(self.__ipAddr, self.__port, "PUT",
                                    Network.URI_NETWORK.format(turi), body)
Exemplo n.º 2
0
    def protection_copyparam(self,
                             copyvarray,
                             pit,
                             type="native",
                             sync='false'):
        copies_param = dict()
        copy = dict()
        copy_entries = []

        copy['type'] = type

        if (pit != ""):
            copy['pointInTime'] = pit
        #true=split
        if (sync == 'true'):
            copy['sync'] = "true"
        else:
            copy['sync'] = "false"
        #for rp and srdf target virtual array should be provided
        from virtualarray import VirtualArray
        varray_obj = VirtualArray(self.__ipAddr, self.__port)
        varray_uri = varray_obj.varray_query(copyvarray)

        copy['copyID'] = varray_uri
        copy_entries.append(copy)
        copies_param['copy'] = copy_entries
        return json.dumps(copies_param)
Exemplo n.º 3
0
    def storageport_update_uri(self, spuri, tzuri, varraysToAdd,
                               varrayToRemove, port_nw_id):

        # varray changes
        varray_obj = VirtualArray(self.__ipAddr, self.__port)
        addvarrayList = varray_obj.convertNamesToUris(varraysToAdd)
        removevarrayList = varray_obj.convertNamesToUris(varrayToRemove)

        parms = {
            'varray_assignment_changes': {
                'add': {
                    'varrays': addvarrayList
                },
                'remove': {
                    'varrays': removevarrayList
                }
            }
        }

        # Network to be associated
        if (tzuri):
            parms['network'] = tzuri

        if (port_nw_id):
            parms['port_network_id'] = port_nw_id

        body = json.dumps(parms)

        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port, "PUT",
            Storageport.URI_STORAGEPORT_UPDATE.format(spuri), body)
        return common.json_decode(s)
Exemplo n.º 4
0
    def computevpool_create(self, name, systemtype, description,
                            usematchedpools, varrays, minprocessors,
                            maxprocessors, mincores, maxcores, minthreads,
                            maxthreads, mincpuspeed, maxcpuspeed, minmemory,
                            maxmemory, minnics, maxnics, minhbas, maxhbas,
                            templates):
        params = {'name': name}
        #varray details to computevpool
        if (varrays):
            varrobj = VirtualArray(self.__ipAddr, self.__port)
            varr_list = []
            for varray in varrays:
                varr_list.append(varrobj.varray_query(varray))
            params["varrays"] = varr_list

        #service profile templates
        if (templates):
            params["service_profile_template"] = templates

        self._computevpool_prepare_payload(params, systemtype, description,
                                           usematchedpools, minprocessors,
                                           maxprocessors, mincores, maxcores,
                                           minthreads, maxthreads, mincpuspeed,
                                           maxcpuspeed, minmemory, maxmemory,
                                           minnics, maxnics, minhbas, maxhbas)

        body = json.dumps(params)
        (s, h) = common.service_json_request(self.__ipAddr, self.__port,
                                             "POST", self.URI_COMPUTE_VPOOL,
                                             body)

        return common.json_decode(s)
Exemplo n.º 5
0
    def computevpool_update(self, name, label, systemtype, description,
                            usematchedpools, minprocessors, maxprocessors,
                            mincores, maxcores, minthreads, maxthreads,
                            mincpuspeed, maxcpuspeed, minmemory, maxmemory,
                            minnics, maxnics, minhbas, maxhbas, varray_add,
                            varray_remove, templates_add, templates_remove):
        compute_uri = self.computevpool_query(name)
        params = {'name': label}
        self._computevpool_prepare_payload(params, systemtype, description,
                                           usematchedpools, minprocessors,
                                           maxprocessors, mincores, maxcores,
                                           minthreads, maxthreads, mincpuspeed,
                                           maxcpuspeed, minmemory, maxmemory,
                                           minnics, maxnics, minhbas, maxhbas)

        nhobj = VirtualArray(self.__ipAddr, self.__port)
        if (varray_add):
            add_varr_list = []
            for varray in varray_add:
                add_varr_list.append(nhobj.varray_query(varray))
            params['varray_changes'] = {'add': {'varrays': add_varr_list}}

        if (varray_remove):
            remove_varr_list = []
            for varray in varray_remove:
                remove_varr_list.append(nhobj.varray_query(varray))
            params['varray_changes'] = {
                'remove': {
                    'varrays': remove_varr_list
                }
            }

        if (templates_add):
            params['service_profile_template_changes'] = {
                'add': {
                    'service_profile_template': templates_add
                }
            }

        if (templates_remove):
            params['service_profile_template_changes'] = {
                'remove': {
                    'service_profile_template': templates_remove
                }
            }

        body = json.dumps(params)
        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port, "PUT",
            self.URI_COMPUTE_VPOOL_ID.format(compute_uri), body)

        return common.json_decode(s)
Exemplo n.º 6
0
    def list_networks(self, varray):
        '''
        Makes REST API call to list networks in a varray
        Parameters:
            varray: name of varray
        Returns:
            List of network uuids in JSONo response payload
        '''
        varray_uri = None
        if (varray):
            varray_obj = VirtualArray(self.__ipAddr, self.__port)
            varray_uri = varray_obj.varray_query(varray)

        return self.list_by_uri(varray_uri)
Exemplo n.º 7
0
    def datastore_create(self, type, label, varray, cos, size, token,
                         mountpoint):

        if ((varray) and (not common.is_uri(varray))):
            from virtualarray import VirtualArray
            obj = VirtualArray(self.__ipAddr, self.__port)
            nbhinst = obj.varray_show(varray)
            varray = nbhinst['id']

        if (not common.is_uri(cos)):
            from cos import Cos
            obj = Cos(self.__ipAddr, self.__port)
            # check this
            cosinst = obj.cos_show(cos, 'object')
            cos_uri = cosinst['id']

        parms = {
            'name': label,
            'object_cos': cos_uri,
        }

        if (size):
            parms['size'] = size

        if (varray):
            parms['varray'] = varray

        if (mountpoint):
            parms['mount_point'] = mountpoint

        if (not token):
            token = 'cli-create-' + cos

        body = json.dumps(parms)

        uri = self.URI_DATA_STORE_LIST + "/" + type

        qparms = {'task': token}

        if (qparms):
            for qk in qparms.iterkeys():
                if (qparms[qk] is not None):
                    uri += '&' if ('?' in uri) else '?'
                    uri += qk + '=' + qparms[qk]

        (s, h) = common.service_json_request(self.__ipAddr, self.__port,
                                             "POST", uri, body)

        o = common.json_decode(s)
Exemplo n.º 8
0
    def bucket_create(self, name, project, owner , varray,vpool , retention, softquota , hardquota):
        
        
        
        from project import Project
        proj_obj = Project(self.__ipAddr, self.__port)
        project_uri = proj_obj.project_query(project)

        from virtualpool import VirtualPool
        vpool_obj = VirtualPool(self.__ipAddr, self.__port)
        vpool_uri = vpool_obj.vpool_query(vpool, "object")
        
        from virtualarray import VirtualArray
        varray_obj = VirtualArray(self.__ipAddr, self.__port)
        varray_uri = varray_obj.varray_query(varray)
        
        uri = Bucket.URI_BUCKET_CREATE + "?project=" + project_uri
        

        request = {
            'name': name,
            'varray': varray_uri,
            'vpool': vpool_uri
        }
        if(owner):
            request["owner"] = owner
        if(retention):
            request["retention"] = retention
        if(softquota):
            request["soft_quota"] = softquota
        if(hardquota):
            request["hard_quota"] = hardquota
        
        body = json.dumps(request)
        

        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port,
            "POST",
            uri,
            body)
        o = common.json_decode(s)
        return o
    def init_vipr_cli_components(self):
        import common as vipr_utils
        vipr_utils.COOKIE = None

        from exportgroup import ExportGroup
        from host import Host
        from hostinitiators import HostInitiator
        from snapshot import Snapshot
        from virtualarray import VirtualArray
        from volume import Volume

        # instantiate a few vipr cli objects for later use
        self.volume_obj = Volume(self.configuration.vipr_hostname,
                                 self.configuration.vipr_port)
        self.exportgroup_obj = ExportGroup(self.configuration.vipr_hostname,
                                           self.configuration.vipr_port)
        self.host_obj = Host(self.configuration.vipr_hostname,
                             self.configuration.vipr_port)
        self.hostinitiator_obj = HostInitiator(
            self.configuration.vipr_hostname, self.configuration.vipr_port)
        self.varray_obj = VirtualArray(self.configuration.vipr_hostname,
                                       self.configuration.vipr_port)
        self.snapshot_obj = Snapshot(self.configuration.vipr_hostname,
                                     self.configuration.vipr_port)
Exemplo n.º 10
0
 def getVarrayList(self, varrays):
     varray_obj = VirtualArray(self.__ipAddr, self.__port)
     return varray_obj.convertNamesToUris(varrays)
Exemplo n.º 11
0
def storagepool_list(args):
    obj = StoragePool(args.ip, args.port)
    try:
        from storagesystem import StorageSystem
        sys = StorageSystem(args.ip, args.port)
        if (args.serialnumber):
            device_id = sys.query_by_serial_number_and_type(
                args.serialnumber, args.type)
        else:
            device = sys.show(name=args.storagesystem, type=args.type)
            device_id = device['id']

        uris = obj.storagepool_list_by_uri(device_id)
        output = []
        for uri in uris:
            result = obj.storagepool_show_by_uri(device_id, uri)

            # adding new column storage tier names assicated with pools
            if ("tier_utilization_percentages" in result and args.long == True
                    and (result['registration_status'] == 'REGISTERED')):
                tierUtilizationPercentages = result[
                    'tier_utilization_percentages']
                # Go and fetch storage-tiers only if the utilization value is present
                # Assumption here is, if there some utilization value, then
                # such a pool has storage tiers
                if (tierUtilizationPercentages is not None
                        and len(tierUtilizationPercentages) > 0):
                    tiernamelst = []
                    returnlst = []
                    # get list of storage tier objects
                    returnlst = obj.storagepool_get_tiers_by_uri(uri)
                    for item in returnlst:
                        tiernamelst.append(item['name'])
                    result["storage_tiers"] = tiernamelst

            if (result):
                output.append(result)

        if (len(output) > 0):
            if (args.verbose == True):
                return common.format_json_object(output)

            for iter in output:
                from decimal import Decimal
                if (iter['free_gb'] / (1024 * 1024) >= 1):
                    iter['free'] = Decimal(
                        Decimal(iter['free_gb']) / (1024 * 1024))
                    iter['free'] = str(iter['free']) + ' PB'
                elif (iter['free_gb'] / (1024) >= 1):
                    iter['free'] = Decimal(Decimal(iter['free_gb']) / (1024))
                    iter['free'] = str(iter['free']) + ' TB'
                else:
                    iter['free'] = str(iter['free_gb']) + ' GB'

                if (iter['used_gb'] / (1024 * 1024) >= 1):
                    iter['used'] = Decimal(
                        Decimal(iter['used_gb']) / (1024 * 1024))
                    iter['used'] = str(iter['used']) + ' PB'
                elif (iter['used_gb'] / (1024) >= 1):
                    iter['used'] = Decimal(Decimal(iter['used_gb']) / (1024))
                    iter['used'] = str(iter['used']) + ' TB'
                else:
                    iter['used'] = str(iter['used_gb']) + ' GB'

            if (args.long == True):
                for iter in output:
                    if ('vpool_set' in iter):
                        vpoolnames = ''
                        for vpooliter in iter['vpool_set']:
                            from virtualpool import VirtualPool
                            obj = VirtualPool(args.ip, args.port)

                            if (args.type in ['isilon', 'vnxfile', 'netapp']):
                                vpooltype = 'file'
                            else:
                                vpooltype = 'block'

                            vpool = obj.vpool_show_uri(vpooltype,
                                                       vpooliter['id'])
                            if (vpool):
                                vpoolnames = vpoolnames + vpool['name'] + ','

                        if (len(vpoolnames) > 0):
                            vpoolnames = vpoolnames[0:len(vpoolnames) - 1]
                        if (vpoolnames):
                            iter['vpool_set'] = vpoolnames
                        else:
                            iter['vpool_set'] = 'NULL'

                    if ('tagged_varrays' in iter):
                        nbhnames = ''
                        for nbhiter in iter['tagged_varrays']:
                            from virtualarray import VirtualArray
                            obj = VirtualArray(args.ip, args.port)

                            nbh = obj.varray_show(nbhiter)
                            if (nbh):
                                nbhnames = nbhnames + nbh['name'] + ','

                        if (len(nbhnames) > 0):
                            nbhnames = nbhnames[0:len(nbhnames) - 1]

                        if (nbhnames):
                            iter['tagged_varrays'] = nbhnames
                        else:
                            iter['tagged_varrays'] = 'NULL'

                from common import TableGenerator
                TableGenerator(output, [
                    'pool_name', 'registration_status', 'free', 'used',
                    'vpool_set', 'tagged_varrays', 'storage_tiers'
                ]).printTable()
            else:
                from common import TableGenerator
                TableGenerator(
                    output,
                    ['pool_name', 'registration_status', 'free', 'used'
                     ]).printTable()

    except SOSError as e:
        if (e.err_code == SOSError.NOT_FOUND_ERR):
            raise SOSError(SOSError.NOT_FOUND_ERR,
                           "Storagepool list failed: " + e.err_text)
        else:
            raise e
Exemplo n.º 12
0
    def storagepool_update(self, storagesystem, serialnumber, devicetype,
                           poolname, nhadds, nhrems, volumetype, maxresources,
                           maxpoolutilization, maxthinpoolsubscription):

        nhassignments = dict()
        #parms['varray_assignment_changes'] = nhassignments
        if (nhadds):
            nhlst = []
            for iter in nhadds:
                from virtualarray import VirtualArray
                obj = VirtualArray(self.__ipAddr, self.__port)

                nbhuri = obj.varray_query(iter)
                if (nbhuri):
                    nhlst.append(nbhuri)

            if (nhlst):
                nh = dict()
                nh['varrays'] = nhlst
                nhassignments['add'] = nh
        if (nhrems):
            nhlst = []
            for iter in nhrems:
                from virtualarray import VirtualArray
                obj = VirtualArray(self.__ipAddr, self.__port)

                nbhuri = obj.varray_query(iter)
                if (nbhuri):
                    nhlst.append(nbhuri)

            if (nhlst):
                nh = dict()
                nh['varrays'] = nhlst
                nhassignments['remove'] = nh

        if (storagesystem):
            device_id = self.storagesystem_query(storagesystem, devicetype,
                                                 None)
        else:
            device_id = self.storagesystem_query(None, devicetype,
                                                 serialnumber)

        storagepool_ids = self.storagepool_list_by_uri(device_id)
        not_found = 1
        for uri in storagepool_ids:
            storpool = self.storagepool_show_by_uri(device_id, uri)
            if (storpool['pool_name']) == poolname:
                not_found = 0
            if (poolname):
                if (storpool['pool_name'] == poolname):
                    if ((volumetype) and
                        (storpool['supported_resource_types'] == volumetype)):
                        self.storagepool_update_by_uri(
                            storpool['id'], nhassignments, maxresources,
                            maxpoolutilization, maxthinpoolsubscription)
                    if (not volumetype):
                        self.storagepool_update_by_uri(
                            storpool['id'], nhassignments, maxresources,
                            maxpoolutilization, maxthinpoolsubscription)

            else:
                if (not volumetype):
                    self.storagepool_update_by_uri(storpool['id'],
                                                   nhassignments, maxresources,
                                                   maxpoolutilization,
                                                   maxthinpoolsubscription)
                if ((volumetype) and
                    (storpool['supported_resource_types'] == volumetype)):
                    self.storagepool_update_by_uri(storpool['id'],
                                                   nhassignments, maxresources,
                                                   maxpoolutilization,
                                                   maxthinpoolsubscription)
        if (poolname is not None):
            if (not_found == 1):
                raise SOSError(
                    SOSError.NOT_FOUND_ERR,
                    "Storagepool with name " + str(poolname) + " not found\n")
Exemplo n.º 13
0
    def ps_update(self, name, deviceip, deviceport, username, type, clusterid,
                  varraysToAdd, varraysToRemove):
        '''
        This is the function will
        create the RecoverPoint with given name and type.
        It will send REST API request to ViPR instance.
        parameters:
            name : Name of the protection system.
            type : Type of the protection system { 'rp' }
            username : Username to access protection system (usually "admin")
            deviceip : IP address of management access of protection system
            deviceport : Port to access protection system
            clusterid : ID of cluster (RecoverPoint specific)
            varraysToAdd : Assign virtual arrays to cluster
            varraysToRemove : Unassign virtual arrays to cluster
            Note:  If clusterid is used, CLI supports changing only one cluster
                   virtual array assignments per command.
        return
            returns with protection system object with all details.
        '''
        # check for existance of Protection system.
        passwd = None
        if (username and len(username) > 0):
            if sys.stdin.isatty():
                passwd = getpass.getpass(
                    prompt="Enter password of the protection system: ")
            else:
                passwd = sys.stdin.readline().rstrip()

            if (len(passwd) > 0):
                if sys.stdin.isatty():
                    confirm_passwd = getpass.getpass(
                        prompt="Retype password: "******" " + sys.argv[1] + " " + sys.argv[2] +
                        ": error: Passwords mismatch")
            else:
                raise SOSError(
                    SOSError.CMD_LINE_ERR, sys.argv[0] + " " + sys.argv[1] +
                    " " + sys.argv[2] + ": error: Invalid password")

        parms = dict()
        if (deviceip):
            parms['ip_address'] = deviceip
        if (deviceport):
            parms['port_number'] = deviceport
        if (username):
            parms['user_name'] = username
        if (passwd):
            parms['password'] = passwd
        if (clusterid):
            # varray changes
            varray_obj = VirtualArray(self.__ipAddr, self.__port)
            addvarrayList = varray_obj.convertNamesToUris(varraysToAdd)
            removevarrayList = varray_obj.convertNamesToUris(varraysToRemove)

            parms = {
                'varray_assignment_changes': [{
                    'add': {
                        'varrays': addvarrayList
                    },
                    'remove': {
                        'varrays': removevarrayList
                    },
                    'cluster_id': clusterid
                }]
            }

        uri = self.ps_query(name)

        body = json.dumps(parms)
        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port, "PUT",
            self.URI_PROTECTION_SYSTEM_UPDATE.format(uri), body)
        o = common.json_decode(s)
        return o
Exemplo n.º 14
0
    def filepolicy_assign(
        self,
        name,
        assign_to_vpools,
        project_assign_vpool,
        assign_to_projects,
        source_varray,
        target_varrays,
        ):

        filepolicy = self.filepolicy_query(name)
        (s, h) = common.service_json_request(
                self.__ipAddr,
                self.__port,
                'GET',
                FilePolicy.URI_FILE_POLICY_SHOW.format(filepolicy['id']),
                None,
                None,
                False,
                )
	o = common.json_decode(s)
	appliedat = common.get_node_value(o,"applied_at")
	pol_type = common.get_node_value(o,"type")
	assign_request = {}

	if ( appliedat  == "vpool"):
		vpool_assign_param = {}
		assign_request_vpools = []
		if assign_to_vpools is None:
           		raise SOSError(SOSError.VALUE_ERR,"File policyassign error:"+ "Vpool(assign_to_vpools) value should be provided")
		elif( len(assign_to_vpools)>1):
            		vpool_names = assign_to_vpools.split(',')
            		vpool_obj = VirtualPool(self.__ipAddr, self.__port)
			for name in vpool_names:
                 		uri = vpool_obj.vpool_query(name, 'file')
                 		assign_request_vpools.append(uri)
        	elif( assign_to_vpools is not None ):
            		uri = vpool_obj.vpool_query(assign_to_vpools, 'file')
            		assign_request_vpools.append(uri)
        	vpool_assign_param['assign_to_vpools'] = assign_request_vpools
		assign_request['vpool_assign_param'] = vpool_assign_param
	elif ( appliedat == "project"):
		project_assign_param = {}
		assign_request_projects = []
		assign_request_project_vpools = []
		project_obj = Project(self.__ipAddr, self.__port)
		if assign_to_projects is None or project_assign_vpool is None:
                        raise SOSError(SOSError.VALUE_ERR,"File policyassign error:"+ "Vpool (project_assign_vpool) and project (assign_to_projects) value should be provided")
                
		if( len(assign_to_projects)>1):
            		project_names = assign_to_projects.split(',')
            		for name in project_names:
                 		uri = project_obj.project_query(name) 
		 		assign_request_projects.append(uri)
        	else:
            		uri = project_obj.project_query(assign_to_projects)
            		assign_request_projects.append(uri)
	
		vpool_obj = VirtualPool(self.__ipAddr, self.__port)
            	uri = vpool_obj.vpool_query(project_assign_vpool, 'file')
            	project_assign_param['vpool'] = uri
        	project_assign_param['assign_to_projects'] = assign_request_projects
		assign_request['project_assign_param'] = project_assign_param

	if (pol_type == "file_replication"):
		if (source_varray is not None and target_varrays is not None):
			file_replication_topologies = []
	        	file_replication_topology = {}
			assign_target_varrays = []
			from virtualarray import VirtualArray
                	varray_obj = VirtualArray(self.__ipAddr, self.__port)
	                src_varray_uri = varray_obj.varray_query(source_varray)
		        file_replication_topology['source_varray']= src_varray_uri
	
		        if( len(target_varrays)>1):
				trg_varrays= target_varrays.split(',')
				for varray in trg_varrays:
					uri =  varray_obj.varray_query(varray)
					assign_target_varrays.append(uri)
			else:
				uri = varray_obj.varray_query(target_varrays)
				assign_target_varrays.append(uri)
		
			file_replication_topology['target_varrays']= assign_target_varrays
			file_replication_topologies.append(file_replication_topology)
			assign_request['file_replication_topologies']= file_replication_topologies
		else:
			raise SOSError(SOSError.VALUE_ERR, "File policyassign error:"+ "Target and source virtual array should be provided")

		

        try:
            body = json.dumps(assign_request)
            (s, h) = common.service_json_request(self.__ipAddr,
                    self.__port, 'POST',
                    FilePolicy.URI_FILE_POLICY_ASSIGN.format(filepolicy['id']),
                    body)
            if not s:
                return None
            o = common.json_decode(s)
            return o
        except SOSError, e:
            errorMessage = str(e)