1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain a copy of the License at |
7
|
|
|
# |
8
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
9
|
|
|
# |
10
|
|
|
# Unless required by applicable law or agreed to in writing, software |
11
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
# limitations under the License. |
15
|
|
|
|
16
|
|
|
from vmwarelib import inventory |
17
|
|
|
from vmwarelib.actions import BaseAction |
18
|
|
|
from pyVmomi import vim |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
class GetItems(BaseAction): |
22
|
|
|
|
23
|
|
|
def run(self, itemtype, parents=False, summary=False, vsphere=None): |
24
|
|
|
""" |
25
|
|
|
Return List of items within specified Vsphere endpoint. |
26
|
|
|
Can be used to return a list or a summary of the items. |
27
|
|
|
|
28
|
|
|
Args: |
29
|
|
|
- itemtype: What type of object to retrieve |
30
|
|
|
- parents: Include Parent ID for hierarchy generation |
31
|
|
|
- summary: include object summary within results |
32
|
|
|
- vsphere: Which endpoint to connect to. |
33
|
|
|
|
34
|
|
|
Returns: |
35
|
|
|
- dict: JSON structured lits |
36
|
|
|
""" |
37
|
|
|
items = {'DataCenter': vim.Datacenter, |
38
|
|
|
'DataCenter Cluster': vim.ClusterComputeResource, |
39
|
|
|
'Resource Pool': vim.ResourcePool, |
40
|
|
|
'DataStore Cluster': vim.StoragePod, |
41
|
|
|
'DataStore': vim.Datastore, |
42
|
|
|
'Virtual Machines': vim.VirtualMachine, |
43
|
|
|
'Networks': vim.Network, |
44
|
|
|
'Hosts': vim.HostSystem} |
45
|
|
|
|
46
|
|
|
objecttype = items[itemtype] |
47
|
|
|
results = {} |
48
|
|
|
self.establish_connection(vsphere) |
49
|
|
|
|
50
|
|
|
itemlist = inventory.get_managed_entities(self.si_content, objecttype) |
51
|
|
|
for item in itemlist.view: |
52
|
|
|
values = {} |
53
|
|
|
values["ID"] = item |
54
|
|
|
if parents: |
55
|
|
|
values["Parent"] = item.parent |
56
|
|
|
|
57
|
|
|
if itemtype != 'DataCenter' and summary: |
58
|
|
|
values["summary"] = item.summary |
59
|
|
|
|
60
|
|
|
results[item.name] = values |
61
|
|
|
|
62
|
|
|
return results |
63
|
|
|
|