SlideShare una empresa de Scribd logo
1 de 15
Windows 安裝 ptyhon 控制 VMWare API
20210201
Python 是一種跨平台程式語言。
目的:接到一個任務要對 VMware 下 API 接令 ; 而 API 是 python 程式
環境安裝:
1. 安裝 python
網站下載所要的版本 https://www.python.org/downloads/
以版本 3.8.6 為例
https://www.python.org/downloads/release/python-386/
…..就裝完了
試跑 IDLE
2. 安裝 python 需要的 pip
Pip 是 python 安裝套件 模組的功能
https://bootstrap.pypa.io/get-pip.py
下載存檔
執行
點兩下後很快跑完就不見了
3. 安裝 git
VMWARE API 在 github
VMware vSphere Automation SDK for Python
但先需要 git 程式 , 所以先裝 git
https://git-scm.com/download/win
執行…………..一直下一步
Npp 很好用就指定它為預設編輯, 如果沒有 npp 就先裝 npp ( https://notepad-
plus-plus.org/downloads/ )
接著下一步到結束
到 github
https://github.com/vmware/vsphere-automation-sdk-python
開啟 cmd 把以下兩行貼上
pip install --upgrade pip setuptools
pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk-
python.git
如果 pip 或 python 沒有跑起來 應該是 OS path 沒有自動被加去
自已加路徑或是切到以下路徑
4. 試連 vCenter
開啟 python
貼上以下 [需自行修改 vcenter ip username / password]
import requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client
session = requests.session()
# Disable cert verification for demo purpose.
# This is not recommended in a production environment.
session.verify = False
# Disable the secure connection warning for demo purpose.
# This is not recommended in a production environment.
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Connect to a vCenter Server using username and password
vsphere_client = create_vsphere_client(server='192.168.100.101',
username='administrator@vsphere.local', password='P@ssw0rd', session=session)
# List all VMs inside the vCenter Server
vsphere_client.vcenter.VM.list()
vsphere_client.vcenter.VM.list() 會列出現行系統 VM 列表
例:列出 VM FREENAS 資源狀態
client.vcenter.VM.list(client.vcenter.VM.FilterSpec(names={'FREENAS'}))
接著就依自行需要執行 python API
備註:
Python 程序副檔為.py 可以命令列方式行
Windows 環境變數 PATH 如果不在請自行手動加。
http://code.vmware.com/ > API Explorer https://developer.vmware.com/ 有完整
API

Más contenido relacionado

La actualidad más candente

Network Virtualization
Network VirtualizationNetwork Virtualization
Network Virtualization
ADVA
 
ITLC Hanoi - Triển khai ceph hướng tới Cloud Storage và hỗ trợ OpenStack - du...
ITLC Hanoi - Triển khai ceph hướng tới Cloud Storage và hỗ trợ OpenStack - du...ITLC Hanoi - Triển khai ceph hướng tới Cloud Storage và hỗ trợ OpenStack - du...
ITLC Hanoi - Triển khai ceph hướng tới Cloud Storage và hỗ trợ OpenStack - du...
Le Cuong
 

La actualidad más candente (20)

HPE SimpliVity 升級 4.1.0
HPE SimpliVity 升級 4.1.0HPE SimpliVity 升級 4.1.0
HPE SimpliVity 升級 4.1.0
 
Deep Dive on GSLB with VMware NSX Advanced Load Balancer (Avi Networks)
Deep Dive on GSLB with VMware NSX Advanced Load Balancer (Avi Networks)Deep Dive on GSLB with VMware NSX Advanced Load Balancer (Avi Networks)
Deep Dive on GSLB with VMware NSX Advanced Load Balancer (Avi Networks)
 
VMware vSphere Networking deep dive
VMware vSphere Networking deep diveVMware vSphere Networking deep dive
VMware vSphere Networking deep dive
 
Upgrade to IBM z/OS V2.4 planning
Upgrade to IBM z/OS V2.4 planningUpgrade to IBM z/OS V2.4 planning
Upgrade to IBM z/OS V2.4 planning
 
VMware vSphere Performance Troubleshooting
VMware vSphere Performance TroubleshootingVMware vSphere Performance Troubleshooting
VMware vSphere Performance Troubleshooting
 
20220224台中演講k8s
20220224台中演講k8s20220224台中演講k8s
20220224台中演講k8s
 
VMworld 2017 vSAN Network Design
VMworld 2017 vSAN Network Design VMworld 2017 vSAN Network Design
VMworld 2017 vSAN Network Design
 
VxRail_7.0.x_管理員手冊.en.zh-TW.docx
VxRail_7.0.x_管理員手冊.en.zh-TW.docxVxRail_7.0.x_管理員手冊.en.zh-TW.docx
VxRail_7.0.x_管理員手冊.en.zh-TW.docx
 
Virtualization Architecture & KVM
Virtualization Architecture & KVMVirtualization Architecture & KVM
Virtualization Architecture & KVM
 
Turning Virtual Machines Cloud-Native using KubeVirt
Turning Virtual Machines Cloud-Native using KubeVirtTurning Virtual Machines Cloud-Native using KubeVirt
Turning Virtual Machines Cloud-Native using KubeVirt
 
Infrastructure as Code Maturity Model v1
Infrastructure as Code Maturity Model v1Infrastructure as Code Maturity Model v1
Infrastructure as Code Maturity Model v1
 
Emc data domain technical deep dive workshop
Emc data domain  technical deep dive workshopEmc data domain  technical deep dive workshop
Emc data domain technical deep dive workshop
 
VMware Advance Troubleshooting Workshop - Day 2
VMware Advance Troubleshooting Workshop - Day 2VMware Advance Troubleshooting Workshop - Day 2
VMware Advance Troubleshooting Workshop - Day 2
 
Network Virtualization
Network VirtualizationNetwork Virtualization
Network Virtualization
 
Veeam Presentation
Veeam PresentationVeeam Presentation
Veeam Presentation
 
Présentation de JEE et de son écosysteme
Présentation de JEE et de son écosystemePrésentation de JEE et de son écosysteme
Présentation de JEE et de son écosysteme
 
Docker, LinuX Container
Docker, LinuX ContainerDocker, LinuX Container
Docker, LinuX Container
 
ITLC Hanoi - Triển khai ceph hướng tới Cloud Storage và hỗ trợ OpenStack - du...
ITLC Hanoi - Triển khai ceph hướng tới Cloud Storage và hỗ trợ OpenStack - du...ITLC Hanoi - Triển khai ceph hướng tới Cloud Storage và hỗ trợ OpenStack - du...
ITLC Hanoi - Triển khai ceph hướng tới Cloud Storage và hỗ trợ OpenStack - du...
 
Red Hat Enterprise Virtualization
Red Hat Enterprise VirtualizationRed Hat Enterprise Virtualization
Red Hat Enterprise Virtualization
 
Design Best Practices for High Availability in Load Balancing
Design Best Practices for High Availability in Load BalancingDesign Best Practices for High Availability in Load Balancing
Design Best Practices for High Availability in Load Balancing
 

Similar a Windows 環境下建構python 跑VMware API

Using google appengine_final
Using google appengine_finalUsing google appengine_final
Using google appengine_final
Wei Sun
 
03.python工作环境
03.python工作环境03.python工作环境
03.python工作环境
modou li
 
Using google appengine_1027
Using google appengine_1027Using google appengine_1027
Using google appengine_1027
Wei Sun
 
Using google appengine (2)
Using google appengine (2)Using google appengine (2)
Using google appengine (2)
Wei Sun
 
2020 gops-旷视城市大脑私有云平台实践-刘天伟
2020 gops-旷视城市大脑私有云平台实践-刘天伟2020 gops-旷视城市大脑私有云平台实践-刘天伟
2020 gops-旷视城市大脑私有云平台实践-刘天伟
Tianwei Liu
 
轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)
FLASH开发者交流会
 
自动化运维管理
自动化运维管理自动化运维管理
自动化运维管理
frankwsj
 
设置用vim编辑python
设置用vim编辑python设置用vim编辑python
设置用vim编辑python
King Hom
 
腾讯大讲堂58 拍拍app platform中间件解决方案简介
腾讯大讲堂58 拍拍app platform中间件解决方案简介腾讯大讲堂58 拍拍app platform中间件解决方案简介
腾讯大讲堂58 拍拍app platform中间件解决方案简介
areyouok
 
Python和web开发
Python和web开发Python和web开发
Python和web开发
moonbingbing
 

Similar a Windows 環境下建構python 跑VMware API (20)

Python meetup 1
Python meetup 1Python meetup 1
Python meetup 1
 
LineBot.pptx
LineBot.pptxLineBot.pptx
LineBot.pptx
 
如何幫樹莓派安裝常用的Python套件(How to Install Python Package on Raspberry Pi)
如何幫樹莓派安裝常用的Python套件(How to Install Python Package on Raspberry Pi)如何幫樹莓派安裝常用的Python套件(How to Install Python Package on Raspberry Pi)
如何幫樹莓派安裝常用的Python套件(How to Install Python Package on Raspberry Pi)
 
容器驅動開發 - .NET Conf 2017 @ 台中
容器驅動開發 - .NET Conf 2017 @ 台中容器驅動開發 - .NET Conf 2017 @ 台中
容器驅動開發 - .NET Conf 2017 @ 台中
 
Bitbucket pipeline CI
Bitbucket pipeline CIBitbucket pipeline CI
Bitbucket pipeline CI
 
Using google appengine_final
Using google appengine_finalUsing google appengine_final
Using google appengine_final
 
11132020_python tutor.pdf
11132020_python tutor.pdf11132020_python tutor.pdf
11132020_python tutor.pdf
 
03.python工作环境
03.python工作环境03.python工作环境
03.python工作环境
 
Using google appengine_1027
Using google appengine_1027Using google appengine_1027
Using google appengine_1027
 
Using google appengine (2)
Using google appengine (2)Using google appengine (2)
Using google appengine (2)
 
常用开发工具介绍
常用开发工具介绍常用开发工具介绍
常用开发工具介绍
 
2020 gops-旷视城市大脑私有云平台实践-刘天伟
2020 gops-旷视城市大脑私有云平台实践-刘天伟2020 gops-旷视城市大脑私有云平台实践-刘天伟
2020 gops-旷视城市大脑私有云平台实践-刘天伟
 
轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)轻量级Flash服务器开发框架(刘恒)
轻量级Flash服务器开发框架(刘恒)
 
自动化运维管理
自动化运维管理自动化运维管理
自动化运维管理
 
设置用vim编辑python
设置用vim编辑python设置用vim编辑python
设置用vim编辑python
 
EOS_2015_Fall Team6 - One to Ten App Design Toolkit
EOS_2015_Fall  Team6 - One to Ten App Design ToolkitEOS_2015_Fall  Team6 - One to Ten App Design Toolkit
EOS_2015_Fall Team6 - One to Ten App Design Toolkit
 
腾讯大讲堂58 拍拍app platform中间件解决方案简介
腾讯大讲堂58 拍拍app platform中间件解决方案简介腾讯大讲堂58 拍拍app platform中间件解决方案简介
腾讯大讲堂58 拍拍app platform中间件解决方案简介
 
Python和web开发
Python和web开发Python和web开发
Python和web开发
 
100902 wm4wps-py-webdev
100902 wm4wps-py-webdev100902 wm4wps-py-webdev
100902 wm4wps-py-webdev
 
如何更新 I puppy 的韌體?
如何更新 I puppy 的韌體?如何更新 I puppy 的韌體?
如何更新 I puppy 的韌體?
 

Más de 裝機安 Angelo

Más de 裝機安 Angelo (15)

DELL PowerStore 相關主題中譯本
DELL PowerStore 相關主題中譯本DELL PowerStore 相關主題中譯本
DELL PowerStore 相關主題中譯本
 
Dell VxRail Dynamic Node 設定記錄-7.0.410.pdf
Dell VxRail Dynamic Node 設定記錄-7.0.410.pdfDell VxRail Dynamic Node 設定記錄-7.0.410.pdf
Dell VxRail Dynamic Node 設定記錄-7.0.410.pdf
 
Dell AppSync整合與實現應用程式資料複本管理
Dell AppSync整合與實現應用程式資料複本管理Dell AppSync整合與實現應用程式資料複本管理
Dell AppSync整合與實現應用程式資料複本管理
 
DELL CloudIQ 幫助MIS小克一手掌握IT維運 .docx
DELL CloudIQ 幫助MIS小克一手掌握IT維運 .docxDELL CloudIQ 幫助MIS小克一手掌握IT維運 .docx
DELL CloudIQ 幫助MIS小克一手掌握IT維運 .docx
 
vsphere-esxi-vcenter-server-703-storage-guide-中文.pdf
vsphere-esxi-vcenter-server-703-storage-guide-中文.pdfvsphere-esxi-vcenter-server-703-storage-guide-中文.pdf
vsphere-esxi-vcenter-server-703-storage-guide-中文.pdf
 
VxRail_7.0.x_管理員手冊.pdf
VxRail_7.0.x_管理員手冊.pdfVxRail_7.0.x_管理員手冊.pdf
VxRail_7.0.x_管理員手冊.pdf
 
Dell EMC PowerStore: PowerStore Manager 概述
Dell EMC PowerStore: PowerStore Manager 概述Dell EMC PowerStore: PowerStore Manager 概述
Dell EMC PowerStore: PowerStore Manager 概述
 
需求VMWARE架構下就是要建兩邊可以嗎?
需求VMWARE架構下就是要建兩邊可以嗎?需求VMWARE架構下就是要建兩邊可以嗎?
需求VMWARE架構下就是要建兩邊可以嗎?
 
vSAN7 關機
vSAN7 關機vSAN7 關機
vSAN7 關機
 
(2021-01).UT-商品-企業-訊息-技EDM-2021-1-Dell EMC RP4VM VM保護備份
(2021-01).UT-商品-企業-訊息-技EDM-2021-1-Dell EMC RP4VM VM保護備份(2021-01).UT-商品-企業-訊息-技EDM-2021-1-Dell EMC RP4VM VM保護備份
(2021-01).UT-商品-企業-訊息-技EDM-2021-1-Dell EMC RP4VM VM保護備份
 
(2021-03).UT-商品-企業-訊息-技EDM-2021-3-Dell EMC Avamar VM保護備份
(2021-03).UT-商品-企業-訊息-技EDM-2021-3-Dell EMC Avamar VM保護備份(2021-03).UT-商品-企業-訊息-技EDM-2021-3-Dell EMC Avamar VM保護備份
(2021-03).UT-商品-企業-訊息-技EDM-2021-3-Dell EMC Avamar VM保護備份
 
(2020-02)HPE SimpliVity 安裝設定管理的影片網站
(2020-02)HPE SimpliVity 安裝設定管理的影片網站(2020-02)HPE SimpliVity 安裝設定管理的影片網站
(2020-02)HPE SimpliVity 安裝設定管理的影片網站
 
(2020-06)HPE SimpliVity 開放資源網站
(2020-06)HPE SimpliVity 開放資源網站(2020-06)HPE SimpliVity 開放資源網站
(2020-06)HPE SimpliVity 開放資源網站
 
HPE SimpliVity 使用PowerShell 控制
HPE SimpliVity 使用PowerShell 控制HPE SimpliVity 使用PowerShell 控制
HPE SimpliVity 使用PowerShell 控制
 
2019-HPE Infosight AI智能雲平台功能解析1-7篇
2019-HPE Infosight AI智能雲平台功能解析1-7篇2019-HPE Infosight AI智能雲平台功能解析1-7篇
2019-HPE Infosight AI智能雲平台功能解析1-7篇
 

Windows 環境下建構python 跑VMware API

  • 1. Windows 安裝 ptyhon 控制 VMWare API 20210201 Python 是一種跨平台程式語言。 目的:接到一個任務要對 VMware 下 API 接令 ; 而 API 是 python 程式 環境安裝: 1. 安裝 python 網站下載所要的版本 https://www.python.org/downloads/
  • 3.
  • 5. 2. 安裝 python 需要的 pip Pip 是 python 安裝套件 模組的功能 https://bootstrap.pypa.io/get-pip.py
  • 7. 點兩下後很快跑完就不見了 3. 安裝 git VMWARE API 在 github VMware vSphere Automation SDK for Python 但先需要 git 程式 , 所以先裝 git https://git-scm.com/download/win
  • 9. Npp 很好用就指定它為預設編輯, 如果沒有 npp 就先裝 npp ( https://notepad- plus-plus.org/downloads/ ) 接著下一步到結束 到 github https://github.com/vmware/vsphere-automation-sdk-python
  • 10. 開啟 cmd 把以下兩行貼上 pip install --upgrade pip setuptools pip install --upgrade git+https://github.com/vmware/vsphere-automation-sdk- python.git
  • 11. 如果 pip 或 python 沒有跑起來 應該是 OS path 沒有自動被加去 自已加路徑或是切到以下路徑
  • 13. 貼上以下 [需自行修改 vcenter ip username / password] import requests import urllib3 from vmware.vapi.vsphere.client import create_vsphere_client session = requests.session() # Disable cert verification for demo purpose. # This is not recommended in a production environment. session.verify = False # Disable the secure connection warning for demo purpose. # This is not recommended in a production environment. urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
  • 14. # Connect to a vCenter Server using username and password vsphere_client = create_vsphere_client(server='192.168.100.101', username='administrator@vsphere.local', password='P@ssw0rd', session=session) # List all VMs inside the vCenter Server vsphere_client.vcenter.VM.list() vsphere_client.vcenter.VM.list() 會列出現行系統 VM 列表
  • 15. 例:列出 VM FREENAS 資源狀態 client.vcenter.VM.list(client.vcenter.VM.FilterSpec(names={'FREENAS'})) 接著就依自行需要執行 python API 備註: Python 程序副檔為.py 可以命令列方式行 Windows 環境變數 PATH 如果不在請自行手動加。 http://code.vmware.com/ > API Explorer https://developer.vmware.com/ 有完整 API