コード例 #1
0
def establece_conexion(cluster: str, api_user: str, api_pass: str) -> None:
    config.CONNECTION = HostConnection(
        cluster,
        username=api_user,
        password=api_pass,
        verify=False,
    )
コード例 #2
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])
コード例 #3
0
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
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)
コード例 #5
0
def show_svm(api, apiuser, apipass):
    config.CONNECTION = HostConnection(api, apiuser, apipass, verify=False)
    print()
    print("Getting SVM Details")
    print("===================")
    for svm in Svm.get_collection(fields="uuid"):
        print("SVM name:-%s ; SVM uuid:-%s " % (svm.name, svm.uuid))
コード例 #6
0
ファイル: utils.py プロジェクト: ebl/ontap-rest-python
def setup_connection(cluster: str, api_user: str, api_pass: str) -> None:
    """Configure the default connection for the application"""

    config.CONNECTION = HostConnection(
        cluster,
        username=api_user,
        password=api_pass,
        verify=False,
    )
コード例 #7
0
def connect_ntap(message):
    try:
        config.CONNECTION = HostConnection(message.text.split()[-3],
                                           username=message.text.split()[-2],
                                           password=message.text.split()[-1],
                                           verify=False)
        cluster = Cluster()
        cluster.get()
        bot.send_message(message.chat.id, cluster.name)

    except NetAppRestError as err:
        bot.send_message(
            message.chat.id,
            "Couldn't connect to the appliance. Error was: %s" % err)
コード例 #8
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
コード例 #9
0
def prepare_connection(vserver_ip, username, password):
    global config, args
    try:
        config.CONNECTION = HostConnection(vserver_ip,
                                           username=username,
                                           password=password,
                                           verify=False)
        if args.debug:
            print("Enabling debug on NetApp REST API interface")
            utils.DEBUG = 1
        return True
    except Exception as e:
        print("Error: connection to vserver {:s} failed: {:s}".format(
            vserver_ip, e))
        return False
コード例 #10
0
def delete_volume(api, apiuser, apipass):
    config.CONNECTION = HostConnection(api, apiuser, apipass, verify=False)

    print("=============================================")
    print()
    show_volume(api, apiuser, apipass)
    print()
    volname = input("Enter the name of the volume that needs to be Deleted:- ")
    vol = Volume.find(name=volname)

    try:
        if (vol.delete(poll=True)):
            print("Volume  has been deleted Successfully.")
    except NetAppRestError as e:
        print("HTTP Error Code is " % e.http_err_response.http_response.text)
        print("Exception caught :" + str(e))
    return
コード例 #11
0
def patch_volume(api, apiuser, apipass):
    config.CONNECTION = HostConnection(api, apiuser, apipass, verify=False)

    print("=============================================")
    print()
    show_volume(api, apiuser, apipass)
    print()
    vol_name = input(
        "Enter the name  of the volume that needs to be modified:- ")

    vol = Volume.find(name=vol_name)

    dataObj = {}
    print()
    nambool = input("Would you like to change the volume name (y/n):- ")
    if nambool == 'y':
        nam = input("Enter the new name of the Volume: ")
        vol.name = nam

    print()
    sizebool = input("Would you like to change the volume size (y/n) :- ")
    if sizebool == 'y':
        vol_size = input("Enter the new size of the Volume: ")
        vol_size_format = get_size(vol_size)
        vol.size = vol_size_format

    print()
    statebool = input("Would you like to change the volume state (y/n) :- ")
    if statebool == 'y':
        vol_state = input(
            "Enter the new state of the Volume [offline/online]: ")
        vol.state = vol_state

    try:
        if (vol.patch(poll=True)):
            print("The Volume  has been updated/patched Successfully")
    except NetAppRestError as e:
        print("HTTP Error Code is " % e.http_err_response.http_response.text)
        print("Exception caught :" + str(e))

    return
コード例 #12
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])
コード例 #13
0
def create_volume(api, apiuser, apipass):
    config.CONNECTION = HostConnection(api, apiuser, apipass, verify=False)
    print()
    show_svm(api, apiuser, apipass)
    print()
    svmname = input(
        "Enter the name of the SVM on which the volume needs to be created:- ")
    dataObj = {}
    tmp1 = {"name": svmname}
    dataObj['svm'] = tmp1
    print()
    show_aggregate(api, apiuser, apipass)
    print()
    aggrname = input(
        "Enter the name of the Aggregate on which the volume needs to be created:- "
    )
    tmp2 = [{"name": aggrname}]
    dataObj['aggregates'] = tmp2
    print()
    volname = input("Enter the name of the Volume:- ")
    dataObj['name'] = volname
    print()
    vol_size = input("Enter the size of the Volume in MBs:- ")
    tmp3 = get_size(vol_size)
    dataObj['size'] = tmp3
    print()

    volume = Volume.from_dict(dataObj)

    try:
        if (volume.post(poll=True)):
            print("SVM  %s created Successfully" % volume.name)
    except NetAppRestError as e:
        print("HTTP Error Code is " % e.http_err_response.http_response.text)
        print("Exception caught :" + str(e))

    return
コード例 #14
0
def show_aggregate(api, apiuser, apipass):
    config.CONNECTION = HostConnection(api, apiuser, apipass, verify=False)
    print("\n List of Aggregates:- \n")
    for aggregatelist in Aggregate.get_collection(fields="uuid"):
        print(aggregatelist.name)
    return
コード例 #15
0
################################################################################

import json, os, sys
from netapp_ontap import config, HostConnection, NetAppRestError
from netapp_ontap.resources import Volume


### Step 1 - Read in global variables
with open(os.path.dirname(sys.argv[0])+'/../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 - Create operation
# execute create operation
volume = Volume.from_dict(
{
  "name": global_vars["PRI_SVM"]+"_nfs_01",
  "svm": {
    "name": global_vars["PRI_SVM"]
  },
  "size": global_vars["VOL_SIZE"],
  "aggregates": [
    {
コード例 #16
0
if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description='Passing variables to the program')
    parser.add_argument('-api',
                        '--api',
                        help='API server IP:port details',
                        dest='api',
                        required=True)
    parser.add_argument('-apiuser',
                        '--apiuser',
                        help='Add APIServer Username',
                        dest='apiuser',
                        required=True)
    parser.add_argument('-apipass',
                        '--apipass',
                        help='Add APIServer Password',
                        dest='apipass',
                        required=True)
    parser.add_argument('-v',
                        '--vol_name',
                        help='Volume to create or clone from',
                        dest='vol_name',
                        required=True)
    parser.add_argument('-s',
                        '--snapshot_name',
                        help='Snapshot to create or clone from',
                        dest='snapshot_name')
    globals().update(vars(parser.parse_args()))
    config.CONNECTION = HostConnection(api, apiuser, apipass, verify=False)
    create_snapshot(vol_name, snapshot_name)
コード例 #17
0
from netapp_ontap import config
from netapp_ontap import HostConnection
from netapp_ontap.resources import Cluster, Aggregate, Port, Volume, Autosupport, IpInterface, Disk, Chassis, Account, Svm

import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

conn = HostConnection('192.168.1.200',
                      username='******',
                      password='******',
                      verify=False)

config.CONNECTION = conn
clus = Cluster()
clus.get()
print(clus)

aggr = Aggregate.find()
aggr.get()
print(aggr.name, aggr.node)

svm = Svm.find(name="study")
svm.get()
print(svm.to_dict())
コード例 #18
0
#! /usr/bin/env python3.7
from netapp_ontap import config
from netapp_ontap import HostConnection
from netapp_ontap.resources import Cluster
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
conn = HostConnection("192.168.0.111",
                      username="******",
                      password="******",
                      verify=False)
config.CONNECTION = conn
clus = Cluster()
clus.get()
print(clus.version)
    parser.add_argument("-u",
                        "--api_user",
                        default="admin",
                        help="API Username")
    parser.add_argument("-p", "--api_pass", help="API Password")
    parsed_args = parser.parse_args()

    # collect the password without echo if not already provided
    if not parsed_args.api_pass:
        parsed_args.api_pass = getpass()

    return parsed_args


if __name__ == "__main__":
    logging.basicConfig(
        level=logging.INFO,
        format=
        "[%(asctime)s] [%(levelname)5s] [%(module)s:%(lineno)s] %(message)s",
    )
    args = parse_args()
    config.CONNECTION = HostConnection(
        args.cluster,
        username=args.api_user,
        password=args.api_pass,
        verify=False,
    )

    make_volume_pycl(args.volume_name, args.vserver_name, args.aggr_name,
                     args.volume_size)
コード例 #20
0
def clone_volume(api, apiuser, apipass):
    config.CONNECTION = HostConnection(api, apiuser, apipass, verify=False)

    print("=============================================")
    print()
    show_volume(api, apiuser, apipass)
    print()
    svm_name = input(
        "Enter the NAME of the SVM the parent volume belongs to:-  ")
    svm_uuid = input(
        "Enter the UUID of the SVM the parent volume belongs to [UUID]:- ")
    vol_name = input("Enter the NAME of the volume that needs to be Cloned:- ")
    vol_uuid = input(
        "Enter the UUID of the volume that needs to be Cloned [UUID]:- ")
    print()
    dataObj = {}
    clone_name = input("Enter the name of the clone:- ")

    tmp = {'uuid': svm_uuid}
    dataObj['svm'] = tmp

    dataObj['name'] = clone_name

    clone_volume_json = {
        "is_flexclone": bool("true"),
        "parent_svm": {
            "name": svm_name,
            "uuid": svm_uuid
        },
        "parent_volume": {
            "name": vol_name,
            "uuid": vol_uuid
        }
    }

    dataObj['clone'] = clone_volume_json

    clonesnapshot = input("Would you like to Clone from Snapshot (y/n): ")
    if clonesnapshot == 'y':
        snapshot_name = input(
            "Enter the name of the snapshot that needs to be Cloned:- ")
        snapshot_uuid = get_key_snapshot(snapshot_name, vol_uuid)
        clone_snapshot_json = {
            "is_flexclone": bool(true),
            "parent_snapshot": {
                "name": snapshot_name,
                "uuid": snapshot_uuid
            },
            "parent_svm": {
                "name": svmname,
                "uuid": svm_uuid
            },
            "parent_volume": {
                "name": vol_name,
                "uuid": vol_uuid
            }
        }
        dataObj['clone'] = clone_snapshot_json

    volume = Volume.from_dict(dataObj)

    try:
        if (volume.post(poll=True)):
            print("SVM  %s created Successfully" % volume.name)
    except NetAppRestError as e:
        print("HTTP Error Code is " % e.http_err_response.http_response.text)
        print("Exception caught :" + str(e))

    return