Instantly share code, notes, and snippets.
em2er
/ vapi_vm_tags.py
Last active
August 2, 2021 06:46
Read categories and tags for all VM in vCenter using vSphere Automation SDK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from vmware.vapi.vsphere.client import create_vsphere_client | |
client = create_vsphere_client( | |
server='my-company-vcenter.com', | |
username='my_login', | |
password='my_password', | |
session=None) | |
cat_dict = {} | |
for id in client.tagging.Category.list(): |
em2er
/ vmware_tags_rest_api.py
Last active
February 15, 2024 09:51
Getting categories and tags for all VM in VMWare vCenter using REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from requests import Session | |
from typing import List, Dict | |
VALUE_KEY = 'value' | |
class VMTagReader: | |
def __init__(self, vcenter_url: str, login: str, password: str): | |
self.host = vcenter_url | |
self.session = Session() |