Skip to content

Commit 35e296c

Browse files
authored
Merge pull request #31 from EncoreTechnologies/feature/vm-guest-info
Added new action to retrieve a VM's guest information
2 parents b73ece7 + caa1097 commit 35e296c

14 files changed

+469
-8
lines changed

CHANGES.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Change Log
22

3+
## V0.7.7
4+
5+
Added a new action actions:
6+
* `vsphere.host_get` - retrieves the Summary information for an ESX host.
7+
* `vsphere.host_network_hints_get` - retrieves the Network Hints for an ESX host.
8+
* `vsphere.vm_guest_info_get` - retrieves the Guest information for a VM.
9+
* `vsphere.vm_runtime_info_get` - retrieves the Runtime information for a VM.
10+
11+
Contributed by Nick Maludy (Encore Technologies).
12+
313
## V0.7.6
414

515
Minor linting fixes

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ This trigger is emitted for every task information that is invoked on the specif
115115
Here is a example of a trigger payload.
116116
```json
117117
{
118-
state: success,
119-
queue_time: 2017/03/10 02:08:39,
120-
start_time: 2017/03/10 02:08:39,
121-
complete_time: 2017/03/10 02:08:40,
122-
operation_name: VirtualMachine.destroy,
123-
task_id: task-5714
118+
"state": "success",
119+
"queue_time": "2017/03/10 02:08:39",
120+
"start_time": "2017/03/10 02:08:39",
121+
"complete_time": "2017/03/10 02:08:40",
122+
"operation_name": "VirtualMachine.destroy",
123+
"task_id": "task-5714"
124124
}
125125
```
126126
This is what each parameter means:
@@ -151,10 +151,13 @@ PYVMOMI 6.0 requires alternative connection coding and Python 2.7.9 minimum due
151151
* `vsphere.get_vmconsole_urls` - Retrieves urls of the virtual machines' consoles
152152
* `vsphere.get_vms` - Retrieves the virtual machines on a vCenter Server system. It computes the union of Virtual Machine sets based on each parameter.
153153
* `vsphere.hello_vsphere` - Wait for a Task to complete and returns its result.
154+
* `vsphere.host_get` - Retrieves the Summary information for an ESX host.
155+
* `vsphere.host_network_hints_get` - Retrieves the Network Hints for an ESX host.
154156
* `vsphere.set_vm` - Changes configuration of a Virtual Machine.
155157
* `vsphere.vm_check_tools` - Wait for a Task to complete and returns its result.
156158
* `vsphere.vm_create_from_template` - Create a new VM from existing template.
157159
* `vsphere.vm_env_items_get` - Retrieve list of Objects from VSphere
160+
* `vsphere.vm_guest_info_get` - Retrieve Guest details of a VM object
158161
* `vsphere.vm_hw_barebones_create` - Create BareBones VM (CPU, Ram, Graphics Only)
159162
* `vsphere.vm_hw_basic_build` - Minstral Flow to Build Basic Server and power it on.
160163
* `vsphere.vm_hw_cpu_mem_edit` - Adjust the CPU and RAM values assigned to a Virtual Machine
@@ -168,6 +171,7 @@ PYVMOMI 6.0 requires alternative connection coding and Python 2.7.9 minimum due
168171
* `vsphere.vm_hw_remove` - Removes the Virtual Machine.
169172
* `vsphere.vm_hw_scsi_controller_add` - Add SCSI HDD Controller device to VM
170173
* `vsphere.vm_hw_uuid_get` - Retrieve VM UUID
174+
* `vsphere.vm_runtime_info_get` - Retrieves the Runtime information for a VM.
171175
* `vsphere.wait_task` - Wait for a Task to complete and returns its result.
172176

173177
## Known Bugs

actions/host_get.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.serialize import HostGetJSONEncoder
18+
from vmwarelib.actions import BaseAction
19+
import json
20+
21+
22+
class GetHost(BaseAction):
23+
def run(self, host_ids, host_names, vsphere=None):
24+
"""
25+
Retrieve summary information for given Hosts (ESXi)
26+
27+
Args:
28+
- host_ids: Moid of Host to retrieve
29+
- host_names: Name of Host to retrieve
30+
- vsphere: Pre-configured vsphere connection details (config.yaml)
31+
32+
33+
Returns:
34+
- dict: Host network hints details.
35+
"""
36+
37+
# TODO review using propertspec for retrieving all Hosts's at onces.
38+
results = {}
39+
if not host_ids and not host_names:
40+
raise ValueError("No IDs nor Names provided.")
41+
42+
self.establish_connection(vsphere)
43+
44+
if host_ids:
45+
for hid in host_ids:
46+
host = inventory.get_hostsystem(self.si_content, moid=hid)
47+
if host:
48+
if host.name not in results:
49+
results[host.name] = json.loads(json.dumps(host.summary,
50+
cls=HostGetJSONEncoder))
51+
if host_names:
52+
for host in host_names:
53+
host = inventory.get_hostsystem(self.si_content, name=host)
54+
if host:
55+
if host.name not in results:
56+
print host.name
57+
results[host.name] = json.loads(json.dumps(host.summary,
58+
cls=HostGetJSONEncoder))
59+
return results

actions/host_get.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: host_get
3+
pack: vsphere
4+
runner_type: python-script
5+
description: Retrieve summary information for given Hosts (ESXi)
6+
entry_point: host_get.py
7+
parameters:
8+
host_ids:
9+
type: array
10+
description: Comma seperated list of Host IDs
11+
required: false
12+
position: 0
13+
host_names:
14+
type: array
15+
description: Comma seperated list of Host Names
16+
required: false
17+
position: 1
18+
default: ~
19+
vsphere:
20+
type: string
21+
description: Pre-configured vsphere endpoint
22+
required: false
23+
position: 2

actions/host_network_hits_get.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.serialize import PhysicalNicJSONEncoder
18+
from vmwarelib.actions import BaseAction
19+
import json
20+
21+
22+
class GetHostNetworkHints(BaseAction):
23+
def run(self, host_ids, host_names, vsphere=None):
24+
"""
25+
Retrieve Network Hintsfor given Hosts (ESXi)
26+
27+
Args:
28+
- host_ids: Moid of Host to retrieve
29+
- host_names: Name of Host to retrieve
30+
- vsphere: Pre-configured vsphere connection details (config.yaml)
31+
32+
33+
Returns:
34+
- dict: Host network hints details.
35+
"""
36+
37+
# TODO review using propertspec for retrieving all Hosts's at onces.
38+
results = {}
39+
if not host_ids and not host_names:
40+
raise ValueError("No IDs nor Names provided.")
41+
42+
self.establish_connection(vsphere)
43+
44+
if host_ids:
45+
for hid in host_ids:
46+
host = inventory.get_hostsystem(self.si_content, moid=hid)
47+
if host:
48+
if host.name not in results:
49+
network_hints = host.configManager.networkSystem.QueryNetworkHint()
50+
results[host.name] = json.loads(json.dumps(network_hints,
51+
cls=PhysicalNicJSONEncoder))
52+
if host_names:
53+
for host in host_names:
54+
host = inventory.get_hostsystem(self.si_content, name=host)
55+
if host:
56+
if host.name not in results:
57+
network_hints = host.configManager.networkSystem.QueryNetworkHint()
58+
results[host.name] = json.loads(json.dumps(network_hints,
59+
cls=PhysicalNicJSONEncoder))
60+
return results

actions/host_network_hits_get.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: host_network_hits_get
3+
pack: vsphere
4+
runner_type: python-script
5+
description: Retrieve Network Hints for given Hosts (ESXi)
6+
entry_point: host_network_hits_get.py
7+
parameters:
8+
host_ids:
9+
type: array
10+
description: Comma seperated list of VM IDs
11+
required: false
12+
position: 0
13+
host_names:
14+
type: array
15+
description: Comma seperated list of VM Names
16+
required: false
17+
position: 1
18+
default: ~
19+
vsphere:
20+
type: string
21+
description: Pre-configured vsphere endpoint
22+
required: false
23+
position: 2

actions/vm_guest_info_get.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.serialize import MyJSONEncoder
18+
from vmwarelib.actions import BaseAction
19+
import json
20+
21+
22+
class GetVMGuestInfo(BaseAction):
23+
def run(self, vm_ids, vm_names, vsphere=None):
24+
"""
25+
Retrieve Guest Info for given Virtual Machines
26+
27+
Args:
28+
- vm_ids: Moid of Virtual Machines to retrieve
29+
- vm_names: Name of Virtual Machines to retrieve
30+
- vsphere: Pre-configured vsphere connection details (config.yaml)
31+
32+
33+
Returns:
34+
- dict: Virtual machine details.
35+
"""
36+
37+
# TODO review using propertspec for retrieving all VM's at onces.
38+
results = {}
39+
if not vm_ids and not vm_names:
40+
raise ValueError("No IDs nor Names provided.")
41+
42+
self.establish_connection(vsphere)
43+
44+
if vm_ids:
45+
for vid in vm_ids:
46+
vm = inventory.get_virtualmachine(self.si_content, moid=vid)
47+
if vm:
48+
if vm.name not in results:
49+
results[vm.name] = json.loads(json.dumps(vm.guest, cls=MyJSONEncoder))
50+
if vm_names:
51+
for vm in vm_names:
52+
vm = inventory.get_virtualmachine(self.si_content, name=vm)
53+
if vm:
54+
if vm.name not in results:
55+
results[vm.name] = json.loads(json.dumps(vm.guest, cls=MyJSONEncoder))
56+
return results

actions/vm_guest_info_get.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: vm_guest_info_get
3+
pack: vsphere
4+
runner_type: python-script
5+
description: Retrieve Guest details of a VM object
6+
entry_point: vm_guest_info_get.py
7+
parameters:
8+
vm_ids:
9+
type: array
10+
description: Comma seperated list of VM IDs
11+
required: false
12+
position: 0
13+
vm_names:
14+
type: array
15+
description: Comma seperated list of VM Names
16+
required: false
17+
position: 1
18+
default: ~
19+
vsphere:
20+
type: string
21+
description: Pre-configured vsphere endpoint
22+
required: false
23+
position: 2

actions/vm_runtime_info_get.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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.serialize import VmRuntimeInfoJSONEncoder
18+
from vmwarelib.actions import BaseAction
19+
import json
20+
21+
22+
class GetVMRuntimeInfo(BaseAction):
23+
def run(self, vm_ids, vm_names, vsphere=None):
24+
"""
25+
Retrieve Runtime Info for given Virtual Machines
26+
27+
Args:
28+
- vm_ids: Moid of Virtual Machines to retrieve
29+
- vm_names: Name of Virtual Machines to retrieve
30+
- vsphere: Pre-configured vsphere connection details (config.yaml)
31+
32+
33+
Returns:
34+
- dict: Virtual machine details.
35+
"""
36+
37+
# TODO review using propertspec for retrieving all VM's at onces.
38+
results = {}
39+
if not vm_ids and not vm_names:
40+
raise ValueError("No IDs nor Names provided.")
41+
42+
self.establish_connection(vsphere)
43+
44+
if vm_ids:
45+
for vid in vm_ids:
46+
vm = inventory.get_virtualmachine(self.si_content, moid=vid)
47+
if vm:
48+
if vm.name not in results:
49+
results[vm.name] = json.loads(json.dumps(vm.runtime,
50+
cls=VmRuntimeInfoJSONEncoder))
51+
if vm_names:
52+
for vm in vm_names:
53+
vm = inventory.get_virtualmachine(self.si_content, name=vm)
54+
if vm:
55+
if vm.name not in results:
56+
results[vm.name] = json.loads(json.dumps(vm.runtime,
57+
cls=VmRuntimeInfoJSONEncoder))
58+
return results

actions/vm_runtime_info_get.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: vm_runtime_info_get
3+
pack: vsphere
4+
runner_type: python-script
5+
description: Retrieve Runtime details of a VM object
6+
entry_point: vm_runtime_info_get.py
7+
parameters:
8+
vm_ids:
9+
type: array
10+
description: Comma seperated list of VM IDs
11+
required: false
12+
position: 0
13+
vm_names:
14+
type: array
15+
description: Comma seperated list of VM Names
16+
required: false
17+
position: 1
18+
default: ~
19+
vsphere:
20+
type: string
21+
description: Pre-configured vsphere endpoint
22+
required: false
23+
position: 2

0 commit comments

Comments
 (0)