-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathvol.py
More file actions
84 lines (68 loc) · 2.61 KB
/
vol.py
File metadata and controls
84 lines (68 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env python3.7
"""
ONTAP 9.7 REST API Python Client Library Scripts
This script performs the following:
- Create a volume
usage: python3.7 volume.py [-h] -c CLUSTER -v VOLUME_NAME -vs VSERVER_NAME -a AGGR_NAME
-s VOLUME_SIZE [-u API_USER] [-p API_PASS]
The following arguments are required: -c/--cluster, -v/--volume_name, -vs/--vserver_name,
-a/--aggr_name, -s/--volume_size
"""
import argparse
from getpass import getpass
import logging
from netapp_ontap import config, HostConnection, NetAppRestError
from netapp_ontap.resources import Volume
def make_volume(volume_name: str, vserver_name: str, aggr_name: str, volume_size: int) -> None:
"""Creates a new volume in a SVM"""
data = {
'name': volume_name,
'svm': {'name': vserver_name},
'aggregates': [{'name': aggr_name }],
'size': volume_size
}
volume = Volume(**data)
try:
volume.post()
print("Volume %s created successfully" % volume.name)
except NetAppRestError as err:
print("Error: Volume was not created: %s" % err)
return
def parse_args() -> argparse.Namespace:
"""Parse the command line arguments from the user"""
parser = argparse.ArgumentParser(
description="This script will create a new volume."
)
parser.add_argument(
"-c", "--cluster", required=True, help="API server IP:port details"
)
parser.add_argument(
"-v", "--volume_name", required=True, help="Volume to create or clone from"
)
parser.add_argument(
"-vs", "--vserver_name", required=True, help="SVM to create the volume from"
)
parser.add_argument(
"-a", "--aggr_name", required=True, help="Aggregate to create the volume from"
)
parser.add_argument(
"-s", "--volume_size", required=True, help="Size of the volume."
)
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,
)
# Create a Volume
make_volume(args.volume_name, args.vserver_name, args.aggr_name , args.volume_size)