简体   繁体   English

有没有一种方法可以通过PyVMomi在VMWare服务器上执行Shell命令

[英]Is there a way to execute shell commands on VMWare server via PyVMomi

I am looking to take full advantage of the recently introduce pyvmomi module to further management and I would like to remove the use of ssh and convert utility calls through the API; 我希望充分利用最近引入的pyvmomi模块来进一步管理,并且我想删除ssh的使用并通过API转换实用程序调用; Is this possible? 这可能吗?

Sorry for the slow reply! 很抱歉回复缓慢! I found your Q looking for some info on this myself. 我发现您的Q希望自己提供一些信息。 In vSphere 5 and above there is a provision to run commands as long as you are a registered user on the system (and can abide by the authentication mechanisms). 在vSphere 5及更高版本中,只要您是系统上的注册用户,就可以运行命令(并且可以遵守身份验证机制)。

If you are a Pythonista life is going to get semi-easy for you! 如果您是Pythonista使用者,生活将变得轻松愉快! There is a beautiful module called Pyvmomi - https://github.com/vmware/pyvmomi 有一个名为Pyvmomi的漂亮模块-https: //github.com/vmware/pyvmomi

This allows easy communication with the API of vSphere. 这样可以轻松与vSphere API进行通信。

The steps are: 这些步骤是:

  • Create a Connection (SmartConnect) and it is wise to use an atexit to destroy! 创建一个连接(SmartConnect),明智的方法是使用atexit销毁它!
  • Get the content from the API 从API获取内容
  • Find the VM you want to run on 查找您要在其上运行的VM
  • Create/Prepare the command 创建/准备命令
  • Fire the command 发射命令
  • Verify the process is alive and get the data back 验证该过程是否仍在进行中并取回数据

There are many samples in the community samples page at https://github.com/vmware/pyvmomi-community-samples that will wet your apitite! https://github.com/vmware/pyvmomi-community-samples上的社区样本页面中有许多样本,它们会弄湿您的apitite!

I have tried getting this functionality in lower versions of vSphere but found I really had to abuse the console API - sadly that code has become propriety now so I cannot share :-( 我曾尝试在较低版本的vSphere中获得此功能,但发现我确实不得不滥用控制台API-可悲的是,代码现在变得专有了,所以我无法共享:-(

Happy Automating! 快乐的自动化! //P // P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM