def test_cert_auth(parsed_args: argparse.Namespace, temp_path: str) -> None:
    """Verify our account can connect with a cert and no user/pass. After uploading
    and creating a user account, it can take some time before authentication works.
    In my testing, I've seen it take about 10 seconds. The while loop here tries
    to paper over that.
    """

    substep("List the volumes using a connection with cert-based auth")
    cert_conn = HostConnection(
        parsed_args.cluster,
        cert="%s/cert_user.cert" % temp_path,
        key="%s/cert_user.key" % temp_path,
        verify=False,
    )
    with cert_conn:
        tries = 0
        while True:
            try:
                logging.info([vol.name for vol in Volume.get_collection()])
                logging.debug("Succeeded on try %s", tries)
                break
            except NetAppRestError as err:
                resp = err.http_err_response
                if resp is None or resp.http_response.status_code == 401:
                    tries += 1
                    if tries > 60:
                        logging.error(
                            "Not able to authenticate within 60 tries")
                        raise
                    time.sleep(1)
                else:
                    raise
Beispiel #2
0
def patch_collection_volume(api, apiuser, apipass):
    """Turn the given volumes off then on again"""
    print("=============================================")
    print()
    show_volume(api, apiuser, apipass)
    print()
    noofnames = int(
        input(
            "Enter number of Volumes to be Updated [eg: int value:1,2,3] : "))
    volume_names = list(
        map(
            str,
            input("\nEnter the Volume names to be updated [eg: aaa bbb ccc] : "
                  ).strip().split()))[:noofnames]
    volume_names_final = '|'.join([str(v) for v in volume_names])
    vol_state = input("Enter the new state of the Volume [offline/online]: ")
    page_size = min(len(volume_names_final) - 1, 1)

    try:
        Volume.patch_collection({"state": vol_state},
                                name=volume_names_final,
                                max_records=page_size)
        print(
            list(Volume.get_collection(fields='state',
                                       name=volume_names_final)))
    except NetAppRestError as e:
        print("HTTP Error Code is " % e.http_err_response.http_response.text)
        print("Exception caught :" + str(e))
    return
def get_vols_list():
    ### Step 1 - Read in global variables
    #with open(os.path.dirname(sys.argv[0])+'/global.vars') as json_file:
    with open(os.getcwd() + '/global.vars') as json_file:
        global_vars = json.load(json_file)

    ### Step 2 - Configure connection
    config.CONNECTION = HostConnection(global_vars["PRI_CLU"],
                                       username=global_vars["PRI_CLU_USER"],
                                       password=global_vars["PRI_CLU_PASS"],
                                       verify=False)

    # Volume
    myvols = []
    try:
        for volume in Volume.get_collection(**{
                "svm.name": global_vars["PRI_SVM"],
                "name": "!*_root"
        }):
            myvols.append(volume.name)
        print(json.dumps(myvols))
    except NetAppRestError as err:
        print("--> Error: Volume was not deleted:\n{}".format(err))

    return (myvols)
Beispiel #4
0
def print_vol_perf(message):
    try:
        config.CONNECTION = HostConnection('*.*.*.*',
                                           username='******',
                                           password='******',
                                           verify=False)
    except NetAppRestError as err:
        bot.send_message(
            message.chat.id,
            "Couldn't connect to the appliance. Error was: %s" % err)

    try:
        for volume in Volume.get_collection(
                **{"svm.name": message.text.split()[-1]}):
            volume.get()
            t = "Name: " + volume.name + '\n' + "Latency: " + '\n' + "Read: " + str(
                volume.metric.latency.read) + '\n' + "Write: " + str(
                    volume.metric.latency.write)
            #print(volume.metric.latency.read)

            bot.send_message(message.chat.id, t)

    except NetAppRestError as err:
        bot.send_message(
            message.chat.id, "Error: Volume list  was not created for SVM %s" %
            message.text.split()[-1])
Beispiel #5
0
def delete_collection_volume() -> None:
    """Delete a collection of volumes"""
    print("=============================================")
    print()
    show_svm()
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    show_volume(svm_name)
    print()

    noofnames = int(
        input(
            "Enter number of Volumes to be Deleted [eg: int value:1,2,3] : "))
    volume_names = list(
        map(
            str,
            input("\nEnter the Volume names to be Deleted [eg: aaa bbb ccc] : "
                  ).strip().split()))[:noofnames]
    volume_names_final = '|'.join([str(v) for v in volume_names])

    try:
        Volume.delete_collection(name=volume_names_final)
        print(list(Volume.get_collection()))
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
Beispiel #6
0
def patch_collection_volume() -> None:
    """Update the volume collection"""
    print("=============================================")
    print()
    show_svm()
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    show_volume(svm_name)
    print()

    noofnames = int(
        input("Enter number of Volumes to be Updated [eg: int value:1,2,3] : "))
    volume_names = list(map(str, input(
        "\nEnter the Volume names to be updated [eg: aaa bbb ccc] : ").strip().split()))[:noofnames]
    volume_names_final = '|'.join([str(v) for v in volume_names])
    vol_state = input("Enter the new state of the Volume [offline/online]: ")
    print("Please ensure that the volumes are unmounted in case you are offlining.")
    page_size = min(len(volume_names_final) - 1, 1)

    try:
        Volume.patch_collection({"state": vol_state},
                                name=volume_names_final,
                                max_records=page_size)
        print(
            list(
                Volume.get_collection(
                    fields='state',
                    name=volume_names_final)))
    except NetAppRestError as error:
        print("Exception caught :" + str(error))
def list_volume_pycl(svm_name: str) -> None:
    """List Volumes in a SVM """
    print("\n List of Volumes:- \n")
    try:
        print(*(vol.name
                for vol in Volume.get_collection(**{"svm.name": svm_name})),
              sep="\n")
    except NetAppRestError as err:
        print("Error: Volume list  was not created: %s" % err)
def devuelve_uid_vol(svm_name, vol_name):
    try:
        for volumen in Volume.get_collection(**{"svm.name": svm_name},
                                             **{"name": vol_name},
                                             fields="uuid"):
            return volumen.uuid
    except NetAppRestError as error:
        print("Por favor, INTRODUZCA EL NOMBRE DEL VOLUMEN!\n" +
              error.http_err_response.http_response.text)
Beispiel #9
0
def list_volume_pycl(vserver_name: str) -> None:
    """List Volumes in a SVM """

    print("\n List of Volumes:- \n")
    try:
        for volume in Volume.get_collection(**{"svm.name": vserver_name}):
            volume.get()
            print(volume.name)
    except NetAppRestError as err:
        print("Error: Volume list  was not created: %s" % err)
    return
def show_volume(svm_name) -> None:
    """Show volumes in a SVM"""
    print()
    print("Getting Volume Details")
    print("======================")
    try:
        for volume in Volume.get_collection(**{"svm.name": svm_name},
                                            fields="uuid"):
            print("Name = %s; UUID = %s" % (volume.name, volume.uuid))
    except NetAppRestError as error:
        print("Error:- " % error.http_err_response.http_response.text)
        print("Exception caught :" + str(error))
def list_volumes(vserver_name: str) -> None:
    """List Volumes"""
    for volume in Volume.get_collection():
        one_hour_iops_total = []
        for metrics in VolumeMetrics.get_collection(volume.uuid,
                                                    fields="iops.total",
                                                    interval="1h"):
            one_hour_iops_total.append(metrics.iops.total)
        print(
            f"IOPs over the last hour for volume {volume.name} was {sum(one_hour_iops_total)}"
        )
    return
Beispiel #12
0
    async def get_volumes(self, message):
        """
        A skills function to get volumes on an SVM. The parser looks for the message argument.

        Arguments:
            message {str} -- get volumes on svm {svm}
        """
        svm = message.regex.group('svm')
        volumes = []
        for vol in Volume.get_collection(svm=svm):
            vol.get(fields='name')
            volumes.append(vol.name)
        await message.respond('All done! Response: {}'.format(volumes))
Beispiel #13
0
def get_key_volume(svm_name, volume_name) -> None:
    """Lists Volumes"""
    print()
    print("Getting Volume Details")
    print("======================")
    try:
        for volume in Volume.get_collection(
                **{"svm.name": svm_name, 'volume.name': volume_name}, fields="uuid"):
            print(volume.uuid)
            return volume.uuid
    except NetAppRestError as error:
        print("Error:- " % error.http_err_response.http_response.text)
        print("Exception caught :" + str(error))
Beispiel #14
0
def show_volume(api, apiuser, apipass):
    config.CONNECTION = HostConnection(api, apiuser, apipass, verify=False)
    print("The List of SVMs")
    show_svm(api, apiuser, apipass)
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    print("Getting Volume Details")
    print("===================")
    for volume in Volume.get_collection(**{"svm.name": svm_name},
                                        fields="uuid"):
        print("Volume Name = %s;  Volume UUID = %s" %
              (volume.name, volume.uuid))
    return
Beispiel #15
0
def show_volume() -> None:
    """Lists Volumes"""
    show_svm()
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    print("Getting Volume Details")
    print("======================")
    try:
        for volume in Volume.get_collection(**{"svm.name": svm_name},
                                            fields="uuid"):
            print("Volume Name = %s;  Volume UUID = %s" %
                  (volume.name, volume.uuid))
    except NetAppRestError as error:
        print("Error:- " % error.http_err_response.http_response.text)
        print("Exception caught :" + str(error))
Beispiel #16
0
def delete_collection_volume() -> None:
    """Delete a collection of volumes"""
    print("=============================================")
    print()
    show_volume()
    print()
    noofnames = int(
        input("Enter number of Volumes to be Deleted [eg: int value:1,2,3] : "))
    volume_names = list(map(str, input(
        "\nEnter the Volume names to be Deleted [eg: aaa bbb ccc] : ").strip().split()))[:noofnames]
    volume_names_final = '|'.join([str(v) for v in volume_names])
    page_size = min(len(volume_names_final) - 1, 1)

    try:
        Volume.delete_collection(name=volume_names_final)
        print(list(Volume.get_collection()))
    except NetAppRestError as error:
        print("Error:- " % error.http_err_response.http_response.text)
        print("Exception caught :" + str(error))
Beispiel #17
0
def print_vols(message):
    try:
        config.CONNECTION = HostConnection('*.*.*.*',
                                           username='******',
                                           password='******',
                                           verify=False)
    except NetAppRestError as err:
        bot.send_message(
            message.chat.id,
            "Couldn't connect to the appliance. Error was: %s" % err)

    try:
        for volume in Volume.get_collection(
                **{"svm.name": message.text.split()[-1]}):
            volume.get()
            t = "Name: " + volume.name + '\n' + "Size: " + size(
                volume.size) + '\n' + "Status: " + volume.state
            bot.send_message(message.chat.id, t)

    except NetAppRestError as err:
        bot.send_message(
            message.chat.id, "Error: Volume list  was not created for SVM %s" %
            message.text.split()[-1])
Beispiel #18
0
def delete_collection_volume(api, apiuser, apipass):
    print("=============================================")
    print()
    show_volume(api, apiuser, apipass)
    print()
    noofnames = int(
        input(
            "Enter number of Volumes to be Deleted [eg: int value:1,2,3] : "))
    volume_names = list(
        map(
            str,
            input("\nEnter the Volume names to be Deleted [eg: aaa bbb ccc] : "
                  ).strip().split()))[:noofnames]
    volume_names_final = '|'.join([str(v) for v in volume_names])
    vol_state = input("Enter the new state of the Volume [offline/online]: ")
    page_size = min(len(volume_names_final) - 1, 1)

    try:
        Volume.delete_collection(name=volume_names_final)
        print(list(Volume.get_collection()))
    except NetAppRestError as e:
        print("HTTP Error Code is " % e.http_err_response.http_response.text)
        print("Exception caught :" + str(e))
    return
Beispiel #19
0
def get_uuid(vol_name):
    for volume in Volume.get_collection():
        volume.get()
        if volume.name == vol_name:
            return volume.uuid
### Step 1 - Read in global variables
with open('../global.vars') as json_file:
    global_vars = json.load(json_file)

### Step 2 - Configure connection
config.CONNECTION = HostConnection(global_vars["PRI_CLU"],
                                   username=global_vars["PRI_CLU_USER"],
                                   password=global_vars["PRI_CLU_PASS"],
                                   verify=False)

### Step 3 - Get & print details
# Volumes
print("--> Printing volume details")
print("{:<20}{:<25}{:<15}{:<15}".format("SVM", "Name", "Size", "Used"))
for volume in Volume.get_collection():
    volume.get()
    print("{:<20}{:<25}{:<15}{:<15}".format(volume.svm.name, volume.name,
                                            volume.size, volume.space.used))
print("")

# Qtrees
print("--> Printing qtree details")
print("{:<20}{:<10}{:<15}{:<35}".format("SVM", "Style", "Export Policy",
                                        "Path"))
for qtree in Qtree.get_collection():
    qtree.get()
    print("{:<20}{:<10}{:<15}{:<35}".format(qtree.svm.name,
                                            qtree.security_style,
                                            qtree.export_policy.name,
                                            qtree.path))
Beispiel #21
0

### Step 2 - Configure connection
config.CONNECTION = HostConnection(
	global_vars["PRI_CLU"],
	username=global_vars["PRI_CLU_USER"],
	password=global_vars["PRI_CLU_PASS"],
	verify=False
)


### Step 3 - Delete operation
# Volume
print("--> Starting volume delete operation")
try:
	for volume in Volume.get_collection(
		**{"svm.name":global_vars["PRI_SVM"], "name":"!*_root"}):
		volume.delete()
		print("--> Volume {} deleted successfully".format(volume.name))
except NetAppRestError as err:
	print("--> Error: Volume was not deleted:\n{}".format(err))
print("")

# CIFS Server
print("--> Starting CIFS server delete operation")
try:
	cifs = CifsService.find(name=global_vars["PRI_SVM"])
	if cifs:
		cifs.delete(body={
			"ad_domain": {
				"fqdn": global_vars["PRI_AD_DOMAIN"],
				"user": global_vars["PRI_AD_USER"],