async def create_volume(self, message): """ A skills function to create a volume. The parser looks for the message argument. Arguments: message {str} -- create a {size} MB volume called {name} on svm {svm} and aggregate {aggr} """ name = message.regex.group('name') size = message.regex.group('size') aggr = message.regex.group('aggr') svm = message.regex.group('svm') volume = Volume.from_dict({ 'name': name, 'svm': { 'name': svm }, 'nas': { 'path': '/' + name }, 'size': int(size) * 1024 * 1024, 'aggregates': [{ 'name': aggr }] }) volume.post() await message.respond('All done! Response: {}'.format(volume))
def clona_volumen(svm_name, vol_name, vol_uuid, num_clones) -> None: for i in range(1, num_clones + 1): dataobj = {} clone_name = vol_name + "__clon_" + str(i) tmp = {'name': svm_name} dataobj['svm'] = tmp dataobj['name'] = clone_name clone_volume_json = { "is_flexclone": bool("true"), "parent_svm": { "name": svm_name, }, "parent_volume": { "name": vol_name, "uuid": vol_uuid } } dataobj['clone'] = clone_volume_json try: volume = Volume.from_dict(dataobj) if volume.post(poll=True): print("El CLON %s se ha creado satisfactoriamente" % volume.name) except NetAppRestError as error: print('ERROR !\n {0}'.format( error.http_err_response.http_response.text)) print("\n")
def clone_volume() -> None: """Clone volume""" print("=============================================") print() show_volume() print() print("=============================================") print("Please give in the following details for creating clone.") 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 try: volume = Volume.from_dict(dataobj) if volume.post(poll=True): print("SVM %s created Successfully" % volume.name) except NetAppRestError as error: print("Error:- " % error.http_err_response.http_response.text) print("Exception caught :" + str(error))
def make_volume_pycl(volume_name: str, vserver_name: str, aggr_name: str, volume_size: int) -> None: """Creates a new volume in a SVM""" volume = Volume.from_dict({ 'name': volume_name, 'svm': { 'name': vserver_name }, 'aggregates': [{ 'name': aggr_name }], 'size': volume_size }) try: volume.post() print("Volume %s created successfully" % volume.name) except NetAppRestError as err: print("Error: Volume was not created: %s" % err) return
def clone_create(volume, snapshot, svmname, clone_name): try: clone = Volume.from_dict({ "name": clone_name, "clone": { "parent_volume": { "uuid": volume.uuid }, "parent_snapshot": { "uuid": snapshot.uuid }, "is_flexclone": True, }, "svm": { "name": svmname } }) clone.post() return clone except Exception as e: #print('Error: Cannot create volume clone: {:s}'.format(str(e))) return False
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
async def create_flexclone(self, message): """ A skills function to create a clone of a volume. The parser looks for the message argument. Arguments: message {str} -- create a clone of {volume} on svm {svm} called {name} """ parent_volume = message.regex.group('volume') svm = message.regex.group('svm') name = message.regex.group('name') flexclone = Volume.from_dict({ "name": name, "clone": { "parent_volume": { "name": parent_volume }, "is_flexclone": "true" }, "svm": { "name": svm } }) flexclone.post() await message.respond('All done! Response: {}'.format(flexclone))
### 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": [ { "name": global_vars["PRI_AGGR"] } ], "comment": "Created with ONTAP PCL", "guarantee": { "type": "volume" }, "nas": { "export_policy": { "name": "default" }, "path": "/"+global_vars["PRI_SVM"]+"_nfs_01", "security_style": "unix" } }) print("--> Starting volume create operation") try: volume.post()
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
def cifs_setup() -> None: """Script demostrates the CIFS setup using REST API PCL""" print("THE FOLLOWING SCRIPT DEMOSTRATES CIFS SETUP USING REST API PCL.") print("===============================================================") print() show_svm() print() svm_name = input( "Choose the SVM on which you would like to create a CIFS Share :") print("Make sure that NAS LIFs on each nodes are created on the SVM :") print() print("Create the Volume:-") print("===================") vol_name = input("Enter the Volume Name to be created for CIFS Share:-") vol_size = input("Enter the Volume Size in MBs :-") aggr_name = input("Enter the aggregate name:-") v_size = get_size(vol_size) pather = "/" + vol_name payload2 = { "aggregates": [{ "name": aggr_name }], "svm": { "name": svm_name }, "name": vol_name, "size": v_size, "nas": { "security_style": "ntfs", "path": pather } } volume = Volume.from_dict(payload2) try: if volume.post(poll=True): print("Volume created %s created Successfully" % volume.name) except NetAppRestError as error: print("Exception caught :" + str(error)) sys.exit() print() print("Create the Share:-") print("==================") share_name = input("Enter the share name:-") payload3 = { "path": pather, "svm": { "name": svm_name, }, "name": share_name } cifsshare = CifsShare.from_dict(payload3) try: if cifsshare.post(poll=True): print("cifsshare created Successfully") except NetAppRestError as error: print("Exception caught :" + str(error)) sys.exit()
from netapp_ontap import HostConnection from netapp_ontap.resources import Cluster, Aggregate, Port, Volume, Autosupport, IpInterface, Disk, Chassis, Account, Svm, Snapshot import urllib3 urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) conn = HostConnection('192.168.1.200', username='******', password='******', verify=False) config.CONNECTION = conn name = 'rubrik' size = 20971520 aggr = 'ntap_study_data' svm = 'study' volume = Volume.from_dict({'name': name, 'svm': {'name': svm}, 'nas': {'path': '/'+name} , 'size': size, 'aggregates': [{'name': aggr}]}) volume.post() vol = Volume.find(name=name) vol.get(fields='nas.path') print(vol.nas.path) """ #volume = Volume.find(name=name, svm=svm) #volume.delete() #for svm in Svm.get_collection(): # svm.get() # print(svm.to_dict()) volumes = []
def nfs_setup(): """Script demostrates NFS setup""" print("THE FOLLOWING SCRIPT DEMOSTRATES NFS SETUP USING REST API .") print("===========================================================") show_svm() print() svm_name = input( "Choose the SVM on which you would like to create a NFS Share :") print("Make sure that NAS LIFs on each nodes are created on the SVM.") nfsbool = input( "Would you like to enable NFS protocol on the vserver (y/n):-") if nfsbool == 'y': print("============================") payload1 = { "enabled": bool("true"), "protocol": { "v3_enabled": bool("true") }, "svm": { "name": svm_name } } try: nfsservice = NfsService.from_dict(payload1) if nfsservice.post(poll=True): print("NFS Service created created Successfully") except NetAppRestError as error: print( "Error:- " % error.http_err_response.http_response.text) print("Exception caught :" + str(error)) print("Create the Export Policy:-") print("==========================") export_policy_name = input("Enter New Export Policy Name :- ") protocol = input( "Enter the protocol name for the Export Policy(nfs/cifs/any):- ") clients = input("Enter client details [0.0.0.0/0]:- ") svm_uuid = get_key_svm(svm_name) payload2 = { "name": export_policy_name, "rules": [ { "clients": [ { "match": clients } ], "protocols": [ protocol ], "ro_rule": [ "any" ], "rw_rule": [ "any" ] } ], "svm.uuid": svm_uuid } exportpolicy = ExportPolicy.from_dict(payload2) try: if exportpolicy.post(poll=True): print("Export Policy created created Successfully") except NetAppRestError as error: print("Error:- " % error.http_err_response.http_response.text) print("Exception caught :" + str(error)) print("Create the Volume:-") print("===================") vol_name = input("Enter new Volume Name to create NFS Share:-") vol_size = input("Enter the Volume Size in MBs :-") aggr_name = input("Enter the aggregate name:-") v_size = get_size(vol_size) pather = "/" + vol_name payload3 = {"aggregates": [{"name": aggr_name}], "svm": {"name": svm_name}, "name": vol_name, "size": v_size, "nas": {"export_policy": {"name": export_policy_name}, "security_style": "unix", "path": pather}} print(payload3) volume = Volume.from_dict(payload3) try: if volume.post(poll=True): print("Volume created %s created Successfully" % volume.name) except NetAppRestError as error: print("Error:- " % error.http_err_response.http_response.text) print("Exception caught :" + str(error))
def iscsi_setup() -> None: """ Script demostrates the ISCSI Lun Setup""" print( "THE FOLLOWING SCRIPT DEMOSTRATES ISCSI LUN SETUP USING REST API PCL.") print( "====================================================================") print() show_svm() print() svm_name = input( "Choose the SVM on which you would like to create a lun : ") print( "Make sure that ISCSI protocol and LIFs on each nodes are created on the SVM" ) print() volbool = input("Would you like to create a new volume (y/n) :-") if volbool == 'y': vol_name = input("Enter the Volume Name:-") vol_size = input("Enter the Volume Size (MBs):-") aggr_name = input("Enter the aggregate name:-") v_size = get_size(vol_size) payload1 = { "name": vol_name, "svm": { "name": svm_name }, "aggregates": [{ "name": aggr_name }], "size": v_size } print(payload1) volume = Volume.from_dict(payload1) try: if volume.post(poll=True): print("Volume created created Successfully") except NetAppRestError as error: print("Error:- " % error.http_err_response.http_response.text) print("Exception caught :" + str(error)) else: print() show_volume(svm_name) vol_name = input( "Choose the volume on which you would like to create the LUN : ") print() lun_name = input("Enter the name of the LUN : ") lun_name_ext = "/vol/" + vol_name + "/" + lun_name os_type = input("Enter the name of the OS-TYPE : ") lun_size = input("Enter the LUN size in MBs :") l_size = get_size(lun_size) payload2 = { "comment": lun_name, "location": { "logical_unit": lun_name, "volume": { "name": vol_name } }, "name": lun_name_ext, "os_type": os_type, "space": { "guarantee": { "requested": bool("") }, "size": l_size }, "svm": { "name": svm_name } } lun_object = Lun.from_dict(payload2) try: if lun_object.post(poll=True): print("LUN created %s created Successfully" % lun_object.name) except NetAppRestError as error: print("Error:- " % error.http_err_response.http_response.text) print("Exception caught :" + str(error)) print() igroup_name = input( "Enter the name of the Igroup that you would like to create : ") initiator_name = input( "Enter the name of the Initiator that you would like to add in the InitiatorGroup :" ) os_type2 = input("Enter the OS-TYPE :") payload3 = { "initiators": [{ "name": initiator_name }], "name": igroup_name, "os_type": os_type2, "svm": { "name": svm_name } } igroup_object = Igroup.from_dict(payload3) try: if igroup_object.post(poll=True): print("IGROUP created %s created Successfully" % igroup_object.name) except NetAppRestError as error: print("Error:- " % error.http_err_response.http_response.text) print("Exception caught :" + str(error)) payload4 = { "igroup": { "name": igroup_name }, "lun": { "name": lun_name_ext }, "svm": { "name": svm_name } } lunmap_object = LunMap.from_dict(payload4) try: if lunmap_object.post(poll=True): print("Mapping created Successfully") except NetAppRestError as error: print("Error:- " % error.http_err_response.http_response.text) print("Exception caught :" + str(error))
def create_volume() -> None: """Create volumes""" print() show_svm() 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() 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() voltype = input("Enter the Volume Type[rw/dp]:- ") dataobj['type'] = voltype print() styletype = input("Enter the Volume Style Type:-[flexvol] ") dataobj['style'] = styletype print() autosize = input("Would you like to enable Autosize (y/n): ") if autosize == 'y': print("Enter the following Details") grow_threshold = input("grow_threshold?:- ") maximum = input("maximum?:- ") minimum = input("minimum?:- ") mode = input("mode?:- ") shrink_threshold = input("shrink_threshold?:- ") autosizejson = { "grow_threshold": grow_threshold, "maximum": maximum, "minimum": minimum, "mode": mode, "shrink_threshold": shrink_threshold } dataobj['autosize'] = autosizejson print() efficiency = input("Would you like to enable Efficiency (y/n): ") if efficiency == 'y': print("Enter the following Details") compaction = input("compaction?:- ") compression = input("compression?:- ") cross_volume_dedupe = input("cross_volume_dedupe?:- ") dedupe = input("dedupe?:- ") policy_name_e = input("Efficiency Policy Name?:- ") efficiencyjson = { "compaction": compaction, "compression": compression, "cross_volume_dedupe": cross_volume_dedupe, "dedupe": dedupe, "policy": { "name": policy_name_e } } dataobj['efficiency'] = efficiencyjson print() encryption = input("Would you like to enable Encryption (y/n): ") if encryption == 'y': print("Enter the following Details") enabled_encry = input("Enable Encryption ?:- ") encryptionjson = {"enabled": bool(enabled_encry), "status": {}} dataobj['encryption'] = encryptionjson print() files = input("Would you like to enable Max File Count (y/n): ") if files == 'y': print("Enter the following Details") maximum_files = input("Max File Count?:- ") filesjson = {"maximum": maximum_files} dataobj['files'] = filesjson print() nas = input("Would you like to enable NAS parameters (y/n): ") if nas == 'y': print("Enter the following Details") export_policy_name = input("export_policy_name?:- ") path = input("path?:- ") security_style = input("security_style?:- ") unix_permissions = input("unix_permissions?:- ") nasjson = { "export_policy": { "name": export_policy_name }, "path": path, "security_style": security_style, "unix_permissions": unix_permissions } dataobj['nas'] = nasjson print() qos = input("Would you like to enable QoS (y/n): ") if qos == 'y': print("Enter the following Details") max_throughput_iops = input("max_throughput_iops?:- ") max_throughput_mbps = input("max_throughput_mbps?:- ") min_throughput_iops = input("min_throughput_iops?:- ") qosname = input("qosname?:- ") qosjson = { "policy": { "max_throughput_iops": max_throughput_iops, "max_throughput_mbps": max_throughput_mbps, "min_throughput_iops": min_throughput_iops, "name": qosname } } dataobj['qos'] = qosjson print() quota = input("Would you like to enable Quota (y/n): ") if quota == 'y': print("Enter the following Details") enable_quota = input("enable_quota?:- ") quotajson = {"enabled": bool(enable_quota)} dataobj['quota'] = quotajson try: volume = Volume.from_dict(dataobj) if volume.post(poll=True): print("SVM %s created Successfully" % volume.name) except NetAppRestError as error: print("Error:- " % error.http_err_response.http_response.text) print("Exception caught :" + str(error))
username='******', password='******', verify=False) config.CONNECTION = conn #vol = Volume.find(name='movies') #vol.get() #print(vol) #volume = Volume(name='vol3', svm={'name': 'study'}, aggregates=[{'name': 'ntap_study_data'}]) #volume.post() #volume = Volume.find(name='soccer', svm={'name': 'study'}) #volume.get() #volume = Volume.find(name='soccer', svm={'name': 'study'}) #volume.get() volume = Volume.from_dict({ "name": "movies_clone", "clone": { "parent_volume": { "name": "movies" }, "is_flexclone": "true" }, "svm": { "name": "study" } }) volume.post()