def execute(self, server, cmd_data_json): if ( "name" not in cmd_data_json or "new_name" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( 'SVM rename request must have ' + 'name and new_name defined, got: ' + str(cmd_data_json)) name = cmd_data_json['name'] new_name = cmd_data_json['new_name'] cmd = "vserver-rename" call = NaElement(cmd) call.child_add_string("vserver-name", name) call.child_add_string("new-name", new_name) resp, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + name + ' --> ' + new_name) #LOGGER.debug(resp.sprintf()) if err_resp: return err_resp return self._CREATE_EMPTY_RESPONSE(True, "")
def svm_execute(self, svm, cmd_data_json): if ( "name" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( 'volume [' + self._get_simple_cmd() + '] request must have name ' + 'defined, got: ' + str(cmd_data_json)) name = cmd_data_json['name'] cmd = "volume-" + self._get_simple_cmd() call = NaElement(cmd) call.child_add_string("name", name) resp, err_resp = self._INVOKE_CHECK( svm, call, cmd + ": " + name) #LOGGER.debug(resp.sprintf()) if err_resp: return err_resp return self._CREATE_EMPTY_RESPONSE(True, "")
def execute(self, server, cmd_data_json): if ("name" not in cmd_data_json or "ipspace" not in cmd_data_json or ("subnet" not in cmd_data_json and "gateway" not in cmd_data_json)): return self._CREATE_FAIL_RESPONSE( "subnet modify must" + " have name, ipspace and either" + " gateway or subnet defined" + ", got: " + str(cmd_data_json)) name = cmd_data_json["name"] ipspace = cmd_data_json["ipspace"] cmd = "net-subnet-modify" call = NaElement(cmd) call.child_add_string("subnet-name", name) call.child_add_string("ipspace", ipspace) if "gateway" in cmd_data_json: call.child_add_string("gateway", cmd_data_json["gateway"]) if "subnet" in cmd_data_json: call.child_add_string("subnet", cmd_data_json["subnet"]) _, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + name + " [" + ipspace + "] <-- " + str(cmd_data_json)) if err_resp: return err_resp # LOGGER.debug(resp.sprintf()) return self._CREATE_EMPTY_RESPONSE(True, "")
def execute(self, server, cmd_data_json): if ("node" not in cmd_data_json or "name" not in cmd_data_json or "mode" not in cmd_data_json or "dist" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( "port group create commands must" + " have node, name, mode" + " and distribution defined" + ", got: " + str(cmd_data_json)) node = cmd_data_json["node"] name = cmd_data_json["name"] mode = cmd_data_json["mode"] dist = cmd_data_json["dist"] cmd = "net-port-ifgrp-create" call = NaElement(cmd) call.child_add_string("distribution-function", dist) call.child_add_string("ifgrp-name", name) call.child_add_string("mode", mode) call.child_add_string("node", node) call.child_add_string("return-record", False) resp, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + node + " [" + name + "]") if err_resp: return err_resp #LOGGER.debug(resp.sprintf()) return self._CREATE_EMPTY_RESPONSE(True, "")
def execute(self, server, cmd_data_json): call = NaElement("system-get-ontapi-version") resp, err_resp = self._INVOKE_CHECK(server, call, "system-get-ontapi-version") if err_resp: return err_resp majvnum = resp.child_get_int('major-version') minvnum = resp.child_get_int('minor-version') LOGGER.debug("ONTAPI v %d.%d" % (majvnum, minvnum)) call = NaElement("system-get-version") resp, err_resp = self._INVOKE_CHECK(server, call, "system-get-version") if err_resp: return err_resp os_version = resp.child_get_string('version') LOGGER.debug("OS Version: %s", os_version) return { 'success': True, 'errmsg': '', 'data': { 'ontap_major': majvnum, 'ontap_minor': minvnum, 'os_version': os_version } }
def create(self, cluster): api_call = NaElement('vserver-create-async') api_call.child_add_string('vserver-name', self.vserver_name) api_call.child_add_string('root-volume', self.root_volume) api_call.child_add_string('root-volume-aggregate', self.root_volume_aggregate) api_call.child_add_string('root-volume-security-style', self.root_volume_security_style) output = cluster.run_command(api_call) return output.results_status(), output.sprintf()
def create(self, svm): api_call = NaElement('lun-create-by-size') api_call.child_add_string('path', self.path) api_call.child_add_string('size', self.size) api_call.child_add_string('ostype', self.ostype) api_call.child_add_string('space-reservation-enabled', self.space_reservation_enabled) api_call.child_add_string('space-allocation-enabled', self.space_allocation_enabled) output = svm.run_command(api_call) return output.results_status(), output.sprintf()
def execute(self, server, cmd_data_json): if ("name" not in cmd_data_json or "ipspace" not in cmd_data_json or "new_name" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( "subnet rename commands must" + " have name, new name and ipspace defined" + ", got: " + str(cmd_data_json)) name = cmd_data_json["name"] ipspace = cmd_data_json["ipspace"] new_name = cmd_data_json["new_name"] cmd = "net-subnet-rename" call = NaElement(cmd) call.child_add_string("subnet-name", name) call.child_add_string("ipspace", ipspace) call.child_add_string("new-name", new_name) _, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + name + " [" + ipspace + "] --> " + new_name) if err_resp: return err_resp # LOGGER.debug(resp.sprintf()) return self._CREATE_EMPTY_RESPONSE(True, "")
def execute(self, server, cmd_data_json): if ("name" not in cmd_data_json or "ipspace" not in cmd_data_json or "mtu" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( "broadcast domain update commands must" + " have name, ipspace and mtu defined," + " got: " + str(cmd_data_json)) name = cmd_data_json["name"] ipspace = cmd_data_json["ipspace"] mtu = cmd_data_json["mtu"] cmd = "net-port-broadcast-domain-modify" call = NaElement(cmd) call.child_add_string("broadcast-domain", name) call.child_add_string("ipspace", ipspace) call.child_add_string("mtu", mtu) resp, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + name + " [" + ipspace + "]") if err_resp: return err_resp # LOGGER.debug(resp.sprintf()) dd = { "update_status": self._GET_STRING(resp, "port-update-status-combined"), } return {'success': True, 'errmsg': '', 'data': dd}
def create(self, svm): api_call = NaElement('igroup-create') api_call.child_add_string('initiator-group-name', self.initiator_group_name) api_call.child_add_string('initiator-group-type', self.initiator_group_type) api_call.child_add_string('os-type', self.os_type) output = svm.run_command(api_call) return output.results_status(), output.sprintf()
def execute(self, server, cmd_data_json): if "name" not in cmd_data_json: return self._CREATE_FAIL_RESPONSE( 'delete ipspace must have name defined, got: ' + str(cmd_data_json)) name = cmd_data_json["name"] cmd = "net-ipspaces-destroy" call = NaElement(cmd) call.child_add_string("ipspace", name) _, err_resp = self._INVOKE_CHECK(server, call, cmd + ": " + name) if err_resp: return err_resp return self._CREATE_EMPTY_RESPONSE(True, "")
def execute(self, server, cmd_data_json): if ( "name" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( self._get_simple_cmd() + ' SVM request must have name ' + 'defined, got: ' + str(cmd_data_json)) name = cmd_data_json['name'] cmd = "vserver-" + self._get_simple_cmd() call = NaElement(cmd) call.child_add_string("vserver-name", name) # force will only be present if set otherwise ommitted if 'force' in cmd_data_json: call.child_add_string('force', True) resp, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + name) #LOGGER.debug(resp.sprintf()) if err_resp: return err_resp return self._CREATE_EMPTY_RESPONSE(True, "")
def execute(self, server, cmd_data_json): if ("node" not in cmd_data_json or "name" not in cmd_data_json or "ports" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( "port group port " + self._get_cmd_type() + " commands must" + " have node, name and ports defined" + ", got: " + str(cmd_data_json)) node = cmd_data_json["node"] name = cmd_data_json["name"] ports = cmd_data_json["ports"] cmd = ("net-port-ifgrp-" + self._get_cmd_type() + "-port") # ifgrp only allows add/remove of single port... for port in ports: call = NaElement(cmd) call.child_add_string("ifgrp-name", name) call.child_add_string("node", node) call.child_add_string("port", port) resp, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + node + " [" + name + "]" + self._get_cmd_type() + " " + port) if err_resp: return err_resp #LOGGER.debug(resp.sprintf()) return self._CREATE_EMPTY_RESPONSE(True, "")
def execute(self, server, cmd_data_json): if "name" not in cmd_data_json: return self._CREATE_FAIL_RESPONSE( 'create IPSpace request must have name' + ' defined, got: ' + str(cmd_data_json)) name = cmd_data_json["name"] cmd = "net-ipspaces-create" call = NaElement(cmd) call.child_add_string("ipspace", name) call.child_add_string("return-record", "true") resp, err_resp = self._INVOKE_CHECK(server, call, cmd + ": " + name) if err_resp: return err_resp if not (resp.child_get("result") and resp.child_get("result").child_get("net-ipspaces-info")): return self._CREATE_FAIL_RESPONSE( 'no ipspace info received from create, got: ' + resp.sprintf()) ipspace_info = resp.child_get("result").child_get("net-ipspaces-info") dd = {"uuid": self._GET_STRING(ipspace_info, "uuid")} return {'success': True, 'errmsg': '', 'data': dd}
def execute(self, server, cmd_data_json): if ("node" not in cmd_data_json or "port" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( 'modify port request must have node and port defined, got: ' + str(cmd_data_json)) node = cmd_data_json["node"] port = cmd_data_json["port"] cmd = "net-port-modify" call = NaElement(cmd) call.child_add_string("node", node) call.child_add_string("port", port) for cmd_data_key, netapp_cmd_str in self.__cmd_mapping.items(): if cmd_data_key in cmd_data_json: call.child_add_string(netapp_cmd_str, cmd_data_json[cmd_data_key]) _, err_resp = self._INVOKE_CHECK(server, call, cmd + ": " + node + ":" + port) if err_resp: return err_resp return self._CREATE_EMPTY_RESPONSE(True, "")
def execute(self, server, cmd_data_json): if ( "name" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( 'delete SVM request must have name, ' + 'defined, got: ' + str(cmd_data_json)) name = cmd_data_json['name'] cmd = "vserver-destroy-async" call = NaElement(cmd) call.child_add_string("vserver-name", name) resp, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + name) #LOGGER.debug(resp.sprintf()) if err_resp: return err_resp dd = { "status": self._GET_STRING(resp, "result-status"), } if resp.child_get("result-jobid"): dd["jobid"] = self._GET_INT(resp, "result-jobid") if resp.child_get('result-error-code'): dd["errno"] = self._GET_INT(resp, "result-error-code") if resp.child_get('result-error-message'): dd["errmsg"] = self._GET_STRING(resp, "result-error-message") return { 'success' : True, 'errmsg': '', 'data': dd}
def get_nodes(self): api_call = NaElement('cluster-node-get-iter') output = self.run_command(api_call) if output.results_status() == 'failed': return output.results_status(), output.sprintf() else: cluster_node_info = output.children_get() for cni in cluster_node_info: if cni.has_children() == 1: nodes = cni.children_get() nodes_list = [] for n in nodes: nodes_list.append(n.child_get_string('node-name')) return nodes_list
def mapping(self, svm): results = [] for igroup in self.igroup_name: api_call = NaElement('lun-map') api_call.child_add_string('path', self.path) api_call.child_add_string('initiator-group', igroup) output = svm.run_command(api_call) results.append( (output.results_status(), output.sprintf(), self.path, igroup)) return results
def add_initiators(self, svm): results = [] for wwpn in self.initiator_list: api_call = NaElement('igroup-add') api_call.child_add_string('initiator-group-name', self.initiator_group_name) api_call.child_add_string('initiator', wwpn) output = svm.run_command(api_call) results.append((output.results_status(), output.sprintf(), self.initiator_group_name, wwpn)) return results
def svm_execute(self, svm, cmd_data_json): if ( "name" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( 'SVM volume size request must have name ' + 'defined, got: ' + str(cmd_data_json)) name = cmd_data_json['name'] cmd = "volume-size" call = NaElement(cmd) call.child_add_string("volume", name) if 'size' in cmd_data_json: call.child_add_string( 'new-size', cmd_data_json['size']) resp, err_resp = self._INVOKE_CHECK( svm, call, cmd + ": " + name) #LOGGER.debug(resp.sprintf()) if err_resp: return err_resp dd = { "size": self._GET_STRING(resp, "volume-size"), } # if resp.child_get("result-jobid"): # dd["jobid"] = self._GET_INT(resp, "result-jobid") # if resp.child_get('result-error-code'): # dd["errno"] = self._GET_INT(resp, "result-error-code") # if resp.child_get('result-error-message'): # dd["errmsg"] = self._GET_STRING(resp, "result-error-message") return { 'success' : True, 'errmsg': '', 'data': dd}
def execute(self, server, cmd_data_json): if ("name" not in cmd_data_json or "new_name" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( 'update/rename ipspace must have name' + ' and new_name defined, got: ' + str(cmd_data_json)) name = cmd_data_json["name"] new_name = cmd_data_json["new_name"] cmd = "net-ipspaces-rename" call = NaElement(cmd) call.child_add_string("ipspace", name) call.child_add_string("new-name", new_name) _, err_resp = self._INVOKE_CHECK(server, call, cmd + ": " + name + ' to ' + new_name) if err_resp: return err_resp return self._CREATE_EMPTY_RESPONSE(True, "")
def execute(self, server, cmd_data_json): if ("name" not in cmd_data_json or "ipspace" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE('delete subnet must have name' + ' and ipspace defined, got: ' + str(cmd_data_json)) name = cmd_data_json["name"] ipspace = cmd_data_json["ipspace"] cmd = "net-subnet-destroy" call = NaElement(cmd) call.child_add_string("subnet-name", name) call.child_add_string("ipspace", ipspace) _, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + name + ' [' + ipspace + ']') if err_resp: return err_resp return self._CREATE_EMPTY_RESPONSE(True, "")
def execute(self, server, cmd_data_json): if ("node" not in cmd_data_json or "name" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( "port group delete command must" + " have node and name defined" + ", got: " + str(cmd_data_json)) node = cmd_data_json["node"] name = cmd_data_json["name"] cmd = "net-port-ifgrp-destroy" call = NaElement(cmd) call.child_add_string("ifgrp-name", name) call.child_add_string("node", node) resp, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + node + " [" + name + "]") if err_resp: return err_resp #LOGGER.debug(resp.sprintf()) return self._CREATE_EMPTY_RESPONSE(True, "")
def create(self, cluster): api_call = NaElement('aggr-create') api_call.child_add_string('aggregate', self.aggr_name) api_call.child_add_string('disk-count', self.disk_count) api_call.child_add_string('disk-type', self.disk_type) api_call.child_add_string('raid-type', self.raid_type) api_call.child_add_string('raid-size', self.raid_size) api_child_nodes = NaElement('nodes') api_child_nodes.child_add_string('node-name', self.node_name) api_call.child_add(api_child_nodes) output = cluster.run_command(api_call) return output.results_status(), output.sprintf()
def execute(self, server, cmd_data_json): if ("name" not in cmd_data_json or "ipspace" not in cmd_data_json or "ip_ranges" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( "subnet ip range " + self._get_cmd_type() + " commands must" + " have name, ipspace and ip_ranges defined" + ", got: " + str(cmd_data_json)) name = cmd_data_json["name"] ipspace = cmd_data_json["ipspace"] iprs = cmd_data_json["ip_ranges"] cmd = ("net-subnet-" + self._get_cmd_type() + "-ranges") call = NaElement(cmd) call.child_add_string("subnet-name", name) call.child_add_string("ipspace", ipspace) el_iprs = NaElement("ip-ranges") for ip_range in iprs: el_iprs.child_add_string("ip-range", ip_range) call.child_add(el_iprs) _, err_resp = self._INVOKE_CHECK( server, call, cmd + ": " + name + " [" + ipspace + "]" + self._get_cmd_type() + str(iprs)) if err_resp: return err_resp # LOGGER.debug(resp.sprintf()) return self._CREATE_EMPTY_RESPONSE(True, "")
def cluster_setup(cluster): print("> " + cluster["cluster-name"] + ": Creating Cluster ") for node in cluster["cluster-nodes"]: print("---> " + node["node-name"] + ": Working on node ") # Building Session - REST s = requests.Session() s.url = "https://{}".format(node["ip"]) s.verify = False s.auth = (node["user"], node["password"]) s.headers = { "Content-Type": "application/hal+json", "Accept": "application/hal+json" } # Building Session - ZAPI session = NaServer(node["ip"], 1, 140) session.set_server_type("Filer") session.set_admin_user(node["user"], node["password"]) session.set_transport_type("HTTPS") # STEP: Create cluster if ("-01" in node["node-name"]): print("---> " + node["node-name"] + ": Creating cluster...") # create cluster API api = "/api/cluster" # creating body body = { "contact": cluster["contact"], "location": cluster["location"], "name": cluster["cluster-name"], "password": cluster["password"], "management_interface": {} } # add cluster mgmt for lif in cluster["net-interfaces"]: if (lif["role"] == "cluster-mgmt"): body["management_interface"]["ip"] = { "address": lif["address"], "netmask": lif["netmask"] } for route in cluster["net-routes"]: if (route["destination"] == "0.0.0.0/0"): body["management_interface"]["ip"][ "gateway"] = route["gateway"] break else: continue break else: continue # add ntp server #if (cluster.get("ntp-servers")): # for ntp_server in cluster["ntp-servers"]: # body["ntp_servers"].append(ntp_server["server-name"]) # add licenses #for ontap_license in cluster["licenses"]: # body["licenses"].append(cluster["licenses"][ontap_license]) response = s.post(url=s.url + api, data=json.dumps(body)) print("URL==" + s.url + api) #debug print("BODY==" + json.dumps(body)) #debug if response: print(response.json()) else: print("WE DIDNT GET RESPONSE") #sys.exit() status = handle_job(s, response) if (status == "success"): print("---> " + node["node-name"] + ": SUCCESS") else: print("---> " + node["node-name"] + ": " + status) sys.exit() # STEP: Reading cluster LIF IP for joining additional nodes later if ("-01" in node["node-name"]): print( "--- " + node["node-name"] + ": Reading cluster LIF IP for joining further nodes later...") api = NaElement("net-interface-modify") for lif in cluster["net-interfaces"]: if (lif["role"] == "cluster-mgmt"): api.child_add_string("home-port", lif["home-port"]) api.child_add_string("interface-name", "cluster_mgmt") api.child_add_string("vserver", cluster["cluster-name"]) else: continue xo = session.invoke_elem(api) if (xo.results_status() == "failed"): print("Error:\n") print(xo.sprintf()) sys.exit(1) print("Received:\n") print(xo.sprintf()) api1 = NaElement("net-interface-revert") api1.child_add_string("interface-name", "cluster_mgmt") api1.child_add_string("vserver", cluster["cluster-name"]) xo1 = session.invoke_elem(api1) if (xo1.results_status() == "failed"): print("Error:\n") print(xo1.sprintf()) sys.exit(1) print("Received:\n") print(xo1.sprintf()) api = "/api/network/ip/interfaces" url_params = "?fields=services,ip.address&services=cluster_core&max_records=1" response = s.get(url=s.url + api + url_params) status = handle_job(s, response) if (status == "success"): clus_lif_ip = response.json()["records"][0]["ip"]["address"] print("---> " + node["node-name"] + ": SUCCESS") else: print("---> " + node["node-name"] + ": " + status) sys.exit(1) # STEP: Join nodes to cluster if (not "-01" in node["node-name"]): print("--- " + node["node-name"] + ": Joining node to cluster...") zapi_post = NaElement("cluster-join") zapi_post.child_add_string("cluster-ip-address", clus_lif_ip) zapi_post_return = session.invoke_elem(zapi_post) if (zapi_post_return.results_status() == "failed"): print("---> " + node["node-name"] + ": " + zapi_post_return.sprintf().strip()) sys.exit(1) else: zapi_get = NaElement("cluster-create-join-progress-get") is_complete = "" join_iterator = 1 while is_complete != "true" and \ join_iterator < 13: time.sleep(10) zapi_get_return = session.invoke_elem(zapi_get) is_complete = zapi_get_return.child_get( "attributes").child_get( "cluster-create-join-progress-info" ).child_get_string("is-complete") action_status = zapi_get_return.child_get( "attributes").child_get( "cluster-create-join-progress-info" ).child_get_string("status") join_iterator = join_iterator + 1 if (is_complete == "true") and (action_status == "success"): print("---> " + node["node-name"] + ": SUCCESS") else: print("---> " + node["node-name"] + ": " + zapi_get.sprintf().strip()) print("---> " + node["node-name"] + ": " + zapi_get_return.sprintf().strip()) sys.exit(1)
def create(self, svm): api_call = NaElement('volume-create') api_call.child_add_string('volume', self.volume) api_call.child_add_string('containing-aggr-name', self.containing_aggr_name) api_call.child_add_string('size', self.size) api_call.child_add_string('volume-type', self.volume_type) api_call.child_add_string('volume-security-style', self.volume_security_style) api_call.child_add_string('snapshot-policy', self.snapshot_policy) api_call.child_add_string('percentage-snapshot-reserve', self.percentage_snapshot_reserve) api_call.child_add_string('efficiency-policy', self.efficiency_policy) output = svm.run_command(api_call) return output.results_status(), output.sprintf()
def create(self, cluster): api_call = NaElement('net-interface-create') api_child_data_protocols = NaElement('data-protocols') api_child_data_protocols.child_add_string('data-protocol', self.data_protocol) api_call.child_add(api_child_data_protocols) api_call.child_add_string('vserver', self.vserver) if (self.data_protocol == 'none') or (self.data_protocol == 'nfs') or ( self.data_protocol == 'cifs') or (self.data_protocol == 'iscsi'): api_call.child_add_string('interface-name', self.interface_name) api_call.child_add_string('role', self.role) api_call.child_add_string('home-node', self.home_node) api_call.child_add_string('home-port', self.home_port) api_call.child_add_string('address', self.address) api_call.child_add_string('netmask', self.netmask) elif (self.data_protocol == 'fcp'): api_call.child_add_string('interface-name', self.interface_name) api_call.child_add_string('role', self.role) api_call.child_add_string('home-node', self.home_node) api_call.child_add_string('home-port', self.home_port) output = cluster.run_command(api_call) return output.results_status(), output.sprintf()
def set_properties(self, cluster): api_call = NaElement('vserver-modify') api_call.child_add_string('vserver-name', self.vserver_name) api_child_aggrs = NaElement('aggr-list') for aggr in self.aggr_list: api_child_aggrs.child_add_string('aggr-name', aggr) api_child_protocols = NaElement('allowed-protocols') for protocol in self.allowed_protocols: api_child_protocols.child_add_string('protocol', protocol) api_call.child_add(api_child_aggrs) api_call.child_add(api_child_protocols) output = cluster.run_command(api_call) return output.results_status(), output.sprintf()
def execute(self, server, cmd_data_json): if ("name" not in cmd_data_json or "bc_domain" not in cmd_data_json or "ipspace" not in cmd_data_json or "subnet" not in cmd_data_json): return self._CREATE_FAIL_RESPONSE( "subnet create commands must" + " have name, broadcast domain, ipspace" + " and subnet defined, got: " + str(cmd_data_json)) name = cmd_data_json["name"] bcdom = cmd_data_json["bc_domain"] ipspace = cmd_data_json["ipspace"] subnet = cmd_data_json["subnet"] cmd = "net-subnet-create" call = NaElement(cmd) call.child_add_string("subnet-name", name) call.child_add_string("broadcast-domain", bcdom) call.child_add_string("ipspace", ipspace) call.child_add_string("subnet", subnet) # make sure that create call returns record! call.child_add_string("return-record", True) if "gateway" in cmd_data_json: call.child_add_string("gateway", cmd_data_json["gateway"]) if "ip_ranges" in cmd_data_json: iprs = NaElement("ip-ranges") for ip_range in cmd_data_json["ip_ranges"]: iprs.child_add_string("ip-range", ip_range) call.child_add(iprs) resp, err_resp = self._INVOKE_CHECK(server, call, cmd + ": " + name) if err_resp: return err_resp # LOGGER.debug(resp.sprintf()) if not resp.child_get("result"): # no result data in response return self._CREATE_FAIL_RESPONSE( 'no result data for create subnet' + ' with input: [' + str(cmd_data_json) + '] result is: ' + resp.sprintf()) si_info = resp.child_get("result").child_get("net-subnet-info") dd = { "bc_domain": self._GET_STRING(si_info, "broadcast-domain"), "gateway": self._GET_STRING(si_info, "gateway"), "ipspace": self._GET_STRING(si_info, "ipspace"), "subnet": self._GET_STRING(si_info, "subnet"), "name": self._GET_STRING(si_info, "subnet-name"), "ip_count": self._GET_INT(si_info, "total-count"), "ip_used": self._GET_INT(si_info, "used-count"), "ip_avail": self._GET_INT(si_info, "available-count"), "ip_ranges": self._GET_CONTENT_LIST(si_info, "ip-ranges") } return {'success': True, 'errmsg': '', 'data': dd}