Last active
March 24, 2021 09:27
-
-
Save laidbackware/49db28499010778c4786323c0ae1908a to your computer and use it in GitHub Desktop.
Working with the vCenter Python Rest API client
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
#!/usr/bin/python | |
from __future__ import absolute_import, division, print_function | |
__metaclass__ = type | |
from com.vmware.cis.tagging_client import CategoryModel | |
from vmware.vapi.vsphere.client import create_vsphere_client | |
from pprint import pprint | |
import requests | |
session = requests.session() | |
session.verify = False | |
requests.packages.urllib3.disable_warnings() | |
client = create_vsphere_client( | |
server="192.168.0.191", | |
username="[email protected]", | |
password="####", | |
session=session) | |
categories = client.tagging.Category.list() | |
category_list = [] | |
for category in categories: | |
category_list.append(client.tagging.Category.get(category)) | |
pprint(category_list) | |
category_spec = client.tagging.Category.CreateSpec() | |
category_spec.name = "matt" | |
category_spec.description = "" | |
category_spec.cardinality = CategoryModel.Cardinality.SINGLE | |
obj_types_set = ["Datastore"] | |
category_spec.associable_types = set(obj_types_set) | |
category_id = client.tagging.Category.create(category_spec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment