def listSnapshots(volume): cmd = NaElement("snapshot-list-info") cmd.child_add_string("volume", volume) ret = executeCmd(cmd) return ret
def create(self, aggr, size): """@todo: Docstring for create. :aggr: @todo :size: @todo :returns: @todo """ list_in = NaElement('volume-create') #name list_in.child_add_string("volume", self.name) #aggr list_in.child_add_string("containing-aggr-name", aggr) #size size_pattern = re.compile('^[1-9][0-9]*[kmgt]') if size_pattern.match(size): list_in.child_add_string("size", size) else: raise NetCrAPIOut("Size not valid. Please use <number>k|m|g|t.") pass #space reservation (none) list_in.child_add_string("space-reserve", "none") #language (en_US) list_in.child_add_string("language-code", "en_US") out = self.invoke_elem(list_in) check_zapi_error(out)
def listSnapshots(volume): cmd = NaElement('snapshot-list-info') cmd.child_add_string('volume', volume) ret = executeCmd(cmd) return ret
def createClone(parentVolume, volume): cmd = NaElement("volume-clone-create") cmd.child_add_string("parent-volume", parentVolume) cmd.child_add_string("volume", volume) # Feature disabled for now debugret = NaElement("results") debugret.attr_set("status", "failed") debugret.attr_set("reason", "Creating clones not supported...yet!") return debugret
def createSnapshot(volume, customname=None): if customname: snapshotName = customname else: # Create snapshot format name snapshotName = "snap_" + volume + "_" + datetime.strftime(datetime.now(), "%Y%m%d%H%M%S") cmd = NaElement("snapshot-create") cmd.child_add_string("volume", volume) cmd.child_add_string("snapshot", snapshotName) return executeCmd(cmd)
def get_volumes(conn): cmd = NaElement('volume-get-iter') cmd.child_add_string('max-records', 500) out = conn.invoke_elem(cmd) if(out.results_status() == 'failed'): print (out.results_reason() + '\n') sys.exit(2) attributes = out.child_get('attributes-list') return attributes.children_get()
def listVolumes(): isDebug = getConfigOption("Debug") # Build command to list volumes cmd = NaElement("volume-get-iter") xi = NaElement("desired-attributes") xi1 = NaElement("volume-attributes") xi1.child_add(NaElement("volume-id-attributes")) xi1.child_add(NaElement("volume-snapshot-attributes")) xi1.child_add(NaElement("volume-space-attributes")) xi2 = NaElement("volume-clone-attributes") xi2.child_add(NaElement("volume-clone-parent-attributes")) xi1.child_add(xi2) xi.child_add(xi1) cmd.child_add(xi) cmd.child_add_string("max-records", "500") ret = executeCmd(cmd) # Remove volumes from list that contain filterStrings filterString = getConfigOption("VolFilters") filterList = filterString.replace(" ","").split(",") filteredVolumes = NaElement("attributes-list") for vol in ret.child_get("attributes-list").children_get(): volattrs = vol.child_get('volume-id-attributes') if any(x in volattrs.child_get_string('name') for x in filterList): if (isDebug == 'True'): print "Skipping filtered vol : %s" % volattrs.child_get_string('name') continue if (isDebug == 'True'): print 'Volume Name : %s' % volattrs.child_get_string('name') filteredVolumes.child_add(vol) filteredRet = NaElement("results") filteredRet.attr_set("status", "passed") filteredRet.child_add(filteredVolumes) if (isDebug == 'True'): print "Number of volumes (after filtering): " + str(ret.child_get("attributes-list").children_get().__len__()) return filteredRet
def set_snapshot_schedule(self, snap_sched): """@todo: Docstring for set_snapshot_schedule. :snap_sched: Dict that my contain one or more of the following keys: days, hours, minutes, weeks, which-hours, which-minutes :returns: @todo """ list_in = NaElement('snapshot-set-schedule') list_in.child_add_string('volume', self.name) for snap_interval, snap_count in snap_sched.iteritems(): list_in.child_add_string(snap_interval, snap_count) out = self.invoke_elem(list_in) check_zapi_error(out)
def get_instance_list(self, perf_obj): ''' Lists instances associated with the supplied performance object. Some objects actually have instances, like 'volume' and 'aggregate', while others only have themselves (so sad...) like 'system' or 'cifs' ''' list_in = NaElement("perf-object-instance-list-info") list_in.child_add_string("objectname", perf_obj) out = self.invoke_elem(list_in) check_zapi_error(out) inst_info = out.child_get("instances") result = inst_info.children_get() instance_names = [] for inst in result: inst_name = inst.child_get_string("name") instance_names.append(inst_name) return instance_names
def renameSnapshot(volume, snapshot, newName): cmd = NaElement("snapshot-rename") cmd.child_add_string("current-name", snapshot) cmd.child_add_string("volume", volume) cmd.child_add_string("new-name", newName) return executeCmd(cmd)
def get_counter_list(self, perf_obj): ''' Returns the counters associated with a performance object. This function also outputs the 'base counter', 'privilege level' and 'unit' of the counter. ''' list_in = NaElement("perf-object-counter-list-info") list_in.child_add_string("objectname", perf_obj) out = self.invoke_elem(list_in) check_zapi_error(out) counter_info = out.child_get("counters") result = counter_info.children_get() counter_list = [] for counter in result: counter_name = counter.child_get_string("name") if counter.child_get_string("base-counter"): base_counter = counter.child_get_string("base-counter") else: base_counter = "None" privilege_level = counter.child_get_string("privilege-level") if counter.child_get_string("unit"): unit = counter.child_get_string("unit") else: unit = "None" if counter.child_get_string("properties"): counter_type = counter.child_get_string("properties") else: counter_type = "None" counter_list.append([counter_name, base_counter, counter_type, privilege_level, unit]) return counter_list
def get_info(self): """@todo: Docstring for get_info. :returns: @todo """ volume_info = {'volume-autosize-attributes': { 'maximum-size': 'integer', 'increment-size': 'integer', 'is-enabled': 'boolean' }, 'volume-id-attributes': { 'containing-aggregate-name': 'string', 'type': 'string', 'owning-vserver-name': 'string' }, 'volume-inode-attributes': { 'files-total': 'integer', 'files-used': 'integer', 'block-type': 'string' }, 'volume-state-attributes': { 'state': 'string' }, 'volume-space-attributes': { 'percentage-size-used': 'integer', 'size-total': 'integer', 'size-available': 'integer', 'size-used': 'integer', 'size-used-by-snapshots': 'integer', 'space-guarantee': 'string', 'size': 'integer', 'percentage-snapshot-reserve': 'integer', 'percentage-fractional-reserve': 'integer', }, 'volume-sis-attributes': { 'is-sis-volume': 'boolean', 'deduplication-space-saved': 'integer', 'compression-space-saved': 'integer', 'total-space-saved': 'integer' } } vol_get_iter = NaElement('volume-get-iter') query = NaElement('query') vol_query_attrs = NaElement('volume-attributes') vol_id_attrs = NaElement('volume-id-attributes') vol_get_iter.child_add(query) query.child_add(vol_query_attrs) vol_query_attrs.child_add(vol_id_attrs) vol_id_attrs.child_add_string('name', self.name) out = self.invoke_elem(vol_get_iter) attributes_list = out.child_get('attributes-list').children_get()[0] #print attributes_list.sprintf() vol_info_dict = {} for vol_attribute_type, attributes in volume_info.iteritems(): attribute_group = attributes_list.child_get(vol_attribute_type) for attr_name, data_type in attributes.iteritems(): #print vol_attribute_type #print attribute_group #print attr_name #print data_type if data_type == 'string': data = attribute_group.child_get_string(attr_name) vol_info_dict[attr_name] = data elif data_type == 'integer': data = attribute_group.child_get_int(attr_name) vol_info_dict[attr_name] = data elif data_type == 'boolean': data = (attribute_group.child_get_string(attr_name) == 'true') vol_info_dict[attr_name] = data return vol_info_dict
def restoreSnapshot(volume, snapshot): cmd = NaElement("snapshot-restore-volume") cmd.child_add_string("snapshot", snapshot) cmd.child_add_string("volume", volume) return executeCmd(cmd)
'system': { # instances 'system': # counters [ 'serial_no', 'system_id', 'hostname', 'ontap_version', 'system_model' ], }, } server = ZenOntap('8.8.8.8', 'un', 'pw', 'HTTPS') request = NaElement('perf-object-get-instances') for perf, instances in perfGet.iteritems(): request.child_add_string('objectname', perf) reqinst = NaElement('instances') for instance, counters in instances.iteritems(): reqinst.child_add_string('instance', instance) reqcnts = NaElement('counters') for counter in counters: reqcnts.child_add_string('counter', counter) request.child_add(reqcnts) request.child_add(reqinst) response = server.invoke_elem_async(request) deferreds = [response] naElements = defer.DeferredList(deferreds, consumeErrors=True).addCallback(callback) reactor.run()
def deleteSnapshot(volume, snapshot): cmd = NaElement('snapshot-delete') cmd.child_add_string("snapshot", snapshot) cmd.child_add_string("volume", volume) return executeCmd(cmd)