Unverified Commit 6cc262ae authored by Ioannis Tsafaras's avatar Ioannis Tsafaras Committed by Avraam Tsantekidis
Browse files

LAM-40 Use ssh keys from provisioner

parent 078e9265
import tempfile
import ansible
from ansible.playbook import PlayBook
from ansible import callbacks
......@@ -7,21 +8,25 @@ class Manager:
def __init__(self, provisioner_response):
self.inventory = {}
self.inventory["master"] = {
"name": "snf-" + str(provisioner_response["nodes"]["master"]["id"]),
"ip": provisioner_response["nodes"]["master"]["internal_ip"]}
self.inventory["slaves"] = []
for response in provisioner_response["nodes"]["slaves"]:
self.inventory["slaves"].append(
{"name": "snf-" + str(response["id"]),
"ip": response["internal_ip"]})
self.cidr = provisioner_response["subnet"]["cidr"]
self.inventory['master'] = {
'name': 'snf-' + str(provisioner_response['nodes']['master']['id']),
'ip': provisioner_response['nodes']['master']['internal_ip']}
self.inventory['slaves'] = []
for response in provisioner_response['nodes']['slaves']:
self.inventory['slaves'].append(
{'name': 'snf-' + str(response['id']),
'ip': response['internal_ip']})
self.cidr = provisioner_response['subnet']['cidr']
ansible.constants.ANSIBLE_SSH_ARGS = '-o "ProxyCommand ssh -A -W %%h:%%p root@%s"' \
% self.inventory["master"]["name"] + "vm.okeanos.grnet.gr"
self.kf = tempfile.NamedTemporaryFile()
self.kf.write(provisioner_response['pk'])
ansible.constants.ANSIBLE_SSH_ARGS = '-o "ProxyCommand ssh -A -W %%h:%%p root@%s" -i %s' \
% self.inventory['master']['name'] + 'vm.okeanos.grnet.gr' %self.kf.name
# ansible.constants.ANSIBLE_SSH_ARGS = '-o "ProxyCommand ssh root@%s nc %%h %%p"' \
# % self.inventory["master"]["name"] + "vm.okeanos.grnet.gr"
ansible.constants.HOST_KEY_CHECKING = False
ansible.constants.DEFAULT_GATHERING = 'explicit'
def create_inventory(self):
"""
......@@ -32,25 +37,25 @@ class Manager:
inventory_groups = []
host_vars = {}
master_group = ansible.inventory.group.Group(name="master")
host = self.inventory["master"]
ansible_host = ansible.inventory.host.Host(name=host["name"] + ".vm.okeanos.grnet.gr")
host_vars["internal_ip"] = self.inventory["master"]["ip"]
host_vars["local_net"] = self.cidr
master_group = ansible.inventory.group.Group(name='master')
host = self.inventory['master']
ansible_host = ansible.inventory.host.Host(name=host['name'] + '.vm.okeanos.grnet.gr')
host_vars['internal_ip'] = self.inventory['master']['ip']
host_vars['local_net'] = self.cidr
for var_key, var_value in host_vars.iteritems():
ansible_host.set_variable(var_key, var_value)
ansible_host.set_variable("id", 0)
ansible_host.set_variable('id', 0)
master_group.add_host(ansible_host)
inventory_groups.append(master_group)
slave_group = ansible.inventory.group.Group(name="slaves")
host_vars["proxy_env"] = {"http_proxy": "http://" + self.inventory["master"]["name"]+".local:3128"}
slave_group = ansible.inventory.group.Group(name='slaves')
host_vars['proxy_env'] = {'http_proxy': 'http://' + self.inventory['master']['name']+'.local:3128'}
for host_id, host in enumerate(self.inventory["slaves"], start=1):
ansible_host = ansible.inventory.host.Host(name=host["name"] + ".local")
host_vars["internal_ip"] = host["ip"]
ansible_host = ansible.inventory.host.Host(name=host['name'] + '.local')
host_vars['internal_ip'] = host['ip']
for var_key, var_value in host_vars.iteritems():
ansible_host.set_variable(var_key, var_value)
ansible_host.set_variable("id", host_id)
ansible_host.set_variable('id', host_id)
slave_group.add_host(ansible_host)
inventory_groups.append(slave_group)
......
......@@ -19,12 +19,12 @@ if __name__ == "__main__":
parser.add_argument('--disk_slave', type=int, dest='disk_slave', default=40) # in GB
parser.add_argument('--ip_request', type=int, dest='ip_request', default=1)
parser.add_argument('--network_request', type=int, dest='network_request', default=1)
parser.add_argument('--image_name', type=str, dest='image_name', default="debian")
parser.add_argument('--image_name', type=str, dest='image_name', default='debian')
parser.add_argument('--cluster_size', type=int, dest='cluster_size', default=2)
args = parser.parse_args()
provisioner = Provisioner(cloud_name=args.cloud)
provisioner.create_lambda_cluster("test_vm", slaves=args.slaves,
provisioner.create_lambda_cluster('test_vm', slaves=args.slaves,
cluster_size=args.cluster_size,
vcpus_master=args.vcpus_master,
vcpus_slave=args.vcpus_slave,
......@@ -37,13 +37,14 @@ if __name__ == "__main__":
project_name=args.project_name)
provisioner_response = provisioner.get_cluster_details()
master_id = provisioner_response["nodes"]["master"]["id"]
master_id = provisioner_response['nodes']['master']['id']
master_ip = provisioner.get_server_private_ip(master_id)
provisioner_response["nodes"]["master"]["internal_ip"] = master_ip
slave_ids = [slave["id"] for slave in provisioner_response["nodes"]["slaves"]]
for i, slave in enumerate(provisioner_response["nodes"]["slaves"]):
slave_ip = provisioner.get_server_private_ip(slave["id"])
provisioner_response["nodes"]["slaves"][i]["internal_ip"] = slave_ip
provisioner_response['nodes']['master']['internal_ip'] = master_ip
slave_ids = [slave['id'] for slave in provisioner_response['nodes']['slaves']]
for i, slave in enumerate(provisioner_response['nodes']['slaves']):
slave_ip = provisioner.get_server_private_ip(slave['id'])
provisioner_response['nodes']['slaves'][i]['internal_ip'] = slave_ip
provisioner_response['pk'] = provisioner.get_private_key();
manager = Manager(provisioner_response)
manager.create_inventory()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment