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 == None): tenant = "" fullproj = tenant + "/" + project projuri = Project(self.__ipAddr, self.__port).project_query(fullproj) nhuri = VirtualArray(self.__ipAddr, self.__port).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] # else: # exportgrouptype == Exclusive # TODO: add code for initiator 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 exportgroup_add_cluster(self, exportgroupname, tenantname, projectname, clusternames, sync): exportgroup_uri = self.exportgroup_query(exportgroupname, projectname, tenantname) cluster_uris = [] clusterObject = Cluster(self.__ipAddr, self.__port) for clustername in clusternames: cluster_uris.append(clusterObject.cluster_query(clustername, tenantname)) parms = {} parms["cluster_changes"] = self._add_list(cluster_uris) o = self.send_json_request(exportgroup_uri, parms) return self.check_for_sync(o, sync)
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 exportgroup_remove_cluster(self, exportgroupname, tenantname, projectname, clusternames, sync): exportgroup_uri = self.exportgroup_query(exportgroupname, projectname, tenantname) # cluster search API does not take project parameter. cluster_uris = [] clusterObject = Cluster(self.__ipAddr, self.__port) for clustername in clusternames: cluster_uris.append(clusterObject.cluster_query(clustername, tenantname)) parms = {} parms["cluster_changes"] = self._remove_list(cluster_uris) o = self.send_json_request(exportgroup_uri, parms) return self.check_for_sync(o, sync) # host """
def get_cluster_id(self, clusterName, projectName, tenantName): clusterObj = Cluster(self.__ipAddr, self.__port) clusterId = clusterObj.cluster_query(clusterName, projectName, tenantName) return clusterId