Example #1
0
def info(path=''):
    """
    @param path: Path to file
    @return: Generated file info page or error
    """
    os.chdir(flask.request.environ['DOCUMENT_ROOT'])
    path = os.path.normpath(path)

    if os.path.isfile(path):
        try:
            properties = [
                ['File', os.path.basename(path)],
                ['Path', '/' + os.path.split(path)[0]],
                ['Size', utils.get_size(path)],
                ['Mimetype', utils.get_mime(path)],
            ]

        except OSError:
            return flask.abort(403)

        else:
            nav = utils.populate_navbar(path)
            return flask.render_template('info.html', path=path, nav=nav, properties=properties)

    else:
        return flask.abort(404)
Example #2
0
 def add(self, path, force=False):
   MAX_SIZE = 512 * 1024 * 1024
   directory_size = utils.get_size([path])
   if (self.size + directory_size) > MAX_SIZE and not force:
     new_batch = Batch()
     new_batch.add(path, True)
     return new_batch
   else:
     self.paths.append(path)
     self.size += directory_size
   return self
Example #3
0
def main():
    if len(sys.argv) == 2:
        outdir = sys.argv[1]
    else:
        outdir = config.datadir

    while True:
        if utils.get_size(config.datadir) < config.datadir_lim:
            download(outdir)
        else:
            print("Disk full. Sleeping...")
            time.sleep(config.sleeptime)
Example #4
0
 def __init__(self, path):
     if not is_devdax(path):
         fail('Part with path "{}" does not point to dax device'
              ''.format(path))
     _Part.__init__(self, path, get_size(path))
Example #5
0
 def size(self):
     "File size in KB"
     return utils.get_size(self.fpath)
Example #6
0
 def __init__(self, path, time=None, size=None, id=None):
     self.location = os.path.abspath(path)
     self.time = time or datetime.now()
     self.size = size or utils.get_size(path)
     self.id = id or utils.get_hash_str(path, self.time)
Example #7
0
def iscsi_setup(cluster: str, headers_inc: str):
    """Demonstrates ISCSI setup using REST API"""
    print("Demonstrates ISCSI setup using REST API")
    print("====================================================")
    print()
    show_svm(cluster, headers_inc)
    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 on the SVM (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)
        payload = {
            "aggregates.name": [aggr_name],
            "svm.name": svm_name,
            "name": vol_name,
            "size": v_size,
        }

        url = "https://{}/api/storage/volumes".format(cluster)
        try:
            response = requests.post(url,
                                     headers=headers_inc,
                                     json=payload,
                                     verify=False)
            print("Volume creation completed.")
        except requests.exceptions.HTTPError as err:
            print(str(err))
            sys.exit(1)
        except requests.exceptions.RequestException as err:
            print(str(err))
            sys.exit(1)
        url_text = response.json()
        if 'error' in url_text:
            print(url_text)
            sys.exit(1)
    else:
        print()
        show_volume(cluster, headers_inc, 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
        }
    }

    url2 = "https://{}/api/storage/luns".format(cluster)
    try:
        response = requests.post(url2,
                                 headers=headers_inc,
                                 json=payload2,
                                 verify=False)
        print("LUN Creation completed.")
    except requests.exceptions.HTTPError as err:
        print(str(err))
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(str(err))
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)

    print(response.json())

    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
        }
    }

    url3 = "https://{}/api/protocols/san/igroups".format(cluster)
    try:
        response = requests.post(url3,
                                 headers=headers_inc,
                                 json=payload3,
                                 verify=False)
        print("Igroup creation completed.")
    except requests.exceptions.HTTPError as err:
        print(str(err))
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(str(err))
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)

    print(response.json())

    payload4 = {
        "igroup": {
            "name": igroup_name
        },
        "lun": {
            "name": lun_name_ext
        },
        "svm": {
            "name": svm_name
        }
    }

    url4 = "https://{}/api/protocols/san/lun-maps".format(cluster)
    try:
        response = requests.post(url4,
                                 headers=headers_inc,
                                 json=payload4,
                                 verify=False)
        print("LUN Mapping completed.")
    except requests.exceptions.HTTPError as err:
        print(str(err))
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(str(err))
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    print(response.json())
def iscsi_setup() -> None:
    """ Script demostrates the ISCSI Lun Setup"""
    print("THE FOLLOWING SCRIPT DEMOSTRATES ISCSI LUN SETUP USING REST API PCL.")
    print("====================================================================")
    show_svm()
    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")
    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
        }

        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:
        show_volume(svm_name)
        vol_name = input(
            "Choose the volume on which you would like to create the LUN : ")

    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))


    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))
Example #9
0
 def size(self):
   if self._size:
     return self._size
   self._size = utils.get_size(self.files())
   return self._size
Example #10
0
def patch_volume(cluster: str, headers_inc: str):
    """ Update a volume"""
    print("=============================================")
    show_svm(cluster, headers_inc)
    print()
    svm_name = input(
        "Enter the SVM from which the Volumes need to be listed:-")
    print()
    show_volume(cluster, headers_inc, svm_name)
    print()
    volname = input(
        "Enter the name of the volume that needs to be modified:- ")
    dataobj = {}
    dataobj['name'] = volname
    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: ")
        dataobj['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)
        dataobj['size'] = vol_size_format
    print()
    autosizebool = input("Would you like to change autosize options (y/n):- ")
    if autosizebool == '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['efficiency'] = 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

    vol_uuid = get_key_volumes(svm_name, volname, cluster, headers_inc)
    print()
    urlpath = "https://{}/api/storage/volumes/" + vol_uuid
    url = urlpath.format(cluster)
    try:
        response = requests.patch(url,
                                  headers=headers_inc,
                                  json=dataobj,
                                  verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = "https://{}{}".format(
        cluster, url_text['job']['_links']['self']['href'])
    try:
        job_response = requests.get(job_status,
                                    headers=headers_inc,
                                    verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = job_response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = job_response.json()
    check_job_status(job_status, headers_inc, cluster)
Example #11
0
def create_volume(cluster: str, headers_inc: str):
    """Create volume"""
    print()
    show_svm(cluster, headers_inc)
    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(cluster, headers_inc)
    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 MB:- ")
    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['efficiency'] = 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
    print(dataobj)
    url = "https://{}/api/storage/volumes".format(cluster)
    try:
        response = requests.post(url,
                                 headers=headers_inc,
                                 json=dataobj,
                                 verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = "https://{}{}".format(
        cluster, url_text['job']['_links']['self']['href'])
    try:
        job_response = requests.get(job_status,
                                    headers=headers_inc,
                                    verify=False)
    except requests.exceptions.HTTPError as err:
        print(err)
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(err)
        sys.exit(1)
    url_text = job_response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    job_status = job_response.json()
    check_job_status(job_status, headers_inc, cluster)
Example #12
0
def nfs_setup(cluster: str, headers_inc: str):
    """Demonstrates NFS Setup using REST APIs."""
    print("Demonstrates NFS Setup using REST APIs.")
    print("=======================================")
    print()
    show_svm(cluster, headers_inc)
    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 :")
    print()

    print("Checking and Enabling NFS Protocol on SVM:-")
    print("===========================================")

    payload1 = {
        "enabled": bool("true"),
        "protocol": {
            "v3_enabled": bool("true")
        },
        "svm": {
            "name": svm_name
        }
    }

    url1 = "https://{}/api/protocols/nfs/services".format(cluster)
    try:
        response = requests.post(url1,
                                 headers=headers_inc,
                                 json=payload1,
                                 verify=False)
    except requests.exceptions.HTTPError as err:
        print(str(err))
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(str(err))
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)

    print()
    print("Create the Export Policy:-")
    print("==========================")

    export_policy_name = input("Enter the 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]:- ")

    url2 = "https://{}/api/protocols/nfs/export-policies".format(cluster)
    svm_uuid = get_key_svms(svm_name, cluster, headers_inc)
    payload2 = {
        "name":
        export_policy_name,
        "rules": [{
            "clients": [{
                "match": clients
            }],
            "protocols": [protocol],
            "ro_rule": ["any"],
            "rw_rule": ["any"]
        }],
        "svm.uuid":
        svm_uuid
    }

    try:
        response = requests.post(url2,
                                 headers=headers_inc,
                                 json=payload2,
                                 verify=False)
    except requests.exceptions.HTTPError as err:
        print(str(err))
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(str(err))
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)

    url_text = response.json()

    print()
    print("Create the Volume:-")
    print("===================")
    vol_name = input("Enter the 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
        }
    }

    url3 = "https://{}/api/storage/volumes".format(cluster)
    try:
        response = requests.post(url3,
                                 headers=headers_inc,
                                 json=payload3,
                                 verify=False)
        print("Volume %s created" % vol_name)
    except requests.exceptions.HTTPError as err:
        print(str(err))
        sys.exit(1)
    except requests.exceptions.RequestException as err:
        print(str(err))
        sys.exit(1)
    url_text = response.json()
    if 'error' in url_text:
        print(url_text)
        sys.exit(1)
    print("NAS creation script completed.")