def run(self, options, args): info = utils.get_machine_info() c = client.get_local_connection(options.server_config_dir) n = c.create_node( info["username"], options.port, name="master", hostname=info["hostname"], public_ip=info["public_ip"], private_ip=info["private_ip"], pool_name=options.pool, ) if options.bootstrap: print "Bootstrapping worker on node..." j = c.start_job( "Bootstrap-node", JobType.ONE_TIME_JOB, 1, "Bootstrapping %s" % "master", requested_nodes=["master"], node_pool_name=options.pool, ) tr = c.run_task(j, "BootstrapWorker", "bootstrap %s" % "master", "master") c.stop_job(j, task_result_to_job_status(tr)) c.delete_job(j) if tr.status != TaskStatus.TASK_SUCCESSFUL: c.delete_node(n) print "Bootstrap failed, node not created" return 1 print "Successfully created and bootstrapped node 'master'" else: print "Successfully created node 'master'" return 0
def get_machine_resource(sess, battle_api_host, tenant): machine_info = get_machine_info() # If an identical machine resource exists, use that. params = { "rows": 1, "realm": "", "instance_id": "", "instance_type": "", "instance_name": "", "placement": "", "public_ip": "", "group_name": "", "machine_info": {}, } params.update(machine_info) # TODO: use the 'sess' to make the GET request so we have auth in place. # Using 'sess' now will result in 400: Bad Request, probably because the # params are passed as json and not as url query params. r = sess.request("GET", battle_api_host + "/machines", data=json.dumps(params)) if r.status_code == 200 and len(r.json()) > 0: machine = r.json()[0] machine_url = machine.get( "url", machine.get("uri")) #! backwards compability with old uri machine_resource = MachineResource(sess, machine_url, tenant, create=False) else: logger.info( "Got back status code %s from GET so I will create a new machine resource" % r.status_code) machine_resource = MachineResource(sess, battle_api_host + "/machines", tenant, machine_info) return machine_resource
#!/usr/bin/python import argparse import sys import utils parser = argparse.ArgumentParser() parser.add_argument('--myOVA_URL', help='myOVA URL', required=True) parser.add_argument('--myVM_FQDN', help='myVM_FQDN', required=True) args = parser.parse_args() machine_info = utils.get_machine_info('machine_info.csv', 'VM_FQDN', args.myVM_FQDN) if machine_info: vcenter_options = { "host": machine_info['VCENTER_HOSTNAME'], "username": machine_info['VCENTER_USERNAME'], "password": machine_info['VCENTER_PASSWORD'], "datacenter": machine_info['VCENTER_DATACENTER'], "cluster": machine_info['VCENTER_CLUSTER'], "datastore": machine_info['VCENTER_DATASTORE'], "folder": machine_info['VCENTER_FOLDER'] } vm_options = { "fqdn": machine_info['VM_FQDN'], "ip": machine_info['VM_IP'], "dns1": machine_info['VM_DNS1'], "gateway": machine_info['VM_GATEWAY'], "netmask": machine_info['VM_NETMASK'], "network_label": machine_info['VM_NETWORK_LABEL'], "name": machine_info['VM_FQDN']