86
class Property(object):
85
87
"""Property Object base class."""
89
def __init__(self, name=None, val=None):
94
class ManagedObjectReference(object):
95
"""A managed object reference is a remote identifier."""
97
def __init__(self, value="object-123", _type="ManagedObject"):
98
super(ManagedObjectReference, self)
99
# Managed Object Reference value attributes
100
# typically have values like vm-123 or
101
# host-232 and not UUID.
103
# Managed Object Reference _type
104
# attributes hold the name of the type
105
# of the vCenter object the value
106
# attribute is the identifier for
110
class ObjectContent(object):
111
"""ObjectContent array holds dynamic properties."""
113
# This class is a *fake* of a class sent back to us by
114
# SOAP. It has its own names. These names are decided
115
# for us by the API we are *faking* here.
116
def __init__(self, obj_ref, prop_list=None, missing_list=None):
119
if not isinstance(prop_list, collections.Iterable):
122
if not isinstance(missing_list, collections.Iterable):
125
# propSet is the name your Python code will need to
126
# use since this is the name that the API will use
127
self.propSet = prop_list
129
# missingSet is the name your python code will
130
# need to use since this is the name that the
131
# API we are talking to will use.
132
self.missingSet = missing_list
92
135
class ManagedObject(object):
93
"""Managed Data Object base class."""
136
"""Managed Object base class."""
95
def __init__(self, name="ManagedObject", obj_ref=None):
138
def __init__(self, name="ManagedObject", obj_ref=None, value=None):
96
139
"""Sets the obj property which acts as a reference to the object."""
97
140
super(ManagedObject, self).__setattr__('objName', name)
142
# A managed object is a local representation of a
143
# remote object that you can reference using the
98
145
if obj_ref is None:
99
obj_ref = str(uuid.uuid4())
148
obj_ref = ManagedObjectReference(value, name)
150
# we use __setattr__ here because below the
151
# default setter has been altered for this class.
100
152
object.__setattr__(self, 'obj', obj_ref)
101
153
object.__setattr__(self, 'propSet', [])
116
168
return self.__getattr__(attr)
118
170
def __setattr__(self, attr, val):
171
# TODO(hartsocks): this is adds unnecessary complexity to the class
119
172
for prop in self.propSet:
120
173
if prop.name == attr:
126
179
self.propSet.append(elem)
128
181
def __getattr__(self, attr):
182
# TODO(hartsocks): remove this
183
# in a real ManagedObject you have to iterate the propSet
184
# in a real ManagedObject, the propSet is a *set* not a list
129
185
for elem in self.propSet:
130
186
if elem.name == attr:
184
241
"""Virtual Machine class."""
186
243
def __init__(self, **kwargs):
187
super(VirtualMachine, self).__init__("VirtualMachine")
244
super(VirtualMachine, self).__init__("VirtualMachine", value='vm-10')
188
245
self.set("name", kwargs.get("name"))
189
246
self.set("runtime.connectionState",
190
247
kwargs.get("conn_state", "connected"))
202
259
self.set("summary.config.memorySizeMB", kwargs.get("mem", 1))
203
260
self.set("config.hardware.device", kwargs.get("virtual_device", None))
204
261
self.set("config.extraConfig", kwargs.get("extra_config", None))
262
self.set('runtime.host',
263
ManagedObjectReference(value='host-123', _type="HostSystem"))
264
self.device = kwargs.get("virtual_device")
206
266
def reconfig(self, factory, val):
224
284
controller = VirtualLsiLogicController()
225
285
controller.key = controller_key
227
nic = VirtualPCNet32()
229
self.set("config.hardware.device", [disk, controller, nic])
287
self.set("config.hardware.device", [disk, controller,
230
289
except AttributeError:
231
290
# Case of Reconfig of VM to set extra params
232
291
self.set("config.extraConfig", val.extraConfig)
255
314
super(Datastore, self).__init__("Datastore")
256
315
self.set("summary.type", "VMFS")
257
316
self.set("summary.name", "fake-ds")
258
self.set("summary.capacity", 1024 * 1024 * 1024)
259
self.set("summary.freeSpace", 500 * 1024 * 1024)
317
self.set("summary.capacity", 1024 * 1024 * 1024 * 1024)
318
self.set("summary.freeSpace", 500 * 1024 * 1024 * 1024)
262
321
class HostNetworkSystem(ManagedObject):
278
337
class HostSystem(ManagedObject):
279
338
"""Host System class."""
282
super(HostSystem, self).__init__("HostSystem")
340
def __init__(self, obj_ref=None, value='host-123'):
341
super(HostSystem, self).__init__("HostSystem", obj_ref, value)
283
342
self.set("name", "ha-host")
284
343
if _db_content.get("HostNetworkSystem", None) is None:
285
344
create_host_network_system()
308
367
config.product = product
309
368
summary.config = config
370
pnic_do = DataObject()
371
pnic_do.device = "vmnic0"
372
net_info_pnic = DataObject()
373
net_info_pnic.PhysicalNic = [pnic_do]
311
375
self.set("summary", summary)
376
self.set("config.network.pnic", net_info_pnic)
313
378
if _db_content.get("Network", None) is None:
577
642
"powerstate": "poweredOff",
578
643
"vmPathName": config_spec.files.vmPathName,
579
644
"numCpu": config_spec.numCPUs,
580
"mem": config_spec.memoryMB}
645
"mem": config_spec.memoryMB,
646
"virtual_device": config_spec.deviceChange,
647
"extra_config": config_spec.extraConfig}
581
648
virtual_machine = VirtualMachine(**vm_dict)
582
649
_create_object("VirtualMachine", virtual_machine)
583
650
task_mdo = create_task(method, "success")