Snapshot management of VMware API development

Source: Internet
Author: User

Companies to develop their own private cloud management platform, I am responsible for the VMware part of the background interface writing.

Mainly based on the VMware official Python interface Pyvmomi for two packages,

The main realization has the virtual machine switch machine logoff;

Virtual Machine Additions and deletions disk;

Virtual machine snapshot additions and deletions restore;

Console interface for virtual machine HTML5

Virtual Machine Network Management

Zabbix Monitoring ESXi Disk utilization

Zabbix Accept forwarding of ESXi alarm information

This article shows the snapshot function, snapshot is actually a very small function, mainly to let you understand the next VMware snapshot interface, the internet did not do me this thing, the middle of a traversal algorithm

First

1 Actual effect

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/83/84/wKiom1d02gezzSlhAABXB-vAUkU642.png-wh_500x0-wm_3 -wmp_4-s_3724801962.png "style=" Float:none; "title=" 111111.png "alt=" wkiom1d02gezzslhaabxb-vauku642.png-wh_50 "/ >

2, the actual data


650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/83/83/wKioL1d02gfTbF6_AACK_4GmMA4538.png-wh_500x0-wm_3 -wmp_4-s_957658005.png "style=" Float:none; "title=" 22222.png "alt=" Wkiol1d02gftbf6_aack_4gmma4538.png-wh_50 "/>

The code is as follows

From Pyvmomi import vim

From Pyvim.connect import Smartconnect, Disconnect

Import atexit

Import Argparse

Import Getpass

Import SSL

Import Random

Import CGI, CGITB

Import Sys

Import JSON



def wait_for_task (Task):

"" "Wait for a vCenter task to finish" "

Task_done = False

While not task_done:

if task.info.state = = ' Success ':

Return Task.info.result


if task.info.state = = ' ERROR ':

Print ("There is an error")

Task_done = True

form = CGI. Fieldstorage ()

vmnames= form.getvalue (' IP ')


Si = None

context = SSL. Sslcontext (SSL. PROTOCOL_TLSV1)

Context.verify_mode = SSL. Cert_none

Si = Smartconnect (host= "10.20.11.3",

User= "Root",

Pwd= "VMware",

port=443,

Sslcontext=context)

Atexit.register (Disconnect, si)

Content = Si. Retrievecontent ()


container = Content.viewManager.CreateContainerView (Content.rootfolder, [vim]. Virtualmachine], True)

For C in Container.view:

if c.name = = Vmnames:

obj = C

Break


Try

Obj.name

Except Exception as E:

res={' status ': ' Failed ', ' result ': ' IP is not found '}

BODY = Json.dumps (res)

Print ("status:200 OK")

Print ("Content-type:application/json")

Print ("Content-length:%d"% (len (body)))

Print ("")

Print (RES)

Sys.exit ()


Output=[]

#遍历快照的树状结构 Note To set the global variable

def showlist (snapshot):


Global output


Output.append ({Snapshot.snapshot:[snapshot.name,snapshot.createtime.timestamp ()]})


For I in Snapshot.childsnapshotlist:

Showlist (i)


Snapshot management of VMware API development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.