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 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 dict_to_naelement(naelem_dict, parent_naelem=None): """ Generates an NaElement object from a dictionary, useful for API calls that require nested NaElement objects (like nfs exports) or for spoofing response objects. Note that the outermost dictionary can only contain one parent key and the optional attribute. """ attrs = None #if not parent_naelem and len(naelem_dict) > 2 and 'attrs' not in naelem_dict: # raise NetCrAPIOut('There can only be ONE (top level element)!') for k, v in naelem_dict.iteritems(): if k == 'attrs': attrs = v #print "attrs: " #print v continue else: if isinstance(v, dict): new_naelem = NaElement(k) if parent_naelem: parent_naelem.child_add(new_naelem) dict_to_naelement(v, new_naelem) elif isinstance(v, list): for item in v: new_naelem = NaElement(k) if parent_naelem: parent_naelem.child_add(new_naelem) dict_to_naelement(item, new_naelem) elif isinstance(v, str): if parent_naelem: parent_naelem.child_add_string(k, v) if not parent_naelem: if attrs: for k, v in attrs.iteritems(): new_naelem.attr_set(k, v) return new_naelem