-
Notifications
You must be signed in to change notification settings - Fork 1
/
clsCustomer.py
executable file
·154 lines (117 loc) · 5.31 KB
/
clsCustomer.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
from clsBaseClass import *
from clsInstance import *
class clsCustomer(clsBaseClass):
import boto.ec2
__awsConnection = None
__ObjConfig = None
__Instances = ""
id = 0
Name = ""
Access_key = ""
Secret_key = ""
Puppet_repo=""
Puppet_known_hosts = ""
Puppet_ssh_private = ""
Puppet_ssh_pub = ""
Dns_domain = ""
Region = ""
BckVolumesRetention = 1
HistoricalRetention = 1
TagVolumesOnBackup = 1
Instances = 0 #Instance number
def __init__(self, kCustomerId,kCustomersJsonConfig = ""):
self.id = kCustomerId
if kCustomersJsonConfig != "":
self.__ObjConfig = kCustomersJsonConfig
else:
self.__ObjConfig = BOMBO_CUSTOMERS_CONFIG
self.loaData()
def doAwsConnection(self):
if not self.__awsConnection == None:
return self.__awsConnection
try:
self.printMsg ("","[AWS] Connecting to region " + self.Region + "...")
self.__awsConnection = self.boto.ec2.connect_to_region(
self.Region,
aws_access_key_id=self.Access_key,
aws_secret_access_key=self.Secret_key)
self.printMsg ("","---> OK")
except Exception, e:
self.printMsg ("loadAws",e.args[0],True,True)
def loaData(self):
self.printMsg ("","Loading customer...")
jsonCustomersList = self.loadJsonFile(self.__ObjConfig)
try:
self.Name = jsonCustomersList[str(self.id)]["name"]
self.Dns_domain = jsonCustomersList[str(self.id)]["settings"]["dns_domain"]
self.Region = jsonCustomersList[str(self.id)]["settings"]["region"]
self.Puppet_repo = jsonCustomersList[str(self.id)]["settings"]["puppet_repo"]
self.Access_key = jsonCustomersList[str(self.id)]["settings"]["access_key"]
self.Secret_key = jsonCustomersList[str(self.id)]["settings"]["secret_key"]
self.BckVolumesRetention = jsonCustomersList[str(self.id)]["settings"]["bck_volumes_retention"]
self.HistoricalRetention = jsonCustomersList[str(self.id)]["settings"]["historical_volumes_retention"]
self.TagVolumesOnBackup = bool(jsonCustomersList[str(self.id)]["settings"]["tag_volumes_on_backup"])
#Sensitive info
self.Puppet_known_hosts = jsonCustomersList[str(self.id)]["settings"]["puppet_known_hosts"]
self.Puppet_ssh_private = jsonCustomersList[str(self.id)]["settings"]["puppet_ssh_private"]
self.Puppet_ssh_pub = jsonCustomersList[str(self.id)]["settings"]["puppet_ssh_pub"]
self.printMsg ("","---> " + self.Name)
return True
except Exception, e:
self.printMsg ("loadData",e.args[0],True,True)
def getInstances(self):
if self.__Instances == "":
self.__Instances = self.getAllInstances()
return self.__Instances
def getAwsInstance(self,kInstanceId):
if kInstanceId == "":
self.printMsg ("","Ooh no, you must specify the Instance ID!",True,True)
return self.getAllAwsInstances(kInstanceId)
def getAllAwsInstances(self,kInstanceId=""):
import boto
self.doAwsConnection()
self.printMsg ("","[BOMBO] Getting instance details...")
if kInstanceId != "":
reservations = self.__awsConnection.get_all_instances(instance_ids=[kInstanceId])
if not reservations[0].instances:
self.printMsg ("","Ooh no, i can't find the instance -> " + kInstanceId + "!",True,True)
result = reservations[0].instances[0]
self.printMsg ("","---> " + result.id)
else:
reservations = self.__awsConnection.get_all_instances()
result = reservations[0].instances
self.printMsg ("","---> Found " + str(len(result)) + " instances")
return result
def getInstance(self,kInstanceId):
if kInstanceId == "":
self.printMsg ("","Ooh no, you must specify the Instance ID!",True,True)
return self.getAllInstances(kInstanceId)[0]
def getAllInstances(self,kInstanceId=""):
import boto
self.doAwsConnection()
InstancesCollection = []
self.printMsg ("","[BOMBO] Getting instance details...")
if kInstanceId != "":
reservations = self.__awsConnection.get_all_instances(instance_ids=[kInstanceId])
if not reservations[0].instances:
self.printMsg ("","Ooh no, i can't find the instance -> " + kInstanceId + "!",True,True)
InstancesCollection.append(
clsInstance(
reservations[0].instances[0].id,
self,
reservations[0].instances[0]
)
)
self.printMsg ("","---> " + reservations[0].instances[0].id)
else:
reservations = self.__awsConnection.get_all_instances()
for inst in reservations:
InstancesCollection.append(
clsInstance(
inst.instances[0].id,
self,
inst.instances[0]
)
)
self.printMsg ("","---> Found " + str(len(InstancesCollection)) + " instances")
return InstancesCollection