Exemplo n.º 1
0
	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))
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
 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))
Exemplo n.º 5
0
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()
	api = getConnection(options.hostname, options.port, options.ssl, options.username, options.password, 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)
Exemplo n.º 6
0
	def create_backend_api_proxy():
		"""

		:return: True if connected, False if not
		"""
		import lib as tomato

		backend_url = config[BACKEND_API_MODULE]["api_url"]
		try:
			api = tomato.getConnection(backend_url)
			if api.ping():
				Module.backend_api_proxy = api
				return True
			return False
		except:
			return False
Exemplo n.º 7
0
    def create_backend_api_proxy():
        """

		:return: True if connected, False if not
		"""
        import lib as tomato

        backend_url = config[BACKEND_API_MODULE]["api_url"]
        try:
            api = tomato.getConnection(backend_url)
            if api.ping():
                Module.backend_api_proxy = api
                return True
            return False
        except:
            return False
Exemplo n.º 8
0
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']})
	except:
Exemplo n.º 9
0
		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']
Exemplo n.º 10
0
	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:
		url_destination = options.url_destination
Exemplo n.º 11
0
                                     epilog="This program uploads a probing archive to ToMaTo in order to determine package dependencies. You need a ToMaTo account to do this.",
                                     add_help=False)
    parser.add_argument('--help', action='help')
    parser.add_argument("--hostname" , "-h", required=True, help="the host of the server")
    parser.add_argument("--port", "-p", default=8000, help="the port of the server")
    parser.add_argument("--ssl", "-s", action="store_true", default=False, help="whether to use ssl")
    parser.add_argument("--client_cert", required=False, default=None, help="path of the ssl certificate")
    parser.add_argument("--username", "-U", help="the username to use for login")
    parser.add_argument("--password", "-P", help="the password to use for login")
    parser.add_argument("--target", "-t", help="the output filename.", required=True)
    parser.add_argument("--packetconfig", "-c", help='The archive configuration. This should point to a JSON file of the form [{tech:"string",site:"string",template:"string",packages:["string"]}]. Each entry must refer to a different operating system.', required=True)
    parser.add_argument("--verbose", "-v", help="verbose output", action="store_true", default=False)
    options = parser.parse_args()
    if not options.username and not options.client_cert:
        options.username=raw_input("Username: "******"Password: "******"",step="",showStep=False)
debugger.log(subStep="Saved file as "+res_filename, step="Finished",showSubStep=True)
Exemplo n.º 12
0
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']
Exemplo n.º 13
0
	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)
Exemplo n.º 14
0
Arquivo: setup.py Projeto: GLab/ToMaTo
		)
	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:
		json.dump(config, f)