def __init__(self, username, password): self.username = username self.password = password self.backend_api = tomato.getConnection(tomato.createUrl("http+xmlrpc", "localhost", 8000, self.username, self.password)) for module in TOMATO_MODULES: if module != TOMATO_BACKEND_API_MODULE: setattr(self, module, InternalAPIProxy(self.backend_api, module))
def run(): """ Parses the command-line arguments, opens an API connection and creates access to the available commands of the host. It decides based on the options whether to directly execute python code or to execute a file or to grant access to the interactive cli. """ options = parseArgs() url = options.url if options.url else createUrl(options.protocol, options.hostname, options.port, options.username, options.password) api = getConnection(url, options.client_cert) locals = getLocals(api) def _upload_and_use_rextfv(*args, **kwargs): return upload_and_use_rextfv(api, *args, **kwargs) locals["upload_and_use_rextfv"] = _upload_and_use_rextfv def _upload_and_use_image(*args, **kwargs): return upload_and_use_image(api, *args, **kwargs) locals["upload_and_use_image"] = _upload_and_use_image def _download_rextfv(*args, **kwargs): return download_rextfv(api, *args, **kwargs) locals["download_rextfv"] = _download_rextfv def _download_image(*args, **kwargs): return download_image(api, *args, **kwargs) locals["download_image"] = _download_image if options.arguments: runSource(locals, "\n".join(options.arguments)) elif options.file: runFile(locals, options.file, options) else: runInteractive(locals)
def run(): """ Parses the command-line arguments, opens an API connection and creates access to the available commands of the host. It decides based on the options whether to directly execute python code or to execute a file or to grant access to the interactive cli. """ options = parseArgs() url = options.url if options.url else createUrl( options.protocol, options.hostname, options.port, options.username, options.password) api = getConnection(url, options.client_cert) locals = getLocals(api) locals[ "upload_and_use_rextfv"] = lambda element_id, filename: upload_and_use_rextfv( api, element_id, filename) locals[ "upload_and_use_image"] = lambda element_id, filename: upload_and_use_image( api, element_id, filename) locals["download_rextfv"] = lambda element_id, filename: download_rextfv( api, element_id, filename) locals["download_image"] = lambda element_id, filename: download_image( api, element_id, filename) if options.arguments: runSource(locals, "\n".join(options.arguments)) elif options.file: runFile(locals, options.file, options) else: runInteractive(locals)
def __init__(self, username, password): self.username = username self.password = password self.backend_api = tomato.getConnection( tomato.createUrl("http+xmlrpc", "localhost", 8000, self.username, self.password)) for module in TOMATO_MODULES: if module != TOMATO_BACKEND_API_MODULE: setattr(self, module, InternalAPIProxy(self.backend_api, module))
def run(): """ Parses the command-line arguments, opens an API connection and creates access to the available commands of the host. It decides based on the options whether to directly execute python code or to execute a file or to grant access to the interactive cli. """ options = parseArgs() url = options.url if options.url else createUrl(options.protocol, options.hostname, options.port, options.username, options.password) api = getConnection(url, options.client_cert) locals = getLocals(api) if options.arguments: runSource(locals, "\n".join(options.arguments)) elif options.file: runFile(locals, options.file, options) else: runInteractive(locals)
subprocess.call(["./tomato-ctl.py", "gencerts"]) time.sleep(5) print "" # start tomato print "Starting ToMaTo..." subprocess.call(["./tomato-ctl.py", "start"]) time.sleep(10) # give tomato some time to open ports print "" # insert site and hosts print "Adding site and hosts..." backend_url = tomato.createUrl("http+xmlrpc", "localhost", 8000, "admin", "changeme") conn = tomato.getConnection(backend_url) conn.site_create(config['site']['name'], 'others', config['site']['label'], {'location': config['site']['location'], 'geolocation': config['site']['geolocation']} ) for host in config['hosts']: subprocess.call(["../../cli/register_backend_on_host.sh", backend_url, host["address"], "local"]) try: conn.host_create(host['name'], config['site']['name'], {'address': host['address'], 'rpcurl': host['rpcurl']})
print " [%s]" % " ".join(cmd) subprocess.call(cmd) print "" # start tomato print "Starting ToMaTo..." subprocess.call(["./tomato-ctl.py", "start"]) time.sleep(5) # give tomato some time to open ports print "" # insert site and hosts print "Adding site and hosts..." conn = tomato.getConnection(tomato.createUrl("http+xmlrpc", "localhost", 8000, "admin", "changeme")) conn.site_create(config['site']['name'], 'others', config['site']['label'], {'location': config['site']['location'], 'geolocation': config['site']['geolocation']} ) for host in config['hosts']: try: conn.host_create(host['name'], config['site']['name'], {'address': host['address'], 'rpcurl': host['rpcurl']}) except: print "error inserting %s" % host['name']
if version[0] == 3: return _insert_template_3_0_0(api, template, overwrite_on_conflict) elif version[0] == 4: return _insert_template_4_0_0(api, template, overwrite_on_conflict) options = parseArgs() print "" print "testing connection to source backend..." try: if options.url_source: url_source = options.url_source else: url_source = createUrl(options.protocol_source, options.hostname_source, options.port_source, options.username_source, options.password_source) api_source = getConnection(url_source, options.client_cert_source) source_version = api_source.server_info().get('api_version', [3, 0, 0]) print " Success" except TransportError as e: print " ERROR:", e.message exit(1) except: print " ERROR" print "" raise print "" print "testing connection to destination backend..." try:
os.path.basename(options.html) + ".topology.png") htmldir = os.path.abspath(os.path.dirname(options.html)) if not os.path.exists(htmldir): os.makedirs(htmldir) shutil.copy( os.path.join("gui", "topology.png"), os.path.join(htmldir, os.path.basename(options.html) + ".topology.png")) with open(options.html, "w+") as f: f.write(htmlcontent) return os.path.abspath(options.html) options = parseArgs() url = options.url if options.url else createUrl( options.protocol, options.hostname, options.port, options.username, options.password) api = getConnection(url, options.client_cert) config, top_id = get_config(options, api) if not options.skip_software: randint = random.randint(0, 100000) while os.path.exists(os.path.join("/tmp", "tomato_demo_setup_%d" % randint)): randint = random.randint(0, 100000) installer_dir = os.path.join("/tmp", "tomato_demo_setup_%d" % randint) installer_archive = os.path.join(installer_dir, "install_demo.tar.gz") shutil.copytree("archive_content", installer_dir)
cmd = ["sudo", "rm", "-rf", mongodb_path] print " [%s]" % " ".join(cmd) subprocess.call(cmd) print "" # start tomato print "Starting ToMaTo..." subprocess.call(["./tomato-ctl.py", "start"]) time.sleep(5) # give tomato some time to open ports print "" # insert site and hosts print "Adding site and hosts..." conn = tomato.getConnection( tomato.createUrl("http+xmlrpc", "localhost", 8000, "admin", "changeme")) conn.site_create( config['site']['name'], 'others', config['site']['label'], { 'location': config['site']['location'], 'geolocation': config['site']['geolocation'] }) for host in config['hosts']: try: conn.host_create(host['name'], config['site']['name'], { 'address': host['address'], 'rpcurl': host['rpcurl'] }) except: print "error inserting %s" % host['name'] print ""
options.username) options.password = keyring.get_password( KEYRING_SERVICE_NAME, KEYRING_USER_NAME) except ImportError: pass if not options.password: options.password = getpass.getpass("Password: "******"http+xmlrpc", options.hostname, options.port, options.username, options.password)) # api = getConnection(options.hostname, options.port, options.ssl, options.username, options.password, options.client_cert) with open(options.packetconfig) as f: template_configs = json.load(f) # do the actual work res_filename = create_archive(api, template_configs, options.target) # final console output debugger.log(subStep="", step="", showStep=False) debugger.log(subStep="Saved file as " + res_filename, step="Finished", showSubStep=True)
elif version[0] == 4: return _insert_template_4_0_2(api, template, overwrite_on_conflict) options = parseArgs() print "" print "testing connection to source backend..." try: if options.url_source: url_source = options.url_source else: url_source = createUrl(options.protocol_source, options.hostname_source, options.port_source, options.username_source, options.password_source) api_source = getConnection(url_source, options.client_cert_source) source_version = api_source.server_info().get('api_version', [3, 0, 0]) print " Success" except TransportError as e: print " ERROR:", e.message exit(1) except: print " ERROR" print "" raise print "" print "testing connection to destination backend..." try: if options.url_destination:
if not options.password and not options.client_cert: if not options.no_keyring: try: import keyring KEYRING_SERVICE_NAME = "ToMaTo" KEYRING_USER_NAME = "%s/%s" % (options.hostname, options.username) options.password = keyring.get_password(KEYRING_SERVICE_NAME, KEYRING_USER_NAME) except ImportError: pass if not options.password: options.password = getpass.getpass("Password: "******"http+xmlrpc", options.hostname, options.port, options.username, options.password)) # api = getConnection(options.hostname, options.port, options.ssl, options.username, options.password, options.client_cert) with open(options.packetconfig) as f: template_configs = json.load(f) # do the actual work res_filename = create_archive(api, template_configs, options.target) # final console output debugger.log(subStep="", step="", showStep=False) debugger.log(subStep="Saved file as " + res_filename, step="Finished", showSubStep=True)
'<iframe class="vnc" id="%s" src="http://%s/element/%s/console_novnc"></iframe>' % (name, options.hostname, info["element_id"]) ) htmlcontent = htmlcontent.replace("</body>", '<a style="color:black;position:absolute;bottom:0;" href="http://%s/topology/%s" target="_blank">Open Editor</a></body>' % (options.hostname, topology_id)) htmlcontent = htmlcontent.replace("topology.png", os.path.basename(options.html)+".topology.png") htmldir = os.path.abspath(os.path.dirname(options.html)) if not os.path.exists(htmldir): os.makedirs(htmldir) shutil.copy(os.path.join("gui", "topology.png"), os.path.join(htmldir, os.path.basename(options.html)+".topology.png")) with open(options.html, "w+") as f: f.write(htmlcontent) return os.path.abspath(options.html) options = parseArgs() url = options.url if options.url else createUrl(options.protocol, options.hostname, options.port, options.username, options.password) api = getConnection(url, options.client_cert) config, top_id = get_config(options, api) if not options.skip_software: randint = random.randint(0, 100000) while os.path.exists(os.path.join("/tmp", "tomato_demo_setup_%d" % randint)): randint = random.randint(0, 100000) installer_dir = os.path.join("/tmp", "tomato_demo_setup_%d" % randint) installer_archive = os.path.join(installer_dir, "install_demo.tar.gz") shutil.copytree("archive_content", installer_dir) with open(os.path.join(installer_dir, "config.json"), "w+") as f: