-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathlist.py
52 lines (45 loc) · 1.89 KB
/
list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /usr/bin/env python
from lndynamic import LNDynamic
import natsort
import time
with open(r"../../system-dev.txt") as hpass:
lines = hpass.readlines()
f = open(r"/home/hme/airbus", "w+")
hfile=open(r"/home/hme/airbus-users", "w+")
api = LNDynamic(lines[0].rstrip('\n'), lines[1].rstrip('\n'))
results = api.request('vm', 'list')
val= results.get('vms')
all_key= ['vm_id','name','primaryip']
#print(val)
user='ubuntu'
user_dic={}
for z in range(0,len(val)):
if "git-student" in val[z].get(all_key[1]):
#print(val[z].get(all_key[0]))
name=val[z].get(all_key[1])
#print(name)
ip= val[z].get(all_key[2])
results = api.request('vm', 'info', {'vm_id': val[z].get(all_key[0])})
#print(results)
thepass=results.get('info')
part=thepass.get('login_details').split(':')
password=part[2]
line = "{} ansible_host={} ansible_ssh_user={} ansible_ssh_pass={} ansible_ssh_extra_args='-o StrictHostKeyChecking=no'\n".format(name, ip, user , password.strip() )
#line = "{} ansible_host={} ansible_ssh_user={} ansible_ssh_pass=lawn-vex ansible_ssh_extra_args='-o StrictHostKeyChecking=no'\n".format(name, ip, user )
user_dic[name]="ip={} user={} password={}".format(ip,"centos",password.strip())
#user_dic[name]="ip={} user={} password=lawn-vex".format(ip,"ubuntu")
f.write(line)
f.close()
list_user = user_dic.keys()
natural = natsort.natsorted(list_user)
for vts in range(0, len(natural)):
myline = user_dic[natural[vts]]
user_line = "{} \t {} \n".format(natural[vts], myline)
hfile.write(user_line)
hfile.close()
#results = api.request('vm', 'info', {'vm_id': 'e3e7ab5c-a944-4118-bf78-8a67b4722c48'})
#print ("-----------------------")
#print (results)
#results = api.request('image', 'list')
#print(results)
#1c018f61-e116-46d2-8a64-18f6963e3be7