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"
Пример #2
0
                   'maxNormalizedIops': int(new_max_value),
                   'typeId': items[0]["qosConfig"]["typeId"]
                  }
                  
# Create the MultipleSelectionRequest object
MS_Request = {'typeId': 'com.tintri.api.rest.v310.dto.MultipleSelectionRequest',
              'ids': [vm1.get_uuid(), vm2.get_uuid()],
              'newValue': modify_qos_info,
              'propertyNames': ["minNormalizedIops", "maxNormalizedIops"]
          }

print_info("Changing min and max QOS values to (" + str(new_min_value) + ", " + str(new_max_value) + ")")

# Update the min and max 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 200, 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)
    sys.exit(-10)


# Get VM 1 value to show that it changed.