def bulk_deploy_networks_for_all_orgs(agent): org_group = settings["CLI"]["networks-org"] store_list = settings["CLI"]["networks-store-list"] serials_list = settings.get("CLI").get("networks-serials") l.runlogs_logger.info("deploy networks <starting>") org_list = json.reader(org_group, "templates") orglist = json.make_pretty(org_list) l.logger.info("org list: {}".format(orglist)) l.logger.info("store list: {}".format(store_list)) l.logger.info("serials list: {}".format(serials_list)) for org in org_list: org_name = org["org_name"] auto_globals.select_org(org_name) l.runlogs_logger.info("selected org: {}".format(org_name)) l.runlogs_logger.info("using clone source: {}".format(settings["CLI"]["networks-clone-source"])) l.runlogs_logger.info("using serials : {}".format(settings.get("CLI").get("networks-serials"))) # Now get the netid for the clone_source store_name = settings["CLI"]["networks-clone-source"] auto_globals.select_store(store_name) auto_globals.load_store(agent, store_name) config.set_clone_id(settings["netid"]) bulk.perform_bulk_deploy_networks(agent, deploy, deploy_serials, store_list) l.runlogs_logger.info("deploy networks <finished>")
def list(self, org_id): success = False networks = None try: success, networks = meraki.getnetworklist(config.api_key, org_id) if success: log.logger.debug("success") log.logger.debug(Json.make_pretty(networks)) else: log.logger.error("failed.") log.logger.error("networks: {}".format(networks)) gv.fake_assert() except (meraki.EmailFormatError, meraki.OrgPermissionError, meraki.ListError) as err: log.logger.error("orgid: {} Meraki error: {}".format( org_id, err.default)) log.runlogs_logger.error("orgid: {} Meraki error: {}".format( org_id, err.default)) exit(-1) except Exception as err: log.logger.error("orgid: {}".format(org_id)) log.runlogs_logger.error("orgid: {}".format(org_id)) gv.fake_assert() return success, networks
def test(): _orchestration_agent = "cli-test" org_name = "AutomationTestOrg_DONOTDELETE" load_org(_orchestration_agent, org_name) load_store("agent-secret", "8501") netx = get("cc8501") str = mkjson.make_pretty((netx)) print(str)
def getdetail(self, networkid): success = False self.network = None try: success, self.network = meraki.getnetworkdetail( key.apikey, networkid) l.logger.debug(json.make_pretty(self.network)) except Exception as err: l.logger.error("orgid: {}".format(networkid)) traceback.print_tb(err.__traceback__) return success, self.network
def get(self, netid): self.vlans = None try: success, self.vlans = meraki.getvlans(config.apikey, netid) if not success: l.logger.error("failed netid:{} {}".format(netid, self.vlans)) fname = "vlans_{}".format(netid) json.writer(fname, self.vlans) l.logger.info("netid:{} {}".format(netid, json.make_pretty(self.vlans))) except Exception as err: l.logger.error("exception failure netid:{}".format(netid)) traceback.print_tb(err.__traceback__)
def update(self, networkid, name): success = False self.network = None try: success, self.network = meraki.updatenetwork(config.apikey, networkid, name, tz="US/Pacific", tags=None) l.logger.debug(json.make_pretty(self.network)) except Exception as err: l.logger.error("orgid: {}".format(networkid)) traceback.print_tb(err.__traceback__) return success, self.network
def convert_master_template_to_jinja(): from utils.auto_json import reader, make_pretty from copy import deepcopy master_tpl = reader("vlan_template_master_final", configDir="config") # str = make_pretty(master_tpl) # print(str) jinja_tpl = [] item = {} for vlan in master_tpl: id = vlan["Vlan"] item["id"] = id item["networkId"] = "{{networkid}}" item["name"] = vlan["Description"] subnet = vlan["Subnet"] last_cctect = subnet.split(".") last_octect = last_cctect[3] last_octect = last_cctect[3].split("/") last_octect = int(last_octect[0]) str = "{{vlan[{}]['subnet']}}.{}".format(id, last_octect + 1) item["applianceIp"] = str subnet = vlan["Subnet"] str = "{{vlan[{}]['subnet']}}".format(id) item["subnet"] = str item["dnsNameservers"] = vlan["dnsNameservers"] item["fixedIpAssignments"] = {} item["reservedIpRanges"] = [] if vlan["reservedIpRanges1-start"] is not "": it = {} it["comment"] = vlan["reservedIpRanges1-comment"] it["end"] = vlan["reservedIpRanges1-end"] it["start"] = vlan["reservedIpRanges1-start"] item["reservedIpRanges"].append(deepcopy(it)) if vlan["reservedIpRanges2-start"] is not "": it = {} it["comment"] = vlan["reservedIpRanges2-comment"] it["end"] = vlan["reservedIpRanges2-end"] it["start"] = vlan["reservedIpRanges2-start"] item["reservedIpRanges"].append(deepcopy(it)) jinja_tpl.append(deepcopy(item)) str = make_pretty(jinja_tpl) print(str)
def list(self, orgid): success = False self.networks = None try: success, self.networks = meraki.getnetworklist( config.apikey, orgid) if success: l.logger.debug("success") l.logger.debug(json.make_pretty(self.networks)) else: l.logger.error("failed.") l.logger.error("vlan: {}".format(vl)) except Exception as err: l.logger.error("orgid: {}".format(orgid)) traceback.print_tb(err.__traceback__) return success, self.networks
def getdetail(self, networkid): success = False self.network = None try: success, self.network = meraki.getnetworkdetail( config.api_key, networkid) log.logger.debug(Json.make_pretty(self.network)) if not success: log.logger.error("failed: {}".format(self.network)) log.runlogs_logger.error("failed: {}".format(self.network)) gv.fake_assert() except Exception as err: logger.error("exception failure networkid: {} {}".format( networkid, self.network)) runlogs_logger.error("exception failure {}".format(self.network)) gv.fake_assert() return success, self.network
def update_settings_single(self, org_id, vpn_rules=[]): api_key = config.api_key success = False str = None try: single_rule = [] count = 1100 start = count for rule in vpn_rules[start:]: l.runlogs_logger.info( "deploying rule number: {} ==> rule: {}".format( count, str)) single_rule.append(rule) success, str = meraki.updatemxvpnfwrules( api_key, org_id, single_rule, syslogDefaultRule=False, suppressprint=False) single_rule.pop() count += 1 str = Json.make_pretty(rule) l.logger.info( "deployed org-id {} count {} rule number {}".format( org_id, count, str)) l.runlogs_logger.info( "deployed org-di {} rule number {}".format(org_id, count)) Json.writer("s2svpnrules_deploy", single_rule) if not success: l.logger.error("failed count {} {}".format(count, str)) l.runlogs_logger.error("failed count {} {}".format( count, str)) l.runlogs_logger.error("{}".format(str)) gv.fake_assert() except Exception as err: l.runlogs_logger.error("org_id: {} str:{}".format(org_id, str)) l.logger.error("org_id: {} str:{}".format(org_id, str)) gv.fake_assert() return success, str
def update(self, networkid, name): success = False self.network = None try: success, str = meraki.updatenetwork(config.api_key, networkid, name, tz="US/Pacific", tags=None) self.network = str logger.debug(Json.make_pretty(self.network)) if not success: logger.error("{}".format(str)) runlogs_logger.error("{}".format(str)) gv.fake_assert() except Exception as err: logger.error("exception failure netid: {} name: {}".format( networkid, name)) runlogs_logger.error("exception failure name: {}".format(name)) gv.fake_assert() return success, self.network
def get_vlans(self, netid): self.vlans = None try: success, self.vlans = meraki.getvlans(config.api_key, netid) if not success: l.logger.error("failed netid:{} {}".format(netid, self.vlans)) l.runlogs_logger.error("failed {}".format(self.vlans)) gv.fake_assert() fname = "vlans_{}".format(netid) #json.writer(fname, self.vlans) l.logger.info("netid:{} {}".format(netid, json.make_pretty(self.vlans))) except (meraki.EmailFormatError, meraki.OrgPermissionError, meraki.ListError) as err: l.logger.error("Meraki error: {}".format(err.default)) l.runlogs_logger.error("Meraki error: {}".format(err.default)) exit(-1) except Exception as err: l.logger.error("exception failure netid:{}".format( netid, self.vlans)) l.runlogs_logger.error("exception failure \n{}".format(self.vlans)) gv.fake_assert()
l.logger.debug(str) pickNet = "CC = %s.5" % netX[_netx] l.logger.debug("netX created.") return netX, pickNet def _get(netx=None, name=None, addr=None): obj = NetX() obj.getAll(_netx, name, addr) def get(name): obj = NetX() netx, picknet = obj.getAll(None, name, None) return netx, picknet import utils.auto_json as mkjson import utils.auto_logger as l if __name__ == '__main__': cwd = os.getcwd() _netx = None _name = None _addr = None netx, picknet = get("mx9845a") str = mkjson.make_pretty((netx)) l.logger.debug(str) #netXPicks = _get(netx=None, name=None, addr="151.101.193.67")