예제 #1
0
def perform_bulk_delete_vlans(agent,
                              org_name,
                              fname,
                              fn_deploy,
                              vlans_only=False):
    store_list = Json.reader(fname, "templates")

    if not goahead_confirm("stores"):
        return

    for store in store_list:
        store_name = store.get("name", None)
        l.runlogs_logger.info("deploying network: {}".format(store_name))
        if store_name is None:
            str = "fname: {} ::: store_name field was not found for store {}".format(
                fname, store)
            l.logger.error(str)
            l.runlogs_logger.error(str)
            gv.fake_assert()
        l.logger.info("deploying store : {}".format(store_name))
        auto_globals.select_store(store_name)
        if (auto_globals.load_store(agent, store_name)) is False:
            l.logger.error("failed deploying network: {}".format(store_name))
            l.runlogs_logger.error(
                "failed deploying network: {}".format(store_name))
            return

        fn_deploy(agent, vlans_only)
        l.logger.info("deployed store : {}".format(store_name))
        Json.writer(fname, store_list, "templates")
        Csv.transform_to_csv(fname, None, path="templates")
        l.runlogs_logger.info("deployed network: {}  netid: {}".format(
            store_name, settings["netid"]))
예제 #2
0
def perform_bulk_get_vpn_firewall(agent, org_list_fname, fn_get):
    l.runlogs_logger.info("downloading {}".format(agent))
    org_list = Json.reader(org_list_fname, "templates")
    Csv.transform_to_csv(org_list_fname, None, path="templates")

    org_name = org_list[0].get("org_name", None)
    auto_globals.load_org(agent, org_name)

    if org_name is None:
        str = "org {} not found".format(org_name)
        l.logger.error(str)
        l.runlogs_logger.error(str)
        gv.fake_assert()
    try:
        str = "downloading vpns2srules for org: {}".format(org_name)
        l.logger.info(str)
        l.runlogs_logger.info(str)
        fn_get(agent)
    except:
        str = "failed obtaining s2svpnrules for org: {}".format(org_name)
        l.logger.error(str)
        l.runlogs_logger.info(str)
        gv.fake_assert()
    str = 'downloaded s2svpnrules for org : "{}"'.format(org_name)
    l.logger.info(str)
    l.runlogs_logger.info(str)
예제 #3
0
 def create_output(self, template, fname, context):
     data = self.render_template(template, context)
     if data is None:
         l.logger.error("failed")
         return
     csv_json.Json().writer(fname, data)
     header = [
         "id", "networkId", "name", "applianceIp", "subnet",
         "dnsNameservers", "fixedIpAssignments", "reservedIpRanges"
     ]
     csv_json.transform_to_csv(fname, header)
     # csv_json.transform_to_json(fname)
     l.logger.debug(fname)
예제 #4
0
def perform_bulk_update_vpn_firewall(agent, fname, fn_deploy, rules=None):
    l.runlogs_logger.info("deploying {}".format(agent))
    org_list = Json.reader(fname, "templates")
    Csv.transform_to_csv(fname, None, path="templates")
    org_name = org_list[0].get("org_name", None)
    settings["org-name"] = org_name
    auto_globals.load_org(agent, org_name)
    str = "selected org: {}".format(org_name)
    l.logger.info(str)
    l.runlogs_logger.info(str)

    vpn_rules = settings["CLI"]["s2svpnrules-version"]
    str = "vpns2srules version: {}".format(vpn_rules)
    l.logger.info(str)
    l.runlogs_logger.info(str)

    if not goahead_confirm("s2svpnrules"):
        return

    if org_name is None:
        l.logger.error(
            "failed deploying s2svpnrules to org: {}".format(org_name))
        l.runlogs_logger.error(
            "failed deploying s2svpnrules to org: {}".format(org_name))
        gv.fake_assert()
    try:
        l.logger.info("deploying vpns2srules to org: {}".format(
            vpn_rules, org_name))
        l.runlogs_logger.info(
            "deploying vpns2srules to org: {}".format(org_name))
        fn_deploy(agent, rules)
    except:
        str = "failed deploying s2svpnrules {} to org: {}".format(
            rules, org_name)
        l.logger.error(str)
        l.runlogs_logger.info(str)
        gv.fake_assert()
    str = 'deployed s2svpnrules: "{}" to org: "{}"'.format(rules, org_name)
    l.logger.info(str)
    l.runlogs_logger.info(str)
예제 #5
0
def perform_bulk_update_firewall(agent, fn_deploy, fw_rules, store_list):
    fname = store_list
    store_list = Json.reader(fname, "templates")
    """Ensure that the list now has always all the three fields
    in short that it is normalized so csv conversion is not upset"""
    Json.writer(fname, store_list, "templates")
    Csv.transform_to_csv(fname, None, path="templates")

    show_store_list(store_list)

    if not goahead_confirm("l3fwrules"):
        return

    for store in store_list:
        store_name = store.get("name", None)

        if store_name is None:
            str = "fname: {} ::: name field was not found for store {}".format(
                fname, store)
            l.runlogs_logger.error(str)
            l.logger.error(str)
            gv.fake_assert()
        auto_globals.select_store(store_name)
        try:
            assert (auto_globals.load_store(agent, store_name))
            str = ('deploying l3fwrules to {}'.format(store_name))
            l.runlogs_logger.info(str)
            fn_deploy(agent, fw_rules)
            str = ('deployed l3fwrules to {}'.format(store_name))
            l.logger.info(str)
            l.runlogs_logger.info(str)
        except:
            str = "failed deployment for store : {}".format(store_name)
            l.logger.error(str)
            l.runlogs_logger.error(str)
            gv.fake_assert()
예제 #6
0
    def __init__(self, _fw_rules=None):
        self.vlanFunnelTable = vlan_handler.createVlanTable()
        fname = _fw_rules
        self.firewallOutputFile = "l3fwrules_deploy_{}".format(settings["store-number"])
        self.firewallOutputFileNetx = "l3fwrules_netx"

        #self.header_netx_csv = ["policy", "protocol", "srcCidr", "srcPort", "destCidr", "destPort", "comment", "syslogEnabled"]
        self.header_netx_csv =  ["comment", "policy", "protocol", "srcPort", "srcCidr", "destPort", "destCidr", "syslogEnabled"]


        self.fwRules = json.reader(fname, "templates")
        self.funnelNetx = json.reader("vlans-funnel_netx")
        assert(self.funnelNetx)

        # Transform template to csv for external use
        Csv.transform_to_csv(fname, header=self.header_netx_csv, path="templates")

        # Transform template to  format for external use
        self.transform_rules_from_vlan_to_netx()


        if self.fwRules  is None:
            l.logger.error("unable to load rules from firewall_template : {}". format(fname))
        l.logger.info("using firewall golden rule : {}".format(fname))
예제 #7
0
def writer(fname, data, path="data", header=None, logPath=False):
    if data is None:
        return
    Json.writer(fname, data, path=path, absolute_path=None, logPath=logPath)
    transform_to_csv(fname, path=path, header=header)
예제 #8
0
def writer(fname, data, path="data", header=None):
    if data is None:
        return
    Json.writer(fname, data, path=path)
    transform_to_csv(fname, path=path, header=header)