Code Monkey home page Code Monkey logo

pyvmomi-community-samples's Introduction

Build Status

pyvmomi-community-samples

Community contributed samples for the pyVmomi library.

The pyVmomi library itself is hosted here: https://github.com/vmware/pyvmomi/

The community samples website is here: http://vmware.github.io/pyvmomi-community-samples/

The samples contained here in are provided as-is from contributors around the pyVmomi community. They are intended as learning tools and may vary in quality. Any developer may contribute, enhance, or alter the samples. Ownership of any submitted sample reverts to the project itself

Philosophy

  • Sample Ownership and Copyright Licenses

    • the community creates the samples and the project retains ownership of the samples
    • the community curates the samples and licenses the samples under the project license
      • all samples are distributed under the root project license
      • A copyright line may be added if you contribute a change of more than 10 lines
  • Writing good samples:

    • A good sample shows how to do one thing and only one thing at a time.
    • A good sample follows good and consistent code style see: pep8.
    • When arbitrary choices are made, a good sample chooses the simplest default.
    • Samples must be willing to teach programming as well as the API!

Code Style

Please conform to pep8 standards. Check your code by running the pycodestyle tool. https://pypi.python.org/pypi/pycodestyle

Contribution Process

  • Follow the GitHub process
    • please use one branch per sample or change-set
    • please use one commit and pull request per sample
    • if you include a license with your sample, use the project license

pyvmomi-community-samples's People

Contributors

abdul-anshad-a avatar appsalar avatar chupman avatar cpaggen avatar ddcrjlalumiere avatar deagon avatar eagleeggs avatar exaneserverteam avatar ghostofgoes avatar hartsock avatar jlhasson avatar jm66 avatar jonathandye avatar kumahesh avatar lamw avatar ldfsilva avatar luckylau avatar mriehl avatar mxmader avatar pathcl avatar pgbidkar avatar pietervogelaar avatar prziborowski avatar reubenur-rahman avatar saad-cliqr avatar swamycnn avatar tatankat avatar tianhao64 avatar xpu22 avatar yasensim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyvmomi-community-samples's Issues

Sample: vMotion

Demonstrate vMotion feature moving a virtual machine identified by its UUID from one ESXi Host to another ESXi Host.

Sample: create a template

Demonstrate how to create a vCenter Template using a provided virtual machine. The virtual machine should be identified by UUID and should be unharmed by the process.

Unresolved import: vmodl

When using Eclipse PyDev, in many samples (e.g. getallvms.py) the line:
from pyVmomi import vmodl

results in the error marker:
Unresolved import: vmodl

Is there any way to resolve this without error?

Sample: find a VM using FindByDatastorePath

Demonstrate how to figure out a Virtual Machine's datastore path during create, save the path, and then use that path to find the VM again later. This can be a valuable tool in systems that are focused on Datastore and storage as their primary focus in creating, managing, and moving around Virtual Machines.

In particular the Nova driver on OpenStack does this a lot and could use some clean samples around that work flow.

Problem in assigning network for NIC

error
HI,

host.network returns me a list of available networks on the particular host out of which some are standard and some dvs .

Now with this networks when I am adding or editing NICs I am facing problem for dvs networks. If I right click and see the network settings I find the network label is not getting selected. Where as for standard networks the NIC network label is getting selected.

I have tried to change nicspec.device.backing.network = get_obj(content, [vim.Network], net_name) to nicspec.device.backing.network = get_obj(content, [vim.dvs.DistributedVirtualPortgroup], net_name) . But no luck !

What I am doing is given below :

        nicspec = vim.vm.device.VirtualDeviceSpec()
        nicspec.operation = vim.vm.device.VirtualDeviceSpec.Operation.add
        nicspec.device = vim.vm.device.VirtualVmxnet3()
        nicspec.device.wakeOnLanEnabled = True
        nicspec.device.deviceInfo = vim.Description()
        nicspec.device.deviceInfo.label = net_name
        nicspec.device.deviceInfo.summary = net_name             
        nicspec.device.backing = vim.vm.device.VirtualEthernetCard.NetworkBackingInfo()
        nicspec.device.backing.network = get_obj(content, [vim.Network], net_name)
        #self.logger.debug ("Assigning network %s for NIC" % net_name)
        nicspec.device.backing.deviceName = net_name
        nicspec.device.connectable = vim.vm.device.VirtualDevice.ConnectInfo()
        nicspec.device.connectable.startConnected = True
        nicspec.device.connectable.allowGuestControl = True

Sample: change a guest OS password

Show interacting with a Guest OS and changing its administrator password. You should provide code for either Linux or Windows based guest operating systems.

Sample: restore to a snapshot

Demonstrate how to restore a virtual machine to a named snapshot. The virtual machine should be identified by a UUID, list available snapshots, prompt the user to select the appropriate snapshot to restore to.

Sample: place a file on a datastore

Demonstrate how to place an arbitrary file in an arbitrary location on an arbitrary datastore. Shows how to interact with datastores using pyVmomi API and should include discussion and solutions for keep-alive problems when dealing with very large file transfers.

Issues to show resolutions to:

  • File transport occurs on a separate session from API method invocation
  • Network conditions are not always favorable, how to handle interruptions
  • How to detect file corruption or incomplete transfer
  • How to detect failed file transfers due to permissions issues.

See also: http://www.virtuallyghetto.com/2014/06/how-to-efficiently-transfer-files-to-datastore-in-vcenter-using-the-vsphere-api.html

Sample: query user permissions

Demonstrate how to query the current user's permissions for a given Managed Object. Show how to determine if the user has a specific privilege to read or write to a named datastore for example.

How do I get the vminfo quicker.

We have around 1500 VM's perc vCenter and around 10vCenter's globally.

To get the particular VM info, I am doing this and it is taking really a long time.

container = content.viewManager.CreateContainerView(content.rootFolder, [vim.VirtualMachine], True)
for c in container.view:
if c.name == name:
yourvm = c
break
return yourvm

.......
Retrieving the info from the object like before
print yourvm.runtime.powerState()
.......and more info

Is there anyway to hit the vm directly and get the info without traversing exhaustively ?

Sample: find a resource pool based on search criteria

By default list all the resource pools on a vCenter server (or ESXi host) or alternatively filter the list of resource pools displayed by some criteria. Display resource pool statistics such as number of vCpu, amount of vRAM, or amount and type of disk storage available in each resource pool.

Bonus: also display DRS and other feature status for a Resource Pool / Cluster.

Sample: connect to an iSCSI device

  • Demonstrate how to connect an ESXi host to an iSCSI device.
  • Demonstrate connecting a virtual machine to a VMDK on the iSCI device.
  • Demonstrate connecting a VM to an iSCI device.

Set Affinity rule on a particular VM to stop DRS

Based on: vmware/pyvmomi#25

The equivalent Java Code I found :

    ClusterAffinityRuleSpec cars = new ClusterAffinityRuleSpec();
    cars.setName("App and DB Appliance Bundle");
    cars.setEnabled(Boolean.TRUE);
    ManagedObjectReference vm1 = createMOR("VirtualMachine", vm1_oid);
    ManagedObjectReference vm2 = createMOR("VirtualMachine", vm2_oid);
    cars.setVm(new ManagedObjectReference[] {vm1, vm2});

Author a pyVmomi sample that accomplishes the same or similar.

Sample: Import ova

Based on: vmware/pyvmomi#12

Demonstrate the full process of obtaining an OVA and then uploading the OVA into a connected vSphere environment. Do this with pyVmomi and show how to access the OVF Manager.

Apache 2 license for all.

We need all samples to be listed under the Apache 2 license. That means we need to edit all files to get conflicting licenses stripped or we need to kick those samples out.

Sample: change the IP address of a guest OS

Demonstrate interacting with a Linux and/or Windows guest OS to set the IP address on one or more VIF and PIF attached to the VM. Demonstrate how to query the IP associated with a VM.

Sample: ESXi Host IP addresses

Create a sample that properly queries an ESXi host for it's IP addresses and highlights the management IP address and network for the user.

Sample: login to guest example

Create some simple sample that addresses requests like
vmware/pyvmomi#22

And formalizes...

# executes /bin/touch /tmp/hello.txt
cmdspec = pyVmomi.vim.vm.guest.ProcessManager.ProgramSpec(arguments='/tmp/hello.txt', programPath='/bin/touch')

# cmdoutput returns a pid
cmdoutput = si.content.guestOperationsManager.processManager.StartProgramInGuest(vm=vm, auth=creds, spec=cmdspec)

Sample: Virtual Machine boot from ISO

A sample that builds a Virtual Machine with a blank VMDK. The script should transfer the ISO from the local file system to the appropriate datastore then boot the VM with the ISO. Presumably users of such a script could supply an ISO that would auto install a guest OS onto the VMDK and that's the intention of this sample, to show each discrete step of accomplishing that task.

create_random_marvel_vms.py: fails randomly.

rootFolder may contain vim.Folder and multiple vim.DataCenter objects

https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/create_random_marvel_vms.py#L210

On vCenter servers that have a vim.Folder under rootFolder this sample will fail with...

Traceback (most recent call last):
  File "./create_random_marvel_vms.py", line 233, in <module>
    main()
  File "./create_random_marvel_vms.py", line 211, in main
    vmFolder = datacenter.vmFolder
AttributeError: 'vim.Folder' object has no attribute 'vmFolder'

On vCenter servers with more than one Datacenter object this sample will operate on semi-random datacenter objects if vCenter shifts the natural order of the Datacenter objects (datacenter ordinality is not guaranteed).

Sample: show uses for EventHistoryCollector

We don't have many samples demonstrating the use of Events. I would like to see a sample that allowed a script to listen for multiple VM power on events and take action on the VM power on events asynchronously.

What I mean by that is in the sample create/find 3 VM. Power them on 1, 2, 3 and if 2 powers up first do something to it (like touch a guest file or answer a VM question or something) then go back to listening for 1 and 3's finished power on task.

Sample: cold migration

Demonstrate moving a VM from one ESXi Host to another ESXi Host without using vMotion features. Demonstrate a cold migration.

Sample: Destroy multiple virtual machines based on name

Virtual Machines made by the marvel comics sample will all have the same name pattern, create a sample that finds and deletes virtual machines created by the other sample. Finding names that start with Marvel is a good example.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.