def set_qos(server_name, user_name, password, vm_uuids, new_min_value, new_max_value): # Get the preferred version r = tintri.api_get(server_name, '/info') json_info = r.json() preferred_version = json_info['preferredVersion'] # Verify the correct major and minor versions. versions = preferred_version.split(".") major_version = versions[0] minor_version = int(versions[1]) if major_version != "v310": print_error("Incorrect major version: " + major_version + ". Should be v310.") return "Error" if minor_version < 21: print_error("Incorrect minor Version: " + str(minor_version) + ". Should be 21 or greater") return "Error" # Login into the appropriate VMstore session_id = tintri.api_login(server_name, user_name, password) if session_id is None: return "Error" print_info("Logged onto " + server_name) # Create new QoS object with the fields to be changed modify_qos_info = {'minNormalizedIops': int(new_min_value), 'maxNormalizedIops': int(new_max_value), 'typeId': 'com.tintri.api.rest.v310.dto.domain.beans.vm.VirtualMachineQoSConfig' } # Create the MultipleSelectionRequest object MS_Request = {'typeId': 'com.tintri.api.rest.v310.dto.MultipleSelectionRequest', 'ids': vm_uuids, 'newValue': modify_qos_info, 'propertyNames': ["minNormalizedIops", "maxNormalizedIops"] } print_debug("Changing min and max QOS values to (" + str(new_min_value) + ", " + str(new_max_value) + ")") # Update the min and max QoS IOPs modify_qos_url = "/v310/vm/qosConfig" r = tintri.api_put(server_name, modify_qos_url, MS_Request, session_id) print_debug("The JSON response of the get invoke to the server " + server_name + " is: " + r.text) # if HTTP Response is not 204 then raise an exception if r.status_code != 204: print_error("The HTTP response for the put invoke to the server " + server_name + " is not 204, but is: " + str(r.status_code)) print_error("url = " + modify_qos_url) print_error("payload = " + str(MS_Request)) print_error("response: " + r.text) tintri.api_logout(server_name, session_id) print_info("Error log off " + server_name) return "Error" tintri.api_logout(server_name, session_id) print_info("Sucesss log off " + server_name) return "OK"
print_with_prefix("[ERROR] : ", out) return # main if len(sys.argv) < 4: print("\nDelete the oldest user generated snapshot.\n") print("Usage: " + sys.argv[0] + " server_name user_name password\n") sys.exit(-1) server_name = sys.argv[1] user_name = sys.argv[2] password = sys.argv[3] # Get the preferred version r = tintri.api_get(server_name, '/info') json_info = r.json() print_info("API Version: " + json_info['preferredVersion']) # Login to VMstore session_id = tintri.api_login(server_name, user_name, password) # Create filter to get the oldest user generated snapshot q_filter = {'queryType': 'TOP_DOCS_BY_TIME', 'limit': '1', 'type': 'USER_GENERATED_SNAPSHOT'} # Get the oldest user generated snapshot url = "/v310/snapshot" r = tintri.api_get_query(server_name, url, q_filter, session_id)
def get_vms(session_id): page_size = 25 # default # dictionary of VM objects vms = {} # Get a list of VMs a page size at a time get_vm_url = "/v310/vm" count = 1 vm_paginated_result = {'live' : "TRUE", 'next' : "offset=0&limit=" + str(page_size)} # While there are more VMs, go get them while 'next' in vm_paginated_result: url = get_vm_url + "?" + vm_paginated_result['next'] # This is a work-around for a TGC bug. chop_i = url.find("&replicationHasIssue") if chop_i != -1: url = url[:chop_i] print_debug("Fixing URL") print_debug("Next GET VM URL: " + str(count) + ": " + url) # Invoke the API r = tintri.api_get(server_name, url, session_id) print_debug("The JSON response of the get invoke to the server " + server_name + " is: " + r.text) # if HTTP Response is not 200 then raise an error if r.status_code != 200: print_error("The HTTP response for the get invoke to the server " + server_name + " is not 200, but is: " + str(r.status_code)) print_error("url = " + url) print_error("response: " + r.text) tintri.api_logout(server_name, session_id) sys.exit(-10) # For each VM in the page, print the VM name and UUID. vm_paginated_result = r.json() # Check for the first time through the loop and # print the total number of VMs. if count == 1: num_filtered_vms = vm_paginated_result["filteredTotal"] if num_filtered_vms == 0: print_error("No VMs present") tintri.api_logout(server_name, session_id) sys_exit(-99) # Get and store the VM items and save in a VM object. items = vm_paginated_result["items"] for vm in items: vm_name = vm["vmware"]["name"] vm_uuid = vm["uuid"]["uuid"] vm_stats = VmStat(vm_name, vm_uuid, vm["stat"]["sortedStats"][0]) print_debug(str(count) + ": " + vm_name + ", " + vm_uuid) count += 1 # Store the VM stats object keyed by VM name. vms[vm_name] = vm_stats return vms
# main if len(sys.argv) < 6: print("\nSets the first 2 VMs QOS values\n") print("Usage: " + sys.argv[0] + " server_name user_name password min_value, max_value\n") sys.exit(-1) server_name = sys.argv[1] user_name = sys.argv[2] password = sys.argv[3] new_min_value = sys.argv[4] new_max_value = sys.argv[5] # Get the preferred version r = tintri.api_get(server_name, '/info') json_info = r.json() print_info("API Version: " + json_info['preferredVersion']) # Login to VMstore session_id = tintri.api_login(server_name, user_name, password) # Create filter to get the live VMs q_filter = {'live': 'TRUE'} # Get a list of live VMs url = "/v310/vm" r = tintri.api_get_query(server_name, url, q_filter, session_id) print_debug("The JSON response of the get invoke to the server " + server_name + " is: " + r.text)
# main if len(sys.argv) < 4: print("\nPrints VM information using pagination\n") print("Usage: " + sys.argv[0] + " server_name user_name password\n") sys.exit(-1) server_name = sys.argv[1] user_name = sys.argv[2] password = sys.argv[3] # Could make this an input parameter page_size = 25 # Get the preferred version r = tintri.api_get(server_name, "/info") json_info = r.json() print_info("API Version: " + json_info["preferredVersion"]) # Login to VMstore session_id = tintri.api_login(server_name, user_name, password) # Get a list of VMs, but return a page size at a time get_vm_url = "/v310/vm" count = 1 vm_paginated_result = {"next": "offset=0&limit=" + str(page_size)} # While there are more Vms, go get them while "next" in vm_paginated_result: url = get_vm_url + "?" + vm_paginated_result["next"]
# main if len(sys.argv) < 4: print("\nCollect VM historic status") print("Usage: " + sys.argv[0] + " server_name user_name password <page_size>\n") sys.exit(-1) server_name = sys.argv[1] user_name = sys.argv[2] password = sys.argv[3] page_size = 25 # init default if len(sys.argv) == 5: page_size = sys.argv[4] # Get the preferred version r = tintri.api_get(server_name, '/info') if r.status_code != 200: print_error("The HTTP response for the get invoke to the server " + server_name + " is not 200, but is: " + str(r.status_code)) print_error("URL = /api/info") print_error("response: " + r.text) sys.exit(-2) json_info = r.json() print_info("API Version: " + json_info['preferredVersion']) # Login to VMstore session_id = tintri.api_login(server_name, user_name, password) # Get a VM to work with