Exemple #1
0
def add_data_ip(ip_configs, new_data_ip):

    new_ip_configs = []
    
    # Find a data IP config to copy and copy only the data IP configs.
    for ip_config in ip_configs:
        if (ip_config['ip'] == new_data_ip):
            message = new_data_ip + " already configured."
            raise tintri.TintriRequestsException(message)

        if (ip_config['serviceType'] == "data"):
            ip_config_save = ip_config
            new_ip_configs.append(ip_config)

    if (not ip_config_save):
        message = "Data IP conifg does not exist."
        raise tintri.TintriRequestsException(message)

    data_ip_config = ip_config_save.copy()
    
    # Modify the save copy for our purposes.
    data_ip_config['ip'] = new_data_ip
    data_ip_config['vlanId'] = "untagged"  # For example only.
    
    new_ip_configs.append(data_ip_config)
    return new_ip_configs
Exemple #2
0
def get_service_group(server_name, session_id, service_group):

    # Get a list of service groups
    url = "/v310/servicegroup"
    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)

    sg_paginated_result = r.json()
    num_sgs = int(sg_paginated_result["absoluteTotal"])
    if num_sgs == 0:
        raise tintri.TintriRequestsException("No Service Groups present")

    print_debug(str(num_sgs) + " Service Groups present")

    # Initialze the member list
    sg_uuid = ""
    found = False

    # Look for service group that matches the input name
    items = sg_paginated_result["items"]
    count = 1
    for sg in items:
        sg_name = sg["name"]
        sg_uuid = sg["uuid"]["uuid"]
        sg_member_count = sg["memberCount"]
        print_debug(
            str(count) + ": " + sg_name + "(" + str(sg_member_count) + "): " +
            sg_uuid)
        if sg_name == service_group:
            found = True
            break
        count += 1

    if not found:
        raise tintri.TintriRequestsException("Service Group " + service_group +
                                             " not found.")

    return sg_uuid
Exemple #3
0
def get_vms(server_name, session_id):

    vms = {}

    # Get a list of VMs, but return a page size at a time
    get_vm_url = "/v310/vm"
    count = 1
    page_size = 100
    vm_paginated_result = {'next': "offset=0&limit=" + str(page_size)}

    print_info("Collecting VMs from TGC.")

    # While there are more Vms, go get them
    while 'next' in vm_paginated_result:
        url = get_vm_url + "?" + vm_paginated_result['next']
        print_debug("Next GET VM URL: " + str(count) + ": " + url)

        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)

        # 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_vms = vm_paginated_result["filteredTotal"]
            if num_vms == 0:
                raise tintri.TintriRequestsException("No VMs present")

            print_debug(str(num_vms) + " VMs present")

        items = vm_paginated_result["items"]
        for vm in items:
            vm_name = vm["vmware"]["name"]
            vm_uuid = vm["uuid"]["uuid"]
            print_debug(str(count) + ": " + vm_name + ", " + vm_uuid)
            count += 1
            vms[vm_name] = vm_uuid
        print_info("Collected " + str(count) + " VMs.")

    print_info(str(count) + "VMs collected from TGC.")
    return vms
Exemple #4
0
def get_sg_by_name(server_name, session_id, service_group):
    url = "/v310/servicegroup"
    r = tintri.api_get(server_name, url, session_id)
    print_debug(
        "The JSON response of the service group get invoke to the server " +
        server_name + " is: " + r.text)

    sg_paginated_result = r.json()
    num_sgs = int(sg_paginated_result["absoluteTotal"])
    if num_sgs == 0:
        raise tintri.TintriRequestsException("No service groups present")

    # Look for a qualifying service group
    items = sg_paginated_result["items"]
    for sg in items:
        if (sg["name"] == service_group):
            return sg["uuid"]["uuid"]

    return ""
Exemple #5
0
def get_pools(server, tgc_sess_id):
    vmstore_pools = []

    url = "/v310/vmstorePool"
    r = tintri.api_get(server, url, tgc_sess_id)
    print_debug("The JSON response of the get invoke to the server " + server +
                " is: " + r.text)

    vm_paginated_result = r.json()
    num_pools = int(vm_paginated_result["filteredTotal"])
    if (num_pools) == 0:
        raise tintri.TintriRequestsException("No VMstore Pools present")

    # Load up the pools
    items = vm_paginated_result["items"]
    for pool in items:
        print_info(pool["name"] + ": " + pool["uuid"]["uuid"])
        vmstore_pool = VmstorePool(pool["name"], pool["uuid"]["uuid"])
        vmstore_pools.append(vmstore_pool)

    return vmstore_pools
Exemple #6
0
print("")

try:
    if os.path.isfile(file_loc):
        with open(file_loc, 'r') as csv_file:
            vm_csv_list = csv.reader(csv_file)

            # Gets a list of VMs from a CSV file.
            # Should be able to process both Windows and Linux files.
            for row in vm_csv_list:
                for item in row:
                    if item == "":
                        continue
                    vm_list.append(item.lstrip(' '))
    else:
        raise tt.TintriRequestsException("Could not find file " + file_loc)

    # Get the API version and product.
    r = tt.api_version(server_name)
    json_info = r.json()
    preferred_version = json_info['preferredVersion']
    product_name = json_info['productName']

    # Check for correct product
    if product_name != "Tintri Global Center":
        raise tt.TintriRequestsException(
            "Tintri server should be Tintri Global Center, not " +
            product_name)

    # Check API version.
    versions = preferred_version.split(".")
Exemple #7
0
if args.affinity != None:
    affinity = args.affinity

# Collect the required parameters.
server_name = args.server_name
user_name = args.user_name
password = args.password

# Get the product name.
try:
    r = tintri.api_version(server_name)
    json_info = r.json()
    preferred_version = json_info['preferredVersion']
    product_name = json_info['productName']
    if json_info['productName'] != "Tintri Global Center":
        raise tintri.TintriRequestsException("server needs to be a TGC.")

    versions = preferred_version.split(".")
    major_version = versions[0]
    minor_version = int(versions[1])
    if major_version != "v310":
        raise tintri.TintriRequestsException("Incorrect major version: " +
                                             major_version +
                                             ".  Should be v310.")
    if minor_version < 51:
        raise tintri.TintriRequestsException("Incorrect minor Version: " +
                                             minor_version +
                                             ".  Should be 51 or greater")

    # Login to Tintri server
    session_id = tintri.api_login(server_name, user_name, password)
Exemple #8
0
    new_data_ip = args.add[0]
    add_ip = True
    print_info("Adding " + new_data_ip + " to " + server_name)

if args.delete != None:
    new_data_ip = args.delete[0]
    delete_ip = True
    print_info("Deleting " + new_data_ip + " from " + server_name)

# Get the server type and login
try:
    r = tintri.api_version(server_name)
    json_info = r.json()
    if json_info['productName'] != "Tintri VMstore":
        message = "Server needs to be a VMstore"
        raise tintri.TintriRequestsException(message)

    session_id = tintri.api_login(server_name, user_name, password)

except tintri.TintriRequestsException as tre:
    print_error(tre.__str__())
    exit(2)
except tintri.TintriApiException as tae:
    print_error(tae.__str__())
    exit(3)

# Execute
try:
    ip_configs = get_ip_configs(server_name, session_id)
    print_ip_configs(ip_configs, "Current")
    
Exemple #9
0
    accept_reco = True
    print_info("Accept recommendation")

# Collect the required parameters.
server_name = args.server_name
user_name = args.user_name
password = args.password

# Get the product name
try:
    r = tintri.api_version(server_name)
    json_info = r.json()
    preferred_version = json_info['preferredVersion']
    product_name = json_info['productName']
    if json_info['productName'] != "Tintri Global Center":
        raise tintri.TintriRequestsException("server needs to be a TGC.")

    versions = preferred_version.split(".")
    major_version = versions[0]
    minor_version = int(versions[1])
    if major_version != "v310":
        raise tintri.TintriRequestsException("Incorrect major version: " +
                                             major_version +
                                             ".  Should be v310.")
    if minor_version < 51:
        raise tintri.TintriRequestsException("Incorrect minor Version: " +
                                             minor_version +
                                             ".  Should be 51 or greater")

    # Login to Tintri server
    session_id = tintri.api_login(server_name, user_name, password)
Exemple #10
0
def tintri_snapshot(args, vm):
    try:
        # Confirm the consistency type.
        if (args.tvmstore_consistency_type == "crash"):
            consistency_type = "CRASH_CONSISTENT"
        elif (args.tvmstore_consistency_type == "vm"):
            consistency_type = "VM_CONSISTENT"
        else:
            raise tintri.TintriRequestsException(
                "tvmstore_consistency_type is not 'crash' or 'vm': " +
                args.tvmstore_consistency_type)

        # Get the preferred version
        r = tintri.api_version(args.tvmstore)
        json_info = r.json()

        print_info("Tintri API Version: " + json_info['preferredVersion'])

        # Login to VMstore or TGC
        session_id = tintri.api_login(args.tvmstore, args.tvmstore_user,
                                      args.tvmstore_password)

    except tintri.TintriRequestsException as tre:
        print_error(tre.__str__())
        sys.exit(-10)
    except tintri.TintriApiException as tae:
        print_error(tae.__str__())
        sys.exit(-11)

    try:
        # Create query filter to get the VM specified by the VM name.
        q_filter = {'name': vm.name}

        # Get the UUID of the specified VM
        vm_url = "/v310/vm"
        r = tintri.api_get_query(args.tvmstore, vm_url, q_filter, session_id)
        print_debug("The JSON response of the get invoke to the server " +
                    args.tvmstore + " is: " + r.text)

        vm_paginated_result = r.json()
        num_vms = int(vm_paginated_result["filteredTotal"])
        if num_vms == 0:
            raise tintri.TintriRequestsException("VM " + vm.name +
                                                 " doesn't exist")

        # Get the information from the first item and hopefully the only item.
        items = vm_paginated_result["items"]
        vm = items[0]
        vm_name = vm["vmware"]["name"]
        vm_uuid = vm["uuid"]["uuid"]

        print_info(vm_name + " UUID: " + vm_uuid)

        # Get the time for the snapshot description.
        now = datetime.datetime.now()
        now_sec = datetime.datetime(now.year, now.month, now.day, now.hour,
                                    now.minute, now.second)
        snapshot_name = args.tvmstore_snapshot_name

        # Take a manual snapshot.
        take_snapshot(vm_uuid, snapshot_name, consistency_type,
                      args.tvmstore_snapshot_lifetime, args.tvmstore,
                      session_id)

        # All pau, log out.
        tintri.api_logout(args.tvmstore, session_id)

    except tintri.TintriRequestsException as tre:
        print_error(tre.__str__())
        tintri.api_logout(args.tvmstore, session_id)
        sys.exit(-20)
    except tintri.TintriApiException as tae:
        print_error(tae.__str__())
        tintri.api_logout(args.tvmstore, session_id)
        sys.exit(-21)
    sys.exit(-11)

try:
    # Create query filter to get the VM specified by the VM name.
    q_filter = {'name': vm_name}

    # Get the UUID of the specified VM
    vm_url = "/v310/vm"
    r = tintri.api_get_query(server_name, vm_url, q_filter, session_id)
    print_debug("The JSON response of the get invoke to the server " +
                server_name + " is: " + r.text)

    vm_paginated_result = r.json()
    num_vms = int(vm_paginated_result["filteredTotal"])
    if num_vms == 0:
        raise tintri.TintriRequestsException("VM " + vm_name +
                                             " doesn't exist")

    # Get the information from the first item and hopefully the only item.
    items = vm_paginated_result["items"]
    vm = items[0]
    vm_name = vm["vmware"]["name"]
    vm_uuid = vm["uuid"]["uuid"]

    print_info(vm_name + ": " + vm_uuid)

    # Get the time for the snapshot description.
    now = datetime.datetime.now()
    now_sec = datetime.datetime(now.year, now.month, now.day, now.hour,
                                now.minute, now.second)
    snapshot_name = vm_name + now_sec.isoformat()
Exemple #12
0
    exit(-1)
except tintri.TintriApiException as tae:
    print_error(tae.__str__())
    exit(-2)

try:
    # Get a list of VMs, but only return a page size
    url = "/v310/vm"
    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)

    vm_paginated_result = r.json()
    num_vms = int(vm_paginated_result["filteredTotal"])
    if num_vms == 0:
        raise tintri.TintriRequestsException("No VMs present")

    print_info(str(num_vms) + " VMs present")

    # For each VM, print the VM name and UUID
    items = vm_paginated_result["items"]
    count = 1
    for vm in items:
        vm_name = vm["vmware"]["name"]
        vm_uuid = vm["uuid"]["uuid"]
        vcenter_name = vm["vmware"]["vcenterName"]
        print(
            str(count) + ": " + vm_name + ", " + vm_uuid + " - " +
            vcenter_name)
        count += 1