Skip to content

Instantly share code, notes, and snippets.

View michaelrice's full-sized avatar

Michael Rice michaelrice

View GitHub Profile
@michaelrice
michaelrice / pyvmomi.spec
Created August 21, 2014 21:22
pyvmomi rpm spec
%if 0%{?fedora}
%global _with_python3 1
%endif
%if 0%{?rhel} && 0%{?rhel} <= 6
%{!?__python2: %global __python2 /usr/bin/python2}
%{!?python2_sitelib: %global python2_sitelib %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}
%{!?python2_sitearch: %global python2_sitearch %(%{__python2} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
%endif
@michaelrice
michaelrice / element_order_403.yaml
Created September 18, 2014 04:03
vCloud Usage Meter Server Side Complains About Element Order
interactions:
- request:
body: <rule xmlns="http://www.vmware.com/UM"><vcServer>172.16.214.129</vcServer><customerName>1018700</customerName><objectType>Data
Center</objectType><valueType>Unique ID</valueType><value>datacenter-104</value></rule>
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['214']
Content-Type: [text/xml]
@michaelrice
michaelrice / end_of_input_403.yaml
Last active August 29, 2015 14:06
vCloud Usage Meter End of Input Error
interactions:
- request:
body: <rule xmlns="http://www.vmware.com/UM"><customerName>1018700</customerName><objectType>Data
Center</objectType><valueType>Unique ID</valueType><value>datacenter-104</value><vcServerId>172.16.214.129</vcServerId></rule>
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
Content-Length: ['205']
Content-Type: [text/xml]
@michaelrice
michaelrice / task_mon.py
Created September 19, 2014 19:40
causes bork
import atexit
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
from tools import cli
# connect to vcenter
PARSER = cli.build_arg_parser()
PARSER.add_argument("-m", "--mename",
# list_one always has fewer list items than list 2
# both lists have several thousand items in them
list_one = [
{"acct": "12345a","moref":"dc-12"},
{"acct":"132132","moref":"dc-332"}
]
list_two = [
{"acct":"132132","cc":"US","zip":"77722"},
@michaelrice
michaelrice / rps.py
Created September 29, 2014 16:09
RPSLS
# Copyright 2014 Michael Rice <[email protected]>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@michaelrice
michaelrice / blocking_tasks.yaml
Created October 7, 2014 01:22
vcrpy recording to reproduce issue 176 on vmware pyvmomi
interactions:
- request:
body: null
headers:
Accept: ['*/*']
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.4.1 CPython/2.7.8 Darwin/13.4.0]
method: GET
uri: https://10.12.254.119:443//sdk/vimServiceVersions.xml
>>> from pyVmomi import vim
>>> dc = vim.Datacenter('datacenter-33')
>>> dc
'vim.Datacenter:datacenter-33'
>>> dir(dc)
['Array', 'Destroy', 'Destroy_Task', 'PowerOnMultiVM_Task', 'PowerOnVm', 'QueryConfigOptionDescriptor', 'QueryConnectionInfo', 'Reconfigure', 'ReconfigureDatacenter_Task', 'Reload', 'Rename', 'Rename_Task', 'SetCustomValue', '_GetMethodInfo', '_GetMethodList', '_GetMoId', '_GetPropertyInfo', '_GetPropertyList', '_GetServerGuid', '_GetStub', '_InvokeAccessor', '_InvokeMethod', '__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_methodInfo', '_moId', '_propInfo', '_propList', '_serverGuid', '_stub', '_version', '_wsdlName', 'alarmActionsEnabled', 'availableField', 'configIssue', 'configStatus', 'configuration', 'customValue', 'datastore', 'datastoreFolder', 'declaredAlarmState', 'disabl
@michaelrice
michaelrice / gist:546b38b06e51b35de9a6
Created October 14, 2014 18:47
pyVmomi licensableResource
>>> children = content.rootFolder.childEntity
>>> hosts = children[0].hostFolder.childEntity
>>> hosts[0].host[0].licensableResource
(vim.LicenseManager.LicensableResourceInfo) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
resource = (vmodl.KeyAnyValue) [
(vmodl.KeyAnyValue) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
List buildRDMInformation(Inventory inventory) {
// To store the RDM information
List rdmInfos = []
// For each VM in the inventory
inventory.vms.each { vm ->
// Get the host
Host h = (Host) vm.host