-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEC2Instance.py
148 lines (130 loc) · 5.08 KB
/
EC2Instance.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
##############################################################################
#
# Copyright (C) Zenoss, Inc. 2009, all rights reserved.
#
# This content is made available according to terms specified in
# License.zenoss under the directory where your Zenoss product is installed.
#
##############################################################################
from Products.ZenModel.ManagedEntity import ManagedEntity
from Products.ZenModel.DeviceComponent import DeviceComponent
from Products.ZenRelations.RelSchema import ToOne, ToMany, ToManyCont
from Products.ZenModel.ZenossSecurity import ZEN_VIEW
from Products.Jobber.exceptions import NoSuchJobException
class EC2Instance(DeviceComponent, ManagedEntity):
"""
A DMD Device that represents a group of VMware hosts
that can run virtual devices.
"""
meta_type = "EC2Instance"
instance_id = ""
dns_name = ""
aws_name = ""
public_dns_name = ""
private_dns_name = ""
private_ip = ""
image_id = ""
instance_type = ""
kernel_id = ""
key_name = ""
launch_time = ""
placement = ""
ramdisk = ""
deviceId = ""
state = ""
region = ""
platform = ""
private_ip_addresses = []
_discoveryState = 10
_discoveryJobId = None
_deviceProdStatePreStop = 1000
_properties = (
{'id':'instance_id', 'type':'string', 'mode':'w'},
{'id':'dns_name', 'type':'string', 'mode':'w'},
{'id':'aws_name', 'type':'string', 'mode':'w'},
{'id':'public_dns_name', 'type':'string', 'mode':'w'},
{'id':'private_dns_name', 'type':'string', 'mode':'w'},
{'id':'private_ip', 'type':'string', 'mode':'w'},
{'id':'private_ip_addresses', 'type':'list', 'mode':'w'},
{'id':'image_id', 'type':'string', 'mode':'w'},
{'id':'instance_type', 'type':'string', 'mode':'w'},
{'id':'kernel_id', 'type':'string', 'mode':'w'},
{'id':'key_name', 'type':'string', 'mode':'w'},
{'id':'launch_time', 'type':'string', 'mode':'w'},
{'id':'placement', 'type':'string', 'mode':'w'},
{'id':'ramdisk', 'type':'string', 'mode':'w'},
{'id':'deviceLink', 'type':'string', 'mode':'w'},
{'id':'deviceName', 'type':'string', 'mode':'w'},
{'id':'deviceId', 'type':'string', 'mode':'w'},
{'id':'state', 'type':'string', 'mode':'w'},
{'id':'region', 'type':'string', 'mode':'w'},
{'id':'platform', 'type':'string', 'mode':'w'},
)
_relations = (
('manager', ToOne(ToManyCont,
"ZenPacks.zenoss.ZenAWS.EC2Manager", "instances")),
('instanceType', ToOne(ToMany,
"ZenPacks.zenoss.ZenAWS.EC2InstanceType", "instances")),
)
factory_type_information = (
{
'immediate_view' : 'ec2InstanceStatus',
'actions' :
(
{ 'id' : 'perfServer'
, 'name' : 'Graphs'
, 'action' : 'viewDevicePerformance'
, 'permissions' : (ZEN_VIEW, )
},
{ 'id' : 'status'
, 'name' : 'Status'
, 'action' : 'ec2InstanceStatus'
, 'permissions' : (ZEN_VIEW, )
},
{ 'id' : 'events'
, 'name' : 'Events'
, 'action' : 'viewEvents'
, 'permissions' : (ZEN_VIEW, )
},
{ 'id' : 'perfConf'
, 'name' : 'Template'
, 'action' : 'objTemplates'
, 'permissions' : ("Change Device", )
},
)
},
)
def device(self):
return self.manager()
def monitored(self):
if self.state == 'running':
return super(EC2Instance, self).monitored()
return False
def name(self):
return self.titleOrId()
def isDiscoveryPending(self):
# check if we have a job pending
if self._discoveryJobId:
try:
jobStatus = self.dmd.JobManager.getJob(self._discoveryJobId)
if jobStatus and jobStatus.finished is None:
return True
except NoSuchJobException:
pass
return False
def updateFromDict(self, propDict):
for k, v in propDict.items():
if k == 'monitored': continue
setattr(self, k, v)
def getDeviceLink(self):
if self.deviceId:
rdev = self.findDeviceByIdExact(self.deviceId)
if rdev:
return rdev.getPrimaryUrlPath()
return ""
def getDeviceName(self):
if self.deviceId:
rdev = self.findDeviceByIdExact(self.deviceId)
if rdev:
return rdev.titleOrId()
return ""