Skip to content

Instantly share code, notes, and snippets.

View hartsock's full-sized avatar

Shawn Hartsock hartsock

View GitHub Profile
@hartsock
hartsock / vsphere_current_session.py
Last active August 29, 2015 13:56
A quick and dirty python SUDS script that shows how to get the current session ID using the vSphere API
#!/usr/bin/python
import argparse
import suds
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--host', required=True, action='store', help='Remote host to connect to')
parser.add_argument('-u', '--user', required=True, action='store', help='User name to use when connecting to host')
parser.add_argument('-p', '--password', required=True, action='store', help='Password to use when connecting to host')
args = parser.parse_args()
@hartsock
hartsock / share_sessions_between_pyvmomi_and_suds
Created March 11, 2014 22:27
Here's a quick and dirty script that proves you can share a session between pyVmomi and SUDS clients in either direction. Here's how.
#!/usr/bin/python
import argparse
import cookielib
import suds
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--host', required=True, action='store', help='Remote host to connect to')
parser.add_argument('-u', '--user', required=True, action='store', help='User name to use when connecting to host')
parser.add_argument('-p', '--password', required=True, action='store', help='Password to use when connecting to host')
@hartsock
hartsock / pyvmomi-to-suds.py
Last active August 29, 2015 13:57
Move a session started in pyvmomi to a suds client.
#!/usr/bin/python
import argparse
import cookielib
import suds
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--host',
required=True,
action='store',
@hartsock
hartsock / session_from_pyvmomi_to_suds.py
Last active August 29, 2015 13:57
Login with pyVmomi (any technique) and use it with SUDS
#!/usr/bin/python
import argparse
import cookielib
import suds
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--host',
required=True,
action='store',
#!/usr/bin/env ruby
#
# Convert blogger (blogspot) posts to jekyll posts
#
# Basic Usage
# -----------
#
# ./blogger_to_jekyll.rb feed_url
#
# where `feed_url` can have the following format:
@hartsock
hartsock / renamer.py
Created June 5, 2014 17:08
pyVmomi sample (no dependencies) that demonstrates working with tasks
#!/usr/bin/env python
# VMware vSphere Python SDK
# Copyright (c) 2008-2013 VMware, Inc. All Rights Reserved.
#
# 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
#
@hartsock
hartsock / tasks_different_styles.txt
Created June 9, 2014 22:10
Output of based on power-cycling the vms generated by the Marvel VM sample.
/Users/hartsocks/Virtualenvs/cli/bin/python /Users/hartsocks/PycharmProjects/pyvmomi-tools/samples/tasks_different_styles.py -s 192.168.2.11 -u root -p vmware -n MARVEL
using wait_for_updates
Found VirtualMachine: 'vim.VirtualMachine:vm-748' Name: MARVEL-Serpent_Society
power on
power off
Found VirtualMachine: 'vim.VirtualMachine:vm-746' Name: MARVEL-Hepzibah
power on
power off
Found VirtualMachine: 'vim.VirtualMachine:vm-741' Name: MARVEL-Mach_IV
power on
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim, vmodl
# this script is intended to be run against all vcenters daily in order to
# guard against a possible vcenter crash due to alarms with an unset status.
# it prints all alarms with Trigger events w/ an "Unset" status.
# this bug is detailed at http://kb.vmware.com/kb/2062989
user = "username"
pwd = "password"
require 'rubygems'
require 'nokogiri'
require 'fileutils'
require 'date'
require 'uri'
# usage: ruby import.rb my-blog.xml
# my-blog.xml is a file from Settings -> Basic -> Export in blogger.
data = File.read ARGV[0]
@hartsock
hartsock / link.py
Created June 26, 2014 17:42
A problematic snippet of Python 2.6 code I need to port to Python 3