Skip to content

Instantly share code, notes, and snippets.

View michaelrice's full-sized avatar

Michael Rice michaelrice

View GitHub Profile
@michaelrice
michaelrice / dirty_work_around.patch
Created May 7, 2015 19:53
dirty work around to make python 2.7.9 work for pyvmomi
diff --git a/samples/hello_world_vcenter.py b/samples/hello_world_vcenter.py
index 1320d05..eafa840 100755
--- a/samples/hello_world_vcenter.py
+++ b/samples/hello_world_vcenter.py
@@ -22,6 +22,19 @@ a friendly encouragement to joining the community!
import atexit
import argparse
import getpass
+import requests
+requests.packages.urllib3.disable_warnings()
#!/bin/bash
enums=$(grep -R "public enum" src/main/*|awk '{print $3}')
for enum in ${enums[@]}
do
grep -R ${enum} src/main/java/com/vmware/vim25/mo/*
done
#!/usr/bin/env perl
use warnings;
use strict;
my $file = "VimStub.java";
my @method_names = ();
open FILE, $file or die $!;
while(<FILE>) {
if( $_ =~ /public \w+\b (.*)\(/g) {
#print $1."\n";
// Set the resource pool
ResourcePool rp
if (build.resourcePool) {
rp = (ResourcePool) new InventoryNavigator(rootFolder).searchManagedEntity("ResourcePool", build.resourcePool)
if (rp == null) {
throw new ProvisioningException(
"Could not find the user-provided ResourcePool " +
"${build.resourcePool}.")
}
@michaelrice
michaelrice / decom.groovy
Created April 29, 2015 14:30
remove host from vcenter
boolean removeHostFromVCenter() {
try {
// This only works on a HostSystem that is a member of a cluster.
return hostSystem.destroy_Task().waitForMe().equals(Task.SUCCESS)
}
catch (NotSupported ns) {
// If the host parent is a ComputeResource destroy it.
// That means its a stand alone hostsystem.
if (hostSystem.parent.class.equals(ComputeResource.class)) {
log.debug("Stand alone HostSystem found. Destroying ComputeResource to remove from vCenter.")
@michaelrice
michaelrice / ClusterPropExample.java
Last active August 29, 2015 14:19
ClusterPropExample
package com.toastcoders;
import com.vmware.vim25.*;
import com.vmware.vim25.mo.*;
import java.net.URL;
/**
* Copyright 2015 Michael Rice <[email protected]>
* <p/>
foo
https://10.5.200.142/sdk bar.foo.thing
https://11.22.33.44/sdk baz.bar.com
----------
thing
https://10.22.33.44/sdk some.things.com
----------
@michaelrice
michaelrice / configure_vcsa.sh
Created March 21, 2015 23:53
VCSA Configration
#!/bin/bash
# See the original work from William Lam at http://www.virtuallyghetto.com/
## DO NOT EDIT BEYOND HERE ##
echo "Accepting EULA ..."
/usr/sbin/vpxd_servicecfg eula accept
echo "Setting default ports ..."
# Copyright 2015 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,
public void lookupVmsByDataCenterRoot(Folder datacenterRoot, ServiceInstance si){
// Get the pcMOR MOR
ManagedObjectReference pcMOR = datacenterRoot.serverConnection.getServiceInstance().getPropertyCollector().getMOR()
// Get the root folder MOR
ManagedObjectReference dcRootFolder = datacenterRoot.MOR
// Create the property list
def props = ["name", "runtime.powerState", "config.template", "runtime.connectionState"]