def objectuser_secretkey_create(self, storagesystem, objectuser, secretkey):
        """
        Makes a REST API call to retrieve create secret key of an object user
        
        """
        stsystem_uri = None
        from storagesystem import StorageSystem

        obj = StorageSystem(self.__ipAddr, self.__port)

        stsystem_uri = obj.query_by_name_and_type(storagesystem, "ecs")
        request = {}
        if secretkey:
            request = {"secret_key": secretkey}

        body = json.dumps(request)

        (s, h) = common.service_json_request(
            self.__ipAddr,
            self.__port,
            "POST",
            ObjectUser.URI_OBJECTUSER_SECRET_KEYS.format(stsystem_uri, objectuser),
            body,
        )
        o = common.json_decode(s)
        return o
def consistencygroup_list(args):
    obj = ConsistencyGroup(args.ip, args.port)
    try:
        uris = obj.list(args.project, args.tenant)
        output = []
        for uri in uris:
            cg = obj.show(uri, args.project, args.tenant)
            if(cg):
                from volume import Volume
                from storagesystem import StorageSystem
                if( "volumes" in cg): 
                    volumeuris = common.get_node_value(cg, "volumes")
                    volobj = Volume(args.ip, args.port)
                    volumenames = []
                    for volume in volumeuris:
                        vol = volobj.show_by_uri(volume['id'])
                        if(vol):
                            volumenames.append(vol['name'])
                    cg['volumes'] = volumenames
                ssobj = StorageSystem(args.ip, args.port)
                if( "storage_controller" in cg):
                    ssrow =  common.get_node_value(cg, "storage_controller")
                    storagesystem = ssobj.show_by_uri(ssrow['id'])
                    cg['storage_controller'] = storagesystem['name']
                output.append(cg)
        if(len(output)):
            TableGenerator(output, ['name', 'volumes', 'storage_controller']).printTable() 
    except SOSError as e:
        raise SOSError(SOSError.SOS_FAILURE_ERR, "Consistency Group  List failed:\n" + e.err_text)
Esempio n. 3
0
    def storageportgroup_add(self, storage_device_name, serial_number,
                        storage_device_type, portgroup_name, storageports):

        storage_system = StorageSystem(self.__ipAddr, self.__port)
        storage_system_uri = None

        if(serial_number):
            storage_system_uri \
                = storage_system.query_by_serial_number_and_type(
                    serial_number, storage_device_type)
        elif(storage_device_name):
            storage_system_uri = storage_system.query_by_name_and_type(
                storage_device_name,
                storage_device_type)

        addports = []
        for portname in storageports:
            storage_port = Storageport(self.__ipAddr, self.__port)
            porturi = storage_port.storageport_query(storage_system_uri, portname)
            addports.append(porturi)
            
        body = json.dumps(
                          {'name': portgroup_name,
                           'storage_ports': addports
                           })

        common.service_json_request(self.__ipAddr, self.__port,
             "POST",
             Storageportgroup.URI_STORAGEPORTGROUP_LIST.format(storage_system_uri),
             body)
Esempio n. 4
0
    def storageportgroup_add(self, storage_device_name, serial_number,
                             storage_device_type, portgroup_name,
                             storageports):

        storage_system = StorageSystem(self.__ipAddr, self.__port)
        storage_system_uri = None

        if (serial_number):
            storage_system_uri \
                = storage_system.query_by_serial_number_and_type(
                    serial_number, storage_device_type)
        elif (storage_device_name):
            storage_system_uri = storage_system.query_by_name_and_type(
                storage_device_name, storage_device_type)

        addports = []
        for portname in storageports:
            storage_port = Storageport(self.__ipAddr, self.__port)
            porturi = storage_port.storageport_query(storage_system_uri,
                                                     portname)
            addports.append(porturi)

        body = json.dumps({'name': portgroup_name, 'storage_ports': addports})

        common.service_json_request(
            self.__ipAddr, self.__port, "POST",
            Storageportgroup.URI_STORAGEPORTGROUP_LIST.format(
                storage_system_uri), body)
    def storageport_add(
        self, storage_device_name, serial_number, storage_device_type, port_name, port_id, transport_type
    ):

        storage_system = StorageSystem(self.__ipAddr, self.__port)
        storage_system_uri = None

        if serial_number:
            storage_system_uri = storage_system.query_by_serial_number_and_type(serial_number, storage_device_type)
        elif storage_device_name:
            storage_system_uri = storage_system.query_by_name_and_type(storage_device_name, storage_device_type)

        is_storageport_exist = True
        try:
            self.storageport_query(storage_system_uri, port_name)
        except SOSError as e:
            if e.err_code == SOSError.NOT_FOUND_ERR:
                is_storageport_exist = False
            else:
                raise e

        if is_storageport_exist:
            raise SOSError(SOSError.ENTRY_ALREADY_EXISTS_ERR, "storageport with name " + port_name + " already exists ")

        body = json.dumps({"name": port_name, "port_network_id": port_id, "transport_type": transport_type})

        common.service_json_request(
            self.__ipAddr, self.__port, "POST", Storageport.URI_STORAGEPORT_LIST.format(storage_system_uri), body
        )
    def storagepool_register_main(self, serialnumber,
                           deviceType, poolName):

        '''
        Registers a storagepool with specified parameters
        Parameters:
            serialnumber:   serial number of the storage system
            protocol:        (optional) protocols supported by pool
            maxSnapshots:    (optional) maxSnapshots permitted on the storage pool
            consistency:    (optional) consistency details of storage pool
            deviceType:    storage system type
            poolName:    (optional) specific pool name to be registered
        returns:
            JSON payload of the created storagepool
        '''

        from storagesystem import StorageSystem
        obj_ss = StorageSystem(self.__ipAddr, self.__port)

        #uri = obj_ss.query_storagesystem_by_serial_number(serialnumber)        
        systemuri = obj_ss.query_by_serial_number_and_type(serialnumber, deviceType)        

	pooluris = self.storagepool_list_by_uri(systemuri)

	if(poolName):
            # Need to check if pool is found
            found = False
        else:
            found = True
	for pooluri in pooluris:
	    if(poolName):
		storpool = self.storagepool_show_by_uri(systemuri, pooluri)

		compval = None

		compval = storpool['pool_name']
		'''contrlparms = storpool['controller_params']
		for item in contrlparms:
		    if(item['name'] == 'NativeId'):
		        compval = item['value']'''
			    

	        if(poolName == compval):

                    found = True
                    res = self.storagepool_register(systemuri, pooluri) 
	    else:
                res = self.storagepool_register(systemuri, pooluri) 

        # Print error if named pool is not found
        if (not (found)):
            raise SOSError(SOSError.NOT_FOUND_ERR,
                    "Storagepool with name " +poolName+" not found\n")
    def storagesystem_query(self, storagedeviceName, serialNumber, storagedeviceType):
        urideviceid = None
        storagesystemObj = StorageSystem(self.__ipAddr, self.__port)
        if serialNumber:
            urideviceid = storagesystemObj.query_by_serial_number_and_type(serialNumber, storagedeviceType)

        elif storagedeviceName:
            urideviceidTemp = storagesystemObj.show(name=storagedeviceName, type=storagedeviceType)
            urideviceid = urideviceidTemp["id"]
        else:
            return

        return urideviceid
class TestStorageSystem(TestCase):

    def setUp(self):
        self.storage = StorageSystem("unitTest.exe")
        try:
            self.storage.add_file(open("write.txt",'rb'))
        except FileAllreadyExistsException:
            pass

        if self.storage.buffer.getCount() == 0:
            raise Exception('There was a problem')

    def test_getStats(self):
        self.storage.stat()
    def aliasget(self, initiator_uri, device_name, device_type):
        '''
        Makes a REST API call to get the initiator alias against a storage system
        '''
        from storagesystem import StorageSystem
        obj = StorageSystem(self.__ipAddr, self.__port)
        device_detail = obj.show(name=device_name, type=device_type)
        system_uri = device_detail['id']

        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port, "GET",
            HostInitiator.URI_INITIATOR_ALIASGET.format(initiator_uri, system_uri),
            None)
        o = common.json_decode(s)
        return o
    def aliasget(self, initiator_uri, device_name, device_type):
        '''
        Makes a REST API call to get the initiator alias against a storage system
        '''
        from storagesystem import StorageSystem
        obj = StorageSystem(self.__ipAddr, self.__port)
        device_detail = obj.show(name=device_name, type=device_type)
        system_uri = device_detail['id']

        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port, "GET",
            HostInitiator.URI_INITIATOR_ALIASGET.format(
                initiator_uri, system_uri), None)
        o = common.json_decode(s)
        return o
Esempio n. 11
0
def vnasserver_list(args):
    obj = VnasServer(args.ip, args.port)
    from common import TableGenerator
    from project import Project
    try:
        vnasServerList = obj.list_vnasserver_names()
        resultList = []
        for iter in vnasServerList:
            rslt = obj.vnasserver_show(iter['name'])
            
            #rslt['parent_nas']['name'] should be printed under PARENT_NAS_SERVER.
            #Updating it as a new element in the map
            if('parent_nas' in rslt) and ('name' in rslt['parent_nas']):
                rslt['parent_nas_server'] = rslt['parent_nas']['name']
                
            pr_object = None
            project_list = ''
            if ('associated_projects' in rslt):
                for project_id in rslt['associated_projects']:
                    pr_object = Project(args.ip, args.port).project_show_by_uri(project_id)
                    if pr_object and ('name' in pr_object):
                        if (project_list == ''):
                            project_list = pr_object['name']
                        else :
                            project_list = project_list + ',' + pr_object['name']
                

            st_object = None
            if ('storage_device' in rslt) and ('id' in rslt['storage_device']):
                st_object = StorageSystem(args.ip, args.port).show_by_uri(rslt['storage_device']['id']) 
                
            if pr_object and ('name' in pr_object):
                rslt['project_name'] = project_list
                
            if st_object and ('name' in st_object):
                rslt['storage_system'] = st_object['name']
            if(rslt is not None):
                resultList.append(rslt)
         
        
        if(len(resultList) > 0):
            # show a short table
            if(args.verbose is False and args.long is False):
                TableGenerator(vnasServerList,
                               ["name"]).printTable()
            
            # show a long table
            if(args.verbose is False and args.long is True):
                TableGenerator(
                    resultList,
                    ["nas_name","parent_nas_server","nas_state","storage_domains","project_name","protocols", "storage_system"]).printTable()
                    
            # show all items in json format
            if(args.verbose):
                return common.format_json_object(resultList)

        else:
            return
    except SOSError as e:
        raise e
Esempio n. 12
0
    def storagesystem_query(self, storagedeviceName, serialNumber,
                            storagedeviceType):
        urideviceid = None
        storagesystemObj = StorageSystem(self.__ipAddr, self.__port)
        if (serialNumber):
            urideviceid = storagesystemObj.query_by_serial_number_and_type(
                serialNumber, storagedeviceType)

        elif (storagedeviceName):
            urideviceidTemp = storagesystemObj.show(name=storagedeviceName,
                                                    type=storagedeviceType)
            urideviceid = urideviceidTemp['id']
        else:
            return

        return urideviceid
Esempio n. 13
0
    def storagepool_register_main(self, serialnumber, deviceType, poolName):
        '''
        Registers a storagepool with specified parameters
        Parameters:
            serialnumber:   serial number of the storage system
            protocol:        (optional) protocols supported by pool
            maxSnapshots:
            (optional) maxSnapshots permitted on the storage pool
            consistency:    (optional) consistency details of storage pool
            deviceType:    storage system type
            poolName:    (optional) specific pool name to be registered
        returns:
            JSON payload of the created storagepool
    '''
        obj_ss = StorageSystem(self.__ipAddr, self.__port)

        #uri = obj_ss.query_storagesystem_by_serial_number(serialnumber)
        systemuri = obj_ss.query_by_serial_number_and_type(
            serialnumber, deviceType)

        pooluris = self.storagepool_list_by_uri(systemuri)

        if (poolName):
            # Need to check if pool is found
            found = False
        else:
            found = True
        for pooluri in pooluris:
            if (poolName):
                storpool = self.storagepool_show_by_uri(systemuri, pooluri)

                compval = None

                compval = storpool['pool_name']

                if (poolName == compval):

                    found = True
                    self.storagepool_register(systemuri, pooluri)
                else:
                    self.storagepool_register(systemuri, pooluri)

        # Print error if named pool is not found
        if (not (found)):
            raise SOSError(
                SOSError.NOT_FOUND_ERR,
                "Storagepool with name " + poolName + " not found\n")
    def storageport_add(self, storagedeviceName, serialNumber, storagedeviceType, label, portname, portid, transportType, portspeed, portgroup, networkId):
       
        storagesystemObj = StorageSystem(self.__ipAddr, self.__port) 
        urideviceid = None
        
        if(serialNumber):
            urideviceid = storagesystemObj.query_storagesystem_by_serial_number(serialNumber)

        elif(storagedeviceName):
            urideviceidTemp = storagesystemObj.show(name=storagedeviceName, type=storagedeviceType)
            urideviceid = urideviceidTemp['id']
        else:
            raise SOSError(SOSError.CMD_LINE_ERR,
                           "error: For device type " + storagedeviceType + "  -storagesystem name or serialnumber are required")

           
        #check snapshot is already exist
        is_storageport_exist = True
        try:
            self.storageport_query(storagedeviceName, serialNumber, storagedeviceType, portname)
        except SOSError as e:
            if(e.err_code == SOSError.NOT_FOUND_ERR):
                is_storageport_exist = False
            else:
                raise e

        if(is_storageport_exist):
            raise SOSError(SOSError.ENTRY_ALREADY_EXISTS_ERR,
                           "storageport with name " + portname + 
                           " already exists under device under type" + storagedeviceType)
        
        body = json.dumps({
                        'label' : label,
                        'portName' : portname,
                        'portId' : portid,
                        'transportType' : transportType,
                        'portSpeed' : portspeed,
                        'portGroup' : portgroup,
                        'network':networkId
                    }) 

        
        (s, h) = common.service_json_request(self.__ipAddr, self.__port,
                                              "POST", Storageport.URI_STORAGEPORT_LIST.format(urideviceid), body)
        return common.json_decode(s)
    def aliasset(self, initiator_uri, device_name, device_type, alias):
        '''
        Makes a REST API call to get the initiator alias against a storage system
        '''

        from storagesystem import StorageSystem
        obj = StorageSystem(self.__ipAddr, self.__port)
        device_detail = obj.show(name=device_name, type=device_type)
        system_uri = device_detail['id']

        request = {'system_uri': system_uri, 'initiator_alias': alias}
        body = json.dumps(request)

        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port, "PUT",
            HostInitiator.URI_INITIATOR_ALIASSET.format(initiator_uri), body)
        o = common.json_decode(s)
        return o
    def aliasset(self, initiator_uri, device_name, device_type, alias):
        '''
        Makes a REST API call to get the initiator alias against a storage system
        '''

        from storagesystem import StorageSystem
        obj = StorageSystem(self.__ipAddr, self.__port)
        device_detail = obj.show(name=device_name, type=device_type)
        system_uri = device_detail['id']

        request = {'system_uri': system_uri,
                   'initiator_alias': alias
                   }
        body = json.dumps(request)

        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port, "PUT",
            HostInitiator.URI_INITIATOR_ALIASSET.format(initiator_uri),
            body)
        o = common.json_decode(s)
        return o
    def list_storageports(self, varrayName, network_connectivity=False):

        from storagesystem import StorageSystem
        storageSystemObj = StorageSystem(self.__ipAddr, self.__port)

        varrayUri = self.varray_query(varrayName)

        if(network_connectivity is True):
            (s, h) = common.service_json_request(
                self.__ipAddr, self.__port, "GET",
                VirtualArray.URI_LIST_STORAGE_PORTS.format(
                    varrayUri) + "?network_connectivity=true", None)
        else:
            (s, h) = common.service_json_request(
                self.__ipAddr, self.__port,
                "GET",
                VirtualArray.URI_LIST_STORAGE_PORTS.format(varrayUri), None)

        o = common.json_decode(s)
        portList = []
        for item in o['storage_port']:
            portList.append(item['id'])

        portDetailsList = []
        if(portList):
            for porturi in portList:
                (s, h) = common.service_json_request(
                    self.__ipAddr, self.__port, "GET",
                    self.URI_STORAGE_PORT_DETAILS.format(porturi), None)
                portDetails = common.json_decode(s)

                # Get the storage system name to which the port belongs to
                storageSystemUri = portDetails['storage_system']['id']
                ssDetails = storageSystemObj.show_by_uri(storageSystemUri,
                                                         False)
                portDetails['storage_system'] = ssDetails['name']

                portDetailsList.append(portDetails)

        return portDetailsList
Esempio n. 18
0
    def list_storageports(self, varrayName, network_connectivity=False):

        from storagesystem import StorageSystem
        storageSystemObj = StorageSystem(self.__ipAddr, self.__port)

        varrayUri = self.varray_query(varrayName)

        if (network_connectivity is True):
            (s, h) = common.service_json_request(
                self.__ipAddr, self.__port, "GET",
                VirtualArray.URI_LIST_STORAGE_PORTS.format(varrayUri) +
                "?network_connectivity=true", None)
        else:
            (s, h) = common.service_json_request(
                self.__ipAddr, self.__port, "GET",
                VirtualArray.URI_LIST_STORAGE_PORTS.format(varrayUri), None)

        o = common.json_decode(s)
        portList = []
        for item in o['storage_port']:
            portList.append(item['id'])

        portDetailsList = []
        if (portList):
            for porturi in portList:
                (s, h) = common.service_json_request(
                    self.__ipAddr, self.__port, "GET",
                    self.URI_STORAGE_PORT_DETAILS.format(porturi), None)
                portDetails = common.json_decode(s)

                # Get the storage system name to which the port belongs to
                storageSystemUri = portDetails['storage_system']['id']
                ssDetails = storageSystemObj.show_by_uri(
                    storageSystemUri, False)
                portDetails['storage_system'] = ssDetails['name']

                portDetailsList.append(portDetails)

        return portDetailsList
    def storagesystem_query(self, devicename, devicetype, serialnumber=None):
        '''
        Returns the URI of the storage system given either name or serialnumber
        Parameters:
            devicename:name of the system
            devicetype: type of system
            serialnumber: serial number
        Returns:
            System URI
        '''

        from storagesystem import StorageSystem
        if (not common.is_uri(devicename)):
            obj = StorageSystem(self.__ipAddr, self.__port)
	    if(not serialnumber or len(serialnumber)> 0):
		device_id = obj.query_by_serial_number_and_type(serialnumber, devicetype)
	    else:
                device = obj.show(name=devicename, type=devicetype)        
                device_id = device['id']
        else:
            device_id = devicename
        return device_id
Esempio n. 20
0
    def storageport_add(self, storage_device_name, serial_number,
                        storage_device_type, port_name, port_id,
                        transport_type):

        storage_system = StorageSystem(self.__ipAddr, self.__port)
        storage_system_uri = None

        if (serial_number):
            storage_system_uri \
                = storage_system.query_by_serial_number_and_type(
                    serial_number, storage_device_type)
        elif (storage_device_name):
            storage_system_uri = storage_system.query_by_name_and_type(
                storage_device_name, storage_device_type)

        is_storageport_exist = True
        try:
            self.storageport_query(storage_system_uri, port_name)
        except SOSError as e:
            if (e.err_code == SOSError.NOT_FOUND_ERR):
                is_storageport_exist = False
            else:
                raise e

        if (is_storageport_exist):
            raise SOSError(
                SOSError.ENTRY_ALREADY_EXISTS_ERR,
                "storageport with name " + port_name + " already exists ")

        body = json.dumps({
            'name': port_name,
            'port_network_id': port_id,
            'transport_type': transport_type
        })

        common.service_json_request(
            self.__ipAddr, self.__port, "POST",
            Storageport.URI_STORAGEPORT_LIST.format(storage_system_uri), body)
Esempio n. 21
0
    def objectuser_secretkey_create(self, storagesystem, objectuser,
                                    secretkey):
        '''
        Makes a REST API call to retrieve create secret key of an object user
        
        '''
        stsystem_uri = None
        from storagesystem import StorageSystem
        obj = StorageSystem(self.__ipAddr, self.__port)

        stsystem_uri = obj.query_by_name_and_type(storagesystem, "ecs")
        request = {}
        if (secretkey):
            request = {'secret_key': secretkey}

        body = json.dumps(request)

        (s, h) = common.service_json_request(
            self.__ipAddr, self.__port, "POST",
            ObjectUser.URI_OBJECTUSER_SECRET_KEYS.format(
                stsystem_uri, objectuser), body)
        o = common.json_decode(s)
        return o
Esempio n. 22
0
    def storagesystem_query(self, devicename, devicetype, serialnumber=None):
        '''
        Returns the URI of the storage system given either name or serialnumber
        Parameters:
            devicename:name of the system
            devicetype: type of system
            serialnumber: serial number
        Returns:
            System URI
        '''

        from storagesystem import StorageSystem
        if (not common.is_uri(devicename)):
            obj = StorageSystem(self.__ipAddr, self.__port)
            if (serialnumber and len(serialnumber) > 0):
                device_id = obj.query_by_serial_number_and_type(
                    serialnumber, devicetype)
            else:
                device = obj.show(name=devicename, type=devicetype)
                device_id = device['id']
        else:
            device_id = devicename
        return device_id
Esempio n. 23
0
    def storagepool_create(self, storagename, poolname, protocol, maxSnapshots,
                           consistency, freeCapacity, totalCapacity,
                           extensions, deviceType):
        '''
        Creates a storagepool with specified parameters
        Parameters:
            storagename:           name of the storage system
            poolname:               name of the storage pool
            protocol:        protocols supported by pool
            nativeId:        native ID fothe pool
            extentions:        extended parameters and attributes
            resiliency:        resiliency assosiated with pool
            performance:    performance associated with the storage pool
            efficiency:        efficiency associated with the storage pool
            allocation        allocation of storage pool
            maxSnapshots:    maxSnapshots permitted on the storage pool
            consistency:    consistency details of storage pool
            resiliencymap:    resiliencymap of the storage pool
            freeCapacity:    freeCapacity of the storage pool
            totalCapacity:    totalCapacity of  the storage pool
        returns:
            JSON payload of the created storagepool
        '''

        uri = None
        sstype = None

        if (not common.is_uri(storagename)):
            from storagesystem import StorageSystem
            obj = StorageSystem(self.__ipAddr, self.__port)
            device = obj.show(name=storagename, type=deviceType)
            uri = device['id']

        sstype = deviceType

        checklist = []
        for iter in extensions:
            (key, value) = iter.split('=', 1)
            checklist.append(key)

        if ((sstype == 'vnxblock') or (sstype == 'vnxfile')
                or (sstype == 'vmax')):
            if ('NativeId' not in checklist) or ('PoolType' not in checklist):
                raise SOSError(
                    SOSError.CMD_LINE_ERR, "error: For device type " + sstype +
                    " -nativeid, -pooltype are required")

        if (sstype == 'vnxfile'):
            if ('Name' not in checklist):
                raise SOSError(
                    SOSError.CMD_LINE_ERR, "error: For device type " + sstype +
                    " -controllerpoolname is required")
        '''check for storage pool with existing name'''
        storage_pool_exists = True

        try:
            self.storagepool_show(poolname, storagename, None, deviceType)

        except SOSError as e:
            if (e.err_code == SOSError.NOT_FOUND_ERR):
                storage_pool_exists = False
            else:
                raise e

        if (storage_pool_exists):
            raise SOSError(
                SOSError.ENTRY_ALREADY_EXISTS_ERR,
                "Storage pool with name: " + poolname + " already exists")

        parms = dict()

        if (poolname):
            parms['name'] = poolname

        if (protocol):
            parms['protocols'] = protocol

        if (maxSnapshots):
            parms['max_snapshots'] = maxSnapshots

        if (consistency):
            parms['multi_volume_consistency'] = consistency

        if (extensions):
            parms['controller_params'] = self.__encode_map(extensions)

        if (freeCapacity):
            parms['free_capacity'] = freeCapacity

        if (totalCapacity):
            parms['total_capacity'] = totalCapacity

        body = None

        if (parms):
            body = json.dumps(parms)

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

        o = common.json_decode(s)

        return o
Esempio n. 24
0
    def storagepool_create(self, storagename, poolname,
                           protocol, maxSnapshots, consistency,
                           freeCapacity, totalCapacity,
                           extensions,
                           deviceType):
        '''
        Creates a storagepool with specified parameters
        Parameters:
            storagename:           name of the storage system
            poolname:               name of the storage pool
            protocol:        protocols supported by pool
            nativeId:        native ID fothe pool
            extentions:        extended parameters and attributes
            resiliency:        resiliency assosiated with pool
            performance:    performance associated with the storage pool
            efficiency:        efficiency associated with the storage pool
            allocation        allocation of storage pool
            maxSnapshots:    maxSnapshots permitted on the storage pool
            consistency:    consistency details of storage pool
            resiliencymap:    resiliencymap of the storage pool
            freeCapacity:    freeCapacity of the storage pool
            totalCapacity:    totalCapacity of  the storage pool
        returns:
            JSON payload of the created storagepool
        '''

        uri = None
        sstype = None

        if (not common.is_uri(storagename)):
            from storagesystem import StorageSystem
            obj = StorageSystem(self.__ipAddr, self.__port)
            device = obj.show(name=storagename, type=deviceType)
            uri = device['id']

        sstype = deviceType

        checklist = []
        for iter in extensions:
            (key, value) = iter.split('=', 1)
            checklist.append(key)

        if((sstype == 'vnxblock') or
           (sstype == 'vnxfile') or
           (sstype == 'vmax')):
            if('NativeId' not in checklist)or ('PoolType' not in checklist):
                raise SOSError(SOSError.CMD_LINE_ERR,
                               "error: For device type " + sstype +
                               " -nativeid, -pooltype are required")

        if(sstype == 'vnxfile'):
            if('Name' not in checklist):
                raise SOSError(SOSError.CMD_LINE_ERR,
                               "error: For device type " + sstype +
                               " -controllerpoolname is required")

        '''check for storage pool with existing name'''
        storage_pool_exists = True

        try:
            self.storagepool_show(poolname, storagename, None, deviceType)

        except SOSError as e:
            if(e.err_code == SOSError.NOT_FOUND_ERR):
                storage_pool_exists = False
            else:
                raise e

        if(storage_pool_exists):
            raise SOSError(SOSError.ENTRY_ALREADY_EXISTS_ERR,
                           "Storage pool with name: " +
                           poolname + " already exists")

        parms = dict()

        if (poolname):
            parms['name'] = poolname

        if (protocol):
            parms['protocols'] = protocol

        if (maxSnapshots):
            parms['max_snapshots'] = maxSnapshots

        if (consistency):
            parms['multi_volume_consistency'] = consistency

        if (extensions):
            parms['controller_params'] = self.__encode_map(extensions)

        if (freeCapacity):
            parms['free_capacity'] = freeCapacity

        if (totalCapacity):
            parms['total_capacity'] = totalCapacity

        body = None

        if (parms):
            body = json.dumps(parms)

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

        o = common.json_decode(s)

        return o
Esempio n. 25
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
Esempio n. 26
0
from storagesystem import StorageSystem


m = StorageSystem()

print type(m.file)

file = 'write.txt'

m.add_file(open(file,'rb'))

m.get_file("write.txt")