def main(): from optparse import OptionParser parser = OptionParser(usage=usage()) parser.add_option( "", "--dryrun", dest="debug", action="store_true", default=False, help="only issues 'Get*' calls to the API. Commits nothing.") parser.add_option("", "--verbose", dest="verbose", action="store_true", default=False, help="print all the PLC API calls being made.") parser.add_option("", "--url", dest="url", default=session.API_URL, help="PLC url to contact") parser.add_option("", "--plcconfig", dest="plcconfig", default=session.PLC_CONFIG, help="path to file containing plc login information.") parser.add_option("", "--on", metavar="hostname", dest="ondest", default=None, help="only act on the given hostname (or sitename)") parser.add_option( "", "--syncsite", metavar="site", dest="syncsite", default=None, help="sync the given site, nodes, and pcus. Can be 'all'") parser.add_option( "", "--syncslice", metavar="slice", dest="syncslice", default=None, help="sync the given slice and its attributes. Can be 'all'") parser.add_option( "-A", "--allsteps", dest="allsteps", action="store_true", default=False, help="perform all the following 'add' steps (in context)") parser.add_option("", "--addnodes", dest="addnodes", action="store_true", default=False, help=("[syncsite] create nodes during site sync")) parser.add_option( "", "--addinterfaces", dest="addinterfaces", action="store_true", default=False, help=("[syncsite] create/update ipv4 Interfaces. Omitting " + "this option only syncs ipv6 configuration (which is " + "treated differently in the DB)")) parser.add_option("", "--addusers", dest="addusers", action="store_true", default=False, help=("[syncsite] add PIs to sites")) parser.add_option( "", "--createusers", action="store_true", dest="createusers", default=False, help=("normally, users are assumed to exist. This option " + "creates them first and gives them a default password. " + "Useful for testing. Users are not assigned to slices.")) parser.add_option("", "--addwhitelist", dest="addwhitelist", action="store_true", default=False, help=("[syncslice] add the given slice to whitelists.")) parser.add_option("", "--addsliceips", dest="addsliceips", default=False, action="store_true", help="[syncslice] assign IPs (v4 and/or v6) to slices") parser.add_option( "", "--createslice", action="store_true", dest="createslice", default=False, help=("normally, slices are assumed to exist. This option " + "creates them first. Useful for testing. Users are not " + "assigned to new slices.")) parser.add_option( "", "--getbootimages", dest="getbootimages", action="store_true", default=False, help=("download the ISO boot images for nodes. Without the " "--node-key-keep flag, this is a destructive operation.")) parser.add_option( "", "--node-key-keep", dest="nodekeykeep", action="store_true", default=False, help=("When downloading an ISO boot image, preserve the node " "key generated by previous downloads. This flag enables " "an operator to generate multiple ISOs for hardware " "updates without breaking the current deployment.")) parser.add_option("", "--sitesname", metavar="sites", dest="sitesname", default="sites", help="the name of the module with Site() definitions") parser.add_option("", "--slicesname", metavar="slices", dest="slicesname", default="slices", help="the name of the module with Slice() definitions") parser.add_option("", "--sitelist", metavar="site_list", dest="sitelist", default="site_list", help="the site list variable name.") parser.add_option("", "--slicelist", metavar="slice_list", dest="slicelist", default="slice_list", help="the slice list variable name.") (options, _) = parser.parse_args() if len(sys.argv) == 1: parser.print_help() sys.exit(1) # NOTE: if allsteps is given, set all steps to True if options.allsteps: options.addwhitelist = True options.addsliceips = True options.addinterfaces = True options.addnodes = True options.addusers = True site_list = getattr(__import__(options.sitesname), options.sitelist) slice_list = getattr(__import__(options.slicesname), options.slicelist) print "setup plc session" session.setup_global_session(options.url, options.debug, options.verbose, options.plcconfig) # always setup the configuration for everything (very fast) print "loading slice & site configuration" for sslice in slice_list: for site in site_list: for host in site['nodes']: h = site['nodes'][host] sslice.add_node_address(h) # begin processing arguments to apply filters, etc if options.syncsite is not None and options.syncslice is None: print "sync site" for site in site_list: # sync everything when syncsite is None, # or only when it matches if (options.syncsite == "all" or options.syncsite == site['name']): print "Syncing: site", site['name'] sync.SyncSite(site, options.ondest, options.addusers, options.addnodes, options.addinterfaces, options.getbootimages, options.createusers, options.nodekeykeep) elif options.syncslice is not None and options.syncsite is None: print options.syncslice for sslice in slice_list: if (options.syncslice == "all" or options.syncslice == sslice['name']): print "Syncing: slice", sslice['name'] sync.SyncSlice(sslice, options.ondest, options.addwhitelist, options.addsliceips, options.addusers, options.createslice) else: print usage() sys.exit(1)
def main(): from optparse import OptionParser parser = OptionParser(usage=usage()) parser.set_defaults(syncsite=None, syncslice=None, ondest=None, skipwhitelist=False, skipsliceips=False, skipinterfaces=False, url=session.API_URL, debug=False, verbose=False, ) parser.add_option("", "--dryrun", dest="debug", action="store_true", help=("Only issues 'Get*' calls to the API. "+ "Commits nothing to the API")) parser.add_option("", "--verbose", dest="verbose", action="store_true", help="Print all the PLC API calls being made.") parser.add_option("", "--url", dest="url", help="PLC url to contact") parser.add_option("", "--on", metavar="hostname", dest="ondest", help="only act on the given host") parser.add_option("", "--syncsite", metavar="site", dest="syncsite", help="only sync sites, nodes, pcus, if needed. (saves time)") parser.add_option("", "--syncslice", metavar="slice", dest="syncslice", help="only sync slices and attributes of slices. (saves time)") parser.add_option("", "--skipwhitelist", dest="skipwhitelist", action="store_true", help=("dont try to white list the given slice. (saves time)")) parser.add_option("", "--skipsliceips", dest="skipsliceips", action="store_true", help="dont try to assign ips to slice. (saves time)") parser.add_option("", "--skipinterfaces", dest="skipinterfaces", action="store_true", help=("dont try to create new Interfaces or update existing "+ "Interfaces. This permits IPv6 maniuplation without "+ "changing legacy IPv4 configuration in DB.") ) (options, args) = parser.parse_args() if len(sys.argv) == 1: usage() parser.print_help() sys.exit(1) print "setup plc session" session.setup_global_session(options.url, options.debug, options.verbose) # always setup the configuration for everything (very fast) print "loading slice & site configuration" for sslice in slice_list: for site in site_list: for host in site['nodes']: h = site['nodes'][host] sslice.add_node_address(h) # begin processing arguments to apply filters, etc if ( options.syncsite is not None or options.syncslice is not None ): if options.syncsite is not None and options.syncslice is None: print "sync site" for site in site_list: # sync everything when syncsite is None, # or only when it matches if (options.syncsite == "all" or options.syncsite == site['name']): print "Syncing: site", site['name'] site.sync(options.ondest, options.skipinterfaces) if options.syncslice and options.syncsite is None: print options.syncslice for sslice in slice_list: if (options.syncslice == "all" or options.syncslice == sslice['name']): print "Syncing: slice", sslice['name'] sslice.sync(options.ondest, options.skipwhitelist, options.skipsliceips) if options.syncslice and options.syncsite: print "sync slices & site" if options.syncslice == "all": site = filter(lambda x: x['name'] == options.syncsite, site_list) #site.sync(options.ondest, options.skipinterfaces) for sslice in slice_list: sslice.sync(options.ondest, options.skipwhitelist, options.skipsliceips)
def main(): from optparse import OptionParser parser = OptionParser(usage=usage()) parser.add_option("", "--dryrun", dest="debug", action="store_true", default=False, help="only issues 'Get*' calls to the API. Commits nothing.") parser.add_option("", "--verbose", dest="verbose", action="store_true", default=False, help="print all the PLC API calls being made.") parser.add_option("", "--url", dest="url", default=session.API_URL, help="PLC url to contact") parser.add_option("", "--plcconfig", dest="plcconfig", default=session.PLC_CONFIG, help="path to file containing plc login information.") parser.add_option("", "--on", metavar="hostname", dest="ondest", default=None, help="only act on the given hostname (or sitename)") parser.add_option("", "--syncsite", metavar="site", dest="syncsite", default=None, help="sync the given site, nodes, and pcus. Can be 'all'") parser.add_option("", "--syncslice", metavar="slice", dest="syncslice", default=None, help="sync the given slice and its attributes. Can be 'all'") parser.add_option("-A", "--allsteps", dest="allsteps", action="store_true", default=False, help="perform all the following 'add' steps (in context)") parser.add_option("", "--addnodes", dest="addnodes", action="store_true", default=False, help=("[syncsite] create nodes during site sync")) parser.add_option("", "--addinterfaces", dest="addinterfaces", action="store_true", default=False, help=("[syncsite] create/update ipv4 Interfaces. Omitting "+ "this option only syncs ipv6 configuration (which is "+ "treated differently in the DB)") ) parser.add_option("", "--addusers", dest="addusers", action="store_true", default=False, help=("[syncsite] add PIs to sites")) parser.add_option("", "--createusers", action="store_true", dest="createusers", default=False, help=("normally, users are assumed to exist. This option "+ "creates them first and gives them a default password. "+ "Useful for testing. Users are not assigned to slices.")) parser.add_option("", "--addwhitelist", dest="addwhitelist", action="store_true", default=False, help=("[syncslice] add the given slice to whitelists.")) parser.add_option("", "--addsliceips", dest="addsliceips", default=False, action="store_true", help="[syncslice] assign IPs (v4 and/or v6) to slices") parser.add_option("", "--createslice", action="store_true", dest="createslice", default=False, help=("normally, slices are assumed to exist. This option "+ "creates them first. Useful for testing. Users are not "+ "assigned to new slices.")) parser.add_option("", "--getbootimages", dest="getbootimages", action="store_true", default=False, help=("download the ISO boot images for nodes. Without the " "--node-key-keep flag, this is a destructive operation.")) parser.add_option("", "--node-key-keep", dest="nodekeykeep", action="store_true", default=False, help=("When downloading an ISO boot image, preserve the node " "key generated by previous downloads. This flag enables " "an operator to generate multiple ISOs for hardware " "updates without breaking the current deployment.")) parser.add_option("", "--sitesname", metavar="sites", dest="sitesname", default="sites", help="the name of the module with Site() definitions") parser.add_option("", "--slicesname", metavar="slices", dest="slicesname", default="slices", help="the name of the module with Slice() definitions") parser.add_option("", "--sitelist", metavar="site_list", dest="sitelist", default="site_list", help="the site list variable name.") parser.add_option("", "--slicelist", metavar="slice_list", dest="slicelist", default="slice_list", help="the slice list variable name.") (options, _) = parser.parse_args() if len(sys.argv) == 1: parser.print_help() sys.exit(1) # NOTE: if allsteps is given, set all steps to True if options.allsteps: options.addwhitelist=True options.addsliceips=True options.addinterfaces=True options.addnodes=True options.addusers=True site_list = getattr(__import__(options.sitesname), options.sitelist) slice_list = getattr(__import__(options.slicesname), options.slicelist) print "setup plc session" session.setup_global_session(options.url, options.debug, options.verbose, options.plcconfig) # always setup the configuration for everything (very fast) print "loading slice & site configuration" for sslice in slice_list: for site in site_list: for host in site['nodes']: h = site['nodes'][host] sslice.add_node_address(h) # begin processing arguments to apply filters, etc if options.syncsite is not None and options.syncslice is None: print "sync site" for site in site_list: # sync everything when syncsite is None, # or only when it matches if (options.syncsite == "all" or options.syncsite == site['name']): print "Syncing: site", site['name'] sync.SyncSite(site, options.ondest, options.addusers, options.addnodes, options.addinterfaces, options.getbootimages, options.createusers, options.nodekeykeep) elif options.syncslice is not None and options.syncsite is None: print options.syncslice for sslice in slice_list: if (options.syncslice == "all" or options.syncslice == sslice['name']): print "Syncing: slice", sslice['name'] sync.SyncSlice(sslice, options.ondest, options.addwhitelist, options.addsliceips, options.addusers, options.createslice) else: print usage() sys.exit(1)
def main(): from optparse import OptionParser parser = OptionParser(usage=usage()) parser.set_defaults(syncsite=None, syncslice=None, ondest=None, skipwhitelist=False, sitesname="sites", slicesname="slices", sitelist="site_list", slicelist="slice_list", skipsliceips=False, skipinterfaces=False, createslice=False, getbootimages=False, url=session.API_URL, debug=False, verbose=False, ) parser.add_option("", "--dryrun", dest="debug", action="store_true", help=("Only issues 'Get*' calls to the API. "+ "Commits nothing to the API")) parser.add_option("", "--verbose", dest="verbose", action="store_true", help="Print all the PLC API calls being made.") parser.add_option("", "--url", dest="url", help="PLC url to contact") parser.add_option("", "--on", metavar="hostname", dest="ondest", help="only act on the given host") parser.add_option("", "--syncsite", metavar="site", dest="syncsite", help="only sync sites, nodes, pcus, if needed. (saves time)") parser.add_option("", "--syncslice", metavar="slice", dest="syncslice", help="only sync slices and attributes of slices. (saves time)") parser.add_option("", "--skipwhitelist", dest="skipwhitelist", action="store_true", help=("dont try to white list the given slice. (saves time)")) parser.add_option("", "--skipsliceips", dest="skipsliceips", action="store_true", help="dont try to assign ips to slice. (saves time)") parser.add_option("", "--skipinterfaces", dest="skipinterfaces", action="store_true", help=("dont try to create new Interfaces or update existing "+ "Interfaces. This permits IPv6 maniuplation without "+ "changing legacy IPv4 configuration in DB.") ) parser.add_option("", "--createslice", action="store_true", dest="createslice", help=("Normally, slices are assumed to exist. This option "+ "creates them first. Useful for testing.")) parser.add_option("", "--getbootimages", dest="getbootimages", action="store_true", help=("Download the ISO boot images for Nodes. This is a"+ " destructive operation if ISOs have previously been "+ "downloaded.")) parser.add_option("", "--sitesname", metavar="sites", dest="sitesname", help="The name of the module with Site() definitions") parser.add_option("", "--slicesname", metavar="slices", dest="slicesname", help="The name of the module with Slice() definitions") parser.add_option("", "--sitelist", metavar="site_list", dest="sitelist", help="The site list variable name.") parser.add_option("", "--slicelist", metavar="slice_list", dest="slicelist", help="The slice list variable name.") (options, args) = parser.parse_args() if len(sys.argv) == 1: parser.print_help() sys.exit(1) site_list = getattr(__import__(options.sitesname), options.sitelist) slice_list = getattr(__import__(options.slicesname), options.slicelist) print "setup plc session" session.setup_global_session(options.url, options.debug, options.verbose) # always setup the configuration for everything (very fast) print "loading slice & site configuration" for sslice in slice_list: for site in site_list: for host in site['nodes']: h = site['nodes'][host] sslice.add_node_address(h) # begin processing arguments to apply filters, etc if options.syncsite is not None and options.syncslice is None: print "sync site" for site in site_list: # sync everything when syncsite is None, # or only when it matches if (options.syncsite == "all" or options.syncsite == site['name']): print "Syncing: site", site['name'] site.sync(options.ondest, options.skipinterfaces, options.getbootimages) elif options.syncslice is not None and options.syncsite is None: print options.syncslice for sslice in slice_list: if (options.syncslice == "all" or options.syncslice == sslice['name']): print "Syncing: slice", sslice['name'] sslice.sync(options.ondest, options.skipwhitelist, options.skipsliceips, options.createslice) else: print usage() sys.exit(1)