Skip to content

Instantly share code, notes, and snippets.

@smitmartijn
Created June 23, 2019 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smitmartijn/5cb811756bf98f1c2099d4786368c9a1 to your computer and use it in GitHub Desktop.
Save smitmartijn/5cb811756bf98f1c2099d4786368c9a1 to your computer and use it in GitHub Desktop.
import init_api_client
import swagger_client
from swagger_client.rest import ApiException
# Initialize SDK and parse the args for connection details
args = init_api_client.parse_arguments()
api_client = init_api_client.get_api_client(args)
# Create search API client object
search_api = swagger_client.SearchApi()
# Create request parameters required for search APIs, searching for all VMs in a certain vCenter
filter_string = "vcenter_manager.name = 'my-vcenter'"
public_api_search_request_params = dict(entity_type=swagger_client.EntityType.VIRTUALMACHINE, filter=filter_string, size=100)
# Create payload from search parameters required for calling the search API & call the search API
search_payload = swagger_client.SearchRequest(**public_api_search_request_params)
api_response = search_api.search_entities(body=search_payload)
# Print the output. This will be a list of entity ids
print(api_response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment