def protection_copyparam( self, copyvarray, pit, accessmode, type="native", sync='false'): copies_param = dict() copy = dict() copy_entries = [] copy['type'] = type if(pit != ""): copy['pointInTime'] = pit if(accessmode != ""): copy['accessMode'] = accessmode #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)
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)
def assign(self, name, varray): """ 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.network_query(name, None) nuri = None nlst = [] if varray: from virtualarray import VirtualArray varray_obj = VirtualArray(self.__ipAddr, self.__port) for iter in varray: nuri = varray_obj.varray_query(iter) nlst.append(nuri) if len(nlst) > 0: parms = {"varrays": nlst} else: parms = {"varrays": []} body = json.dumps(parms) (s, h) = common.service_json_request(self.__ipAddr, self.__port, "PUT", Network.URI_NETWORK.format(turi), body)
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)
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)
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)
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)
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)
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)
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) for uri in storagepool_ids: storpool = self.storagepool_show_by_uri(device_id,uri) if(poolname): if(storpool['pool_name'] == poolname): if ( (volumetype) and (storpool['supported_volume_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_volume_types'] == volumetype) ): self.storagepool_update_by_uri(storpool['id'], nhassignments, maxresources, maxpoolutilization, maxthinpoolsubscription)
def exportgroup_create(self, name, project, tenant, varray, exportgrouptype, export_destination=None): """ This function will take export group name and project name as input and it will create the Export group with given name. parameters: name : Name of the export group. project: Name of the project path. tenant: Container tenant name. return returns with status of creation. """ # check for existance of export group. try: status = self.exportgroup_show(name, project, tenant) except SOSError as e: if e.err_code == SOSError.NOT_FOUND_ERR: if tenant is None: tenant = "" fullproj = tenant + "/" + project projObject = Project(self.__ipAddr, self.__port) projuri = projObject.project_query(fullproj) varrayObject = VirtualArray(self.__ipAddr, self.__port) nhuri = varrayObject.varray_query(varray) parms = {"name": name, "project": projuri, "varray": nhuri, "type": exportgrouptype} if exportgrouptype and export_destination: if exportgrouptype == "Cluster": cluster_obj = Cluster(self.__ipAddr, self.__port) try: cluster_uri = cluster_obj.cluster_query(export_destination, fullproj) except SOSError as e: raise e parms["clusters"] = [cluster_uri] elif exportgrouptype == "Host": host_obj = Host(self.__ipAddr, self.__port) try: host_uri = host_obj.query_by_name(export_destination) except SOSError as e: raise e parms["hosts"] = [host_uri] body = json.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 e if status: raise SOSError(SOSError.ENTRY_ALREADY_EXISTS_ERR, "Export group with name " + name + " already exists")
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)
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)
def create(self, varray, name, type): """ Makes REST API call to create network in a varray Parameters: varray: name of varray name: name of network type: type of transport protocol. FC, IP or Ethernet Returns: Created task details in JSON response payload """ network_exists = True try: self.show(name, varray) except SOSError as e: if e.err_code == SOSError.NOT_FOUND_ERR: network_exists = False else: raise e if network_exists: raise SOSError(SOSError.ENTRY_ALREADY_EXISTS_ERR, "Network with name: " + name + " already exists") from virtualarray import VirtualArray varray_obj = VirtualArray(self.__ipAddr, self.__port) varray_uri = varray_obj.varray_query(varray) # As per the ViPR Source Code 5th July body = json.dumps({"name": name, "transport_type": type}) # As per the wiki apec """ body = json.dumps({'network': { 'name' : name, '' : [ { "name" : endpoint } ] } }) """ (s, h) = common.service_json_request( self.__ipAddr, self.__port, "POST", Network.URI_VIRTUALARRAY_NETWORK.format(varray_uri), body ) o = common.json_decode(s) return o
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)
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)
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)
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)
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)
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)
class EMCViPRDriverCommon(object): OPENSTACK_TAG = 'OpenStack' def __init__(self, protocol, default_backend_name, configuration=None): self.protocol = protocol self.configuration = configuration self.configuration.append_config_values(volume_opts) self.check_for_vipr_cli_path() self.init_vipr_cli_components() self.stats = { 'driver_version': '1.0', 'free_capacity_gb': 'unknown', 'reserved_percentage': '0', 'storage_protocol': protocol, 'total_capacity_gb': 'unknown', 'vendor_name': 'EMC', 'volume_backend_name': self.configuration.volume_backend_name or default_backend_name } self.volume_api = cinder_volume.API() def check_for_vipr_cli_path(self): if (self.configuration.vipr_cli_path is None): message = "vipr_cli_path is not set in cinder configuration" raise exception.VolumeBackendAPIException(data=message) if (os.path.exists(self.configuration.vipr_cli_path)): sys.path.append(self.configuration.vipr_cli_path) else: message = self.configuration.vipr_cli_path + " path does not" + \ " exist in the system. Please check/add/change" + \ " vipr_cli_path" + \ " in cinder configuration with valid ViPR" + \ " CLI installation path" raise exception.VolumeBackendAPIException(data=message) 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) def check_for_setup_error(self): # validate all of the vipr_* configuration values if (self.configuration.vipr_hostname is None): message = "vipr_hostname is not set in cinder configuration" raise exception.VolumeBackendAPIException(data=message) if (self.configuration.vipr_port is None): message = "vipr_port is not set in cinder configuration" raise exception.VolumeBackendAPIException(data=message) if (self.configuration.vipr_username is None): message = "vipr_username is not set in cinder configuration" raise exception.VolumeBackendAPIException(data=message) if (self.configuration.vipr_password is None): message = "vipr_password is not set in cinder configuration" raise exception.VolumeBackendAPIException(data=message) if (self.configuration.vipr_tenant is None): message = "vipr_tenant is not set in cinder configuration" raise exception.VolumeBackendAPIException(data=message) if (self.configuration.vipr_project is None): message = "vipr_project is not set in cinder configuration" raise exception.VolumeBackendAPIException(data=message) if (self.configuration.vipr_varray is None): message = "vipr_varray is not set in cinder configuration" raise exception.VolumeBackendAPIException(data=message) def authenticate_user(self): global AUTHENTICATED from authentication import Authentication # we should check to see if we are already authenticated before blindly # doing it again if (AUTHENTICATED is False): obj = Authentication(self.configuration.vipr_hostname, self.configuration.vipr_port) # cookiedir = os.getcwd() cookiedir = self.configuration.vipr_cookiedir obj.authenticate_user(self.configuration.vipr_username, self.configuration.vipr_password, cookiedir, None) AUTHENTICATED = True @retry_wrapper def create_volume(self, vol): self.authenticate_user() name = self._get_volume_name(vol) size = int(vol['size']) * 1073741824 from common import SOSError vpool = self._get_vpool(vol) self.vpool = vpool['ViPR:VPOOL'] try: res = self.volume_obj.create( self.configuration.vipr_tenant + "/" + self.configuration.vipr_project, name, size, self.configuration.vipr_varray, self.vpool, protocol=None, # no longer specified in volume # creation sync=True, number_of_volumes=1, thin_provisioned=None, consistencygroup=None) except SOSError as e: if (e.err_code == SOSError.SOS_FAILURE_ERR): raise SOSError( SOSError.SOS_FAILURE_ERR, "Volume " + name + ": Tag failed\n" + e.err_text) else: raise e @retry_wrapper def setTags(self, vol): self.authenticate_user() name = self._get_volume_name(vol) from common import SOSError # first, get the current tags that start with the OPENSTACK_TAG # eyecatcher removeTags = [] currentTags = self.volume_obj.getTags(self.configuration.vipr_tenant + "/" + self.configuration.vipr_project + "/" + name) for cTag in currentTags: if (cTag.startswith(self.OPENSTACK_TAG)): removeTags.append(cTag) try: if (len(removeTags) > 0): self.volume_obj.tag( self.configuration.vipr_tenant + "/" + self.configuration.vipr_project + "/" + name, None, removeTags) except SOSError as e: if (e.err_code == SOSError.SOS_FAILURE_ERR): LOG.debug("SOSError adding the tag: " + e.err_text) # now add the tags for the volume addTags = [] # put all the openstack volume properties into the ViPR volume try: for prop, value in vars(vol).iteritems(): try: # don't put the status in, it's always the status before # the current transaction if (not prop.startswith("status")): addTags.append(self.OPENSTACK_TAG + ":" + prop + ":" + value) except Exception: pass except Exception: pass try: self.volume_obj.tag( self.configuration.vipr_tenant + "/" + self.configuration.vipr_project + "/" + name, addTags, None) except SOSError as e: if (e.err_code == SOSError.SOS_FAILURE_ERR): LOG.debug("SOSError adding the tag: " + e.err_text) return (self.volume_obj.getTags(self.configuration.vipr_tenant + "/" + self.configuration.vipr_project + "/" + name)) @retry_wrapper def create_cloned_volume(self, vol, src_vref): """Creates a clone of the specified volume.""" self.authenticate_user() name = self._get_volume_name(vol) srcname = self._get_volume_name(src_vref) number_of_volumes = 1 from common import SOSError try: res = self.volume_obj.clone(self.configuration.vipr_tenant + "/" + self.configuration.vipr_project, name, number_of_volumes, srcname, None, sync=True) except SOSError as e: if (e.err_code == SOSError.SOS_FAILURE_ERR): raise SOSError( SOSError.SOS_FAILURE_ERR, "Volume " + name + ": clone failed\n" + e.err_text) else: raise e @retry_wrapper def expand_volume(self, vol, new_size): """expands the volume to new_size specified.""" self.authenticate_user() volume_name = self._get_volume_name(vol) import common as vipr_utils size_in_bytes = vipr_utils.to_bytes(str(new_size) + "G") from common import SOSError try: self.volume_obj.expand( self.configuration.vipr_tenant + "/" + self.configuration.vipr_project + "/" + volume_name, size_in_bytes, True) except SOSError as e: if (e.err_code == SOSError.SOS_FAILURE_ERR): raise SOSError( SOSError.SOS_FAILURE_ERR, "Volume " + volume_name + ": expand failed\n" + e.err_text) else: raise e @retry_wrapper def create_volume_from_snapshot(self, snapshot, volume): """Creates volume from given snapshot ( snapshot clone to volume ).""" self.authenticate_user() src_snapshot_name = snapshot['name'] src_vol_ref = self.volume_api.get(context.get_admin_context(), snapshot['volume_id']) src_vol_name = self._get_volume_name(src_vol_ref) new_volume_name = self._get_volume_name(volume) number_of_volumes = 1 from common import SOSError try: self.volume_obj.clone(self.configuration.vipr_tenant + "/" + self.configuration.vipr_project, new_volume_name, number_of_volumes, src_vol_name, src_snapshot_name, sync=True) except SOSError as e: if (e.err_code == SOSError.SOS_FAILURE_ERR): raise SOSError( SOSError.SOS_FAILURE_ERR, "Snapshot " + src_snapshot_name + ": clone failed\n" + e.err_text) else: raise e @retry_wrapper def delete_volume(self, vol): self.authenticate_user() name = self._get_volume_name(vol) from common import SOSError try: self.volume_obj.delete(self.configuration.vipr_tenant + "/" + self.configuration.vipr_project + "/" + name, volume_name_list=None, sync=True) except SOSError as e: if e.err_code == SOSError.NOT_FOUND_ERR: LOG.info("Volume " + name + " no longer exists; volume deletion is" + " considered success.") elif e.err_code == SOSError.SOS_FAILURE_ERR: raise SOSError( SOSError.SOS_FAILURE_ERR, "Volume " + name + ": Delete failed\n" + e.err_text) else: raise e @retry_wrapper def list_volume(self): import common as vipr_utils from common import SOSError try: uris = self.volume_obj.list_volumes( self.configuration.vipr_tenant + "/" + self.configuration.vipr_project) if (len(uris) > 0): output = [] for uri in uris: output.append(self.volume_obj.show_by_uri(uri)) return vipr_utils.format_json_object(output) else: return except SOSError as e: raise e @retry_wrapper def create_snapshot(self, snapshot): self.authenticate_user() from common import SOSError try: snapshotname = snapshot['name'] vol = snapshot['volume'] volumename = self._get_volume_name(vol) projectname = self.configuration.vipr_project tenantname = self.configuration.vipr_tenant storageresType = 'block' storageresTypename = 'volumes' resourceUri = self.snapshot_obj.storageResource_query( storageresType, fileshareName=None, volumeName=volumename, cgName=None, project=projectname, tenant=tenantname) inactive = False rptype = None sync = True self.snapshot_obj.snapshot_create(storageresType, storageresTypename, resourceUri, snapshotname, inactive, rptype, sync) return except SOSError as e: if (e.err_code == SOSError.SOS_FAILURE_ERR): raise SOSError( SOSError.SOS_FAILURE_ERR, "Snapshot: " + snapshotname + ", Create Failed\n" + e.err_text) else: raise e @retry_wrapper def delete_snapshot(self, snapshot): self.authenticate_user() snapshotname = snapshot['name'] from common import SOSError try: vol = snapshot['volume'] volumename = self._get_volume_name(vol) projectname = self.configuration.vipr_project tenantname = self.configuration.vipr_tenant storageresType = 'block' storageresTypename = 'volumes' resourceUri = self.snapshot_obj.storageResource_query( storageresType, fileshareName=None, volumeName=volumename, cgName=None, project=projectname, tenant=tenantname) if resourceUri is None: LOG.info("Snapshot " + snapshotname + " is not found; snapshot deletion" + " is considered successful.") else: self.snapshot_obj.snapshot_delete(storageresType, storageresTypename, resourceUri, snapshotname, sync=True) return except SOSError as e: if (e.err_code == SOSError.SOS_FAILURE_ERR): raise SOSError( SOSError.SOS_FAILURE_ERR, "Snapshot " + snapshotname + ": Delete Failed\n") else: raise e @retry_wrapper def initialize_connection(self, volume, protocol, initiatorNodes, initiatorPorts, hostname): from common import SOSError try: self.authenticate_user() volumename = self._get_volume_name(volume) foundgroupname = self._find_exportgroup(initiatorPorts) if (foundgroupname is None): for i in xrange(len(initiatorPorts)): # check if this initiator is contained in any ViPR Host # object LOG.debug("checking for initiator port:" + initiatorPorts[i]) foundhostname = self._find_host(initiatorPorts[i]) if (foundhostname is None): hostfound = self._host_exists(hostname) if (hostfound is None): # create a host so it can be added to the export # group hostfound = hostname self.host_obj.create( hostname, platform.system(), hostname, self.configuration.vipr_tenant, port=None, username=None, passwd=None, usessl=None, osversion=None, cluster=None, datacenter=None, vcenter=None, autodiscovery=True) LOG.info("Created host " + hostname) # add the initiator to the host self.hostinitiator_obj.create(hostfound, protocol, initiatorNodes[i], initiatorPorts[i]) LOG.info("Initiator " + initiatorPorts[i] + " added to host " + hostfound) foundhostname = hostfound else: LOG.info("Found host " + foundhostname) # create an export group for this host foundgroupname = foundhostname + 'SG' # create a unique name foundgroupname = foundgroupname + '-' + \ ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(6)) res = self.exportgroup_obj.exportgroup_create( foundgroupname, self.configuration.vipr_project, self.configuration.vipr_tenant, self.configuration.vipr_varray, 'Host', foundhostname) LOG.debug("adding the volume to the exportgroup : " + volumename) res = self.exportgroup_obj.exportgroup_add_volumes( True, foundgroupname, self.configuration.vipr_tenant, self.configuration.vipr_project, [volumename], None, None) return self._find_device_info(volume, initiatorPorts) except SOSError as e: raise SOSError( SOSError.SOS_FAILURE_ERR, "Attach volume (" + self._get_volume_name(volume) + ") to host (" + hostname + ") initiator (" + initiatorPorts[0] + ") failed: " + e.err_text) @retry_wrapper def terminate_connection(self, volume, protocol, initiatorNodes, initiatorPorts, hostname): from common import SOSError try: self.authenticate_user() volumename = self._get_volume_name(volume) tenantproject = self.configuration.vipr_tenant + \ '/' + self.configuration.vipr_project voldetails = self.volume_obj.show(tenantproject + '/' + volumename) volid = voldetails['id'] # find the exportgroups exports = self.volume_obj.get_exports_by_uri(volid) exportgroups = set() itls = exports['itl'] for itl in itls: itl_port = itl['initiator']['port'] if (itl_port in initiatorPorts): exportgroups.add(itl['export']['id']) for exportgroup in exportgroups: res = self.exportgroup_obj.exportgroup_remove_volumes_by_uri( exportgroup, volid, True, None, None, None, None) else: LOG.info("No export group found for the host: " + hostname + "; this is considered already detached.") return itls except SOSError as e: raise SOSError( SOSError.SOS_FAILURE_ERR, "Detaching volume " + volumename + " from host " + hostname + " failed: " + e.err_text) @retry_wrapper def _find_device_info(self, volume, initiator_ports): '''Returns the device_info in a list of itls that have the matched initiator (there could be multiple targets, hence a list): [ { "hlu":9, "initiator":{...,"port":"20:00:00:25:B5:49:00:22"}, "export":{...}, "device":{...,"wwn":"600601602B802D00B62236585D0BE311"}, "target":{...,"port":"50:06:01:6A:46:E0:72:EF"}, "san_zone_name":"..." }, { "hlu":9, "initiator":{...,"port":"20:00:00:25:B5:49:00:22"}, "export":{...}, "device":{...,"wwn":"600601602B802D00B62236585D0BE311"}, "target":{...,"port":"50:06:01:62:46:E0:72:EF"}, "san_zone_name":"..." } ] ''' volumename = self._get_volume_name(volume) fullname = self.configuration.vipr_project + '/' + volumename vol_uri = self.volume_obj.volume_query(fullname) ''' The itl info shall be available at the first try since now export is a synchronous call. We are trying a few more times to accommodate any delay on filling in the itl info after the export task is completed. ''' itls = [] for x in xrange(10): exports = self.volume_obj.get_exports_by_uri(vol_uri) LOG.debug(_("Volume exports: %s") % exports) for itl in exports['itl']: itl_port = itl['initiator']['port'] if (itl_port in initiator_ports): found_device_number = itl['hlu'] if (found_device_number is not None and found_device_number != '-1'): # 0 is a valid number for found_device_number. # Only loop if it is None or -1 LOG.debug("Found Device Number: " + str(found_device_number)) itls.append(itl) if itls: break else: LOG.debug("Device Number not found yet." + " Retrying after 10 seconds...") time.sleep(10) if itls is None: # No device number found after 10 tries; return an empty itl LOG.info("No device number has been found after 10 tries;" + "this likely indicates an unsuccessful attach of" + "volume " + volumename + " to" + " initiator " + str(initiator_ports)) return itls def _get_volume_name(self, vol): try: name = vol['display_name'] except Exception as exp: name = None if (name is None or len(name) == 0): name = vol['name'] return name def _get_vpool(self, volume): vpool = {} ctxt = context.get_admin_context() type_id = volume['volume_type_id'] if type_id is not None: volume_type = volume_types.get_volume_type(ctxt, type_id) specs = volume_type.get('extra_specs') for key, value in specs.iteritems(): vpool[key] = value return vpool @retry_wrapper def _find_exportgroup(self, initiator_ports): '''Find the export group to which the given initiator ports are the same as the initiators in the group ''' foundgroupname = None grouplist = self.exportgroup_obj.exportgroup_list( self.configuration.vipr_project, self.configuration.vipr_tenant) for groupid in grouplist: groupdetails = self.exportgroup_obj.exportgroup_show( groupid, self.configuration.vipr_project, self.configuration.vipr_tenant) if groupdetails is not None: if (groupdetails['inactive']): continue initiators = groupdetails['initiators'] if initiators is not None: inits_eg = set() for initiator in initiators: inits_eg.add(initiator['initiator_port']) if (inits_eg == set(initiator_ports)): foundgroupname = groupdetails['name'] if foundgroupname is not None: # Check the associated varray if groupdetails['varray']: varray_uri = groupdetails['varray']['id'] varray_details = self.varray_obj.varray_show( varray_uri) if (varray_details['name'] == self.configuration.vipr_varray): LOG.debug("Found exportgroup " + foundgroupname) break # Not the right varray foundgroupname = None return foundgroupname @retry_wrapper def _find_host(self, initiator_port): '''Find the host, if exists, to which the given initiator belong.''' foundhostname = None hosts = self.host_obj.list_by_tenant(self.configuration.vipr_tenant) for host in hosts: initiators = self.host_obj.list_initiators(host['id']) for initiator in initiators: if (initiator_port == initiator['name']): foundhostname = host['name'] break if foundhostname is not None: break return foundhostname @retry_wrapper def _host_exists(self, host_name): '''Check if a Host object with the given hostname already exists in ViPR ''' hosts = self.host_obj.search_by_name(host_name) if (len(hosts) > 0): for host in hosts: hostname = host['match'] if (host_name == hostname): return hostname return hostname LOG.debug("no host found for:" + host_name) return None @retry_wrapper def update_volume_stats(self): """Retrieve stats info.""" LOG.debug(_("Updating volume stats")) self.authenticate_user() import common as vipr_utils from common import SOSError try: vols = self.volume_obj.list_volumes( self.configuration.vipr_tenant + "/" + self.configuration.vipr_project) vpairs = set() if (len(vols) > 0): for vol in vols: if (vol): vpair = (vol["vpool"]["id"], vol["varray"]["id"]) if (vpair not in vpairs): vpairs.add(vpair) if (len(vpairs) > 0): free_gb = 0.0 used_gb = 0.0 provisioned_gb = 0.0 precent_used = 0.0 percent_provisioned = 0.0 for vpair in vpairs: if (vpair): (s, h) = vipr_utils.service_json_request( self.configuration.vipr_hostname, self.configuration.vipr_port, "GET", URI_VPOOL_VARRAY_CAPACITY.format( vpair[0], vpair[1]), body=None) capacity = vipr_utils.json_decode(s) free_gb += float(capacity["free_gb"]) used_gb += float(capacity["used_gb"]) provisioned_gb += float(capacity["provisioned_gb"]) self.stats['free_capacity_gb'] = free_gb self.stats['total_capacity_gb'] = free_gb + used_gb self.stats['reserved_percentage'] = 100 * \ provisioned_gb / (free_gb + used_gb) return self.stats except SOSError as e: raise e
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
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")
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
def getVarrayList(self, varrays): varray_obj = VirtualArray(self.__ipAddr, self.__port) return varray_obj.convertNamesToUris(varrays)
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
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")