Beispiel #1
0
     export_id = {}
     configuration.host = "https://" + add_exports_host + ":8080"
     configuration.username = isln_user
     configuration.password = isln_password
     configuration.verify_ssl = False
     isilon = isi_sdk_8_0.ApiClient(configuration)
     addr = socket.gethostbyname(sh[0])
     isilon_network = isi_sdk_8_0.NetworkApi(isilon)
     net_results = isilon_network.get_network_pools()
     for p in net_results.pools:
         for r in p.ranges:
             ip_range = list(netaddr.iter_iprange(r.low,r.high))
             if netaddr.IPAddress(addr) in ip_range:
                 zone = p.access_zone
                 break
     isilon_protocols = isi_sdk_8_0.ProtocolsApi(isilon)
     alias_results = isilon_protocols.list_nfs_aliases(zone=zone)
     for a in alias_results.aliases:
         alias = (a.name,a.path)
         alias_list.append(alias)
     exports_results = isilon_protocols.list_nfs_exports(zone=zone)
     for ex in exports_results.exports:
         ex_instance = (ex.paths[0],ex.root_clients)
         ex_list.append(ex_instance)
         export_id[ex.paths[0]] = ex.id
     exports[sh[0]] = Exports(zone, alias_list, export_list, ex_list)
 path = sh[1]
 for a in exports[sh[0]].aliases:
     if sh[1] in a:
         path = a[1]
         break
Beispiel #2
0
def isln_get_share_list(host, user, password, protocol, sc_zone_list, az_list):
    hostname = {}
    aliases = {}

    # Set up Isilon API Session

    configuration = isi_sdk_8_0.Configuration()
    configuration.host = "https://" + host + ":8080"
    configuration.username = user
    configuration.password = password
    configuration.verify_ssl = False
    isilon = isi_sdk_8_0.ApiClient(configuration)

    # Generate Access Zone list if not given on CLI

    if not az_list:
        isilon_zones = isi_sdk_8_0.ZonesApi(isilon)
        try:
            result = isilon_zones.list_zones()
        except ApiException as e:
            sys.stderr.write("Error calling list_zones: " + str(e) + "\n")
            exit(1)
        for z in result.zones:
            az_list.append(z.name)

# Look at Network pools, find an applicable pool for each access zone.  Grab the SC Zone name if available

    isilon_network = isi_sdk_8_0.NetworkApi(isilon)
    try:
        result_pools = isilon_network.get_network_pools()
    except ApiException as e:
        sys.stderr.write("Error calling network_pools: " + str(e) + "\n")
        exit(1)
    if sc_zone_list:
        for p in result_pools.pools:
            if p.sc_dns_zone in sc_zone_list:
                hostname[p.access_zone] = p.sc_dns_zone
    for p in result_pools.pools:
        if p.access_zone in hostname.keys():
            continue
        if p.sc_dns_zone:
            hostname[p.access_zone] = p.sc_dns_zone
        else:
            hostname[p.access_zone] = p.ranges[0].low


# For each access zone, grab the NFS exports or SMB shares.  Generate the share_list structure for main()

    for zone in az_list:
        alias_instance = ()
        al_list = []
        zone_share_list = []
        isilon_protocols = isi_sdk_8_0.ProtocolsApi(isilon)
        if protocol == "nfs":
            try:
                result_aliases = isilon_protocols.list_nfs_aliases(zone=zone)
            except ApiException as e:
                sys.stderr.write("Error calling nfs_aliases: " + str(e) + "\n")
                exit(1)
            for alias in result_aliases.aliases:
                alias_instance = (alias.name, alias.path)
                al_list.append(alias_instance)
            try:
                results_exports = isilon_protocols.list_nfs_exports(zone=zone)
            except ApiException as e:
                sys.stderr.write("Error calling nfs_exports: " + str(e) + "\n")
                exit(1)
            for x in results_exports.exports:
                for p in x.paths:
                    if p == "/ifs":  # Exclude a root export
                        continue
                    found_alias = False
                    for a in al_list:
                        if p in a:
                            zone_share_list.append(a[0])
                            found_alias = True
                    if not found_alias:
                        zone_share_list.append(p)
        elif protocol == "smb" or protocol == "cifs":
            try:
                results_exports = isilon_protocols.list_smb_shares(zone=zone)
            except ApiException as e:
                sys.stderr.write("Error calling smb_shares: " + str(e) + "\n")
                exit(1)
            for x in results_exports.shares:
                if x.path == "/ifs":  # Exclude any /ifs root shares
                    continue
                zone_share_list.append(x.name)

        share_list[hostname[zone]] = zone_share_list
    return (share_list)
Beispiel #3
0
def add_isilon_shares(rubrik, host, protocol, add_list, az_list,
                      export_id_list, nas_host_data, config):
    configuration = isi_sdk_8_0.Configuration()
    configuration.host = "https://" + host + ":8080"
    configuration.username = config['array_user']
    configuration.password = config['array_password']
    configuration.verify_ssl = False
    isilon = isi_sdk_8_0.ApiClient(configuration)
    isilon_protocols = isi_sdk_8_0.ProtocolsApi(isilon)
    dprint("Add_LIST: " + str(add_list))
    if protocol == "nfs":
        addr_list = []
        rubrik_net = rubrik.get('internal',
                                '/cluster/me/network_interface',
                                timeout=60)
        for n in rubrik_net['data']:
            for i in n['ipAddresses']:
                addr_list.append(i)
        rubrik_net = rubrik.get('internal',
                                '/cluster/me/floating_ip',
                                timeout=60)
        for f in rubrik_net['data']:
            if f['ip'] in addr_list:
                addr_list.remove(f['ip'])
    for nas_host in add_list:
        zone = get_zone_from_name(nas_host, az_list)
        host_id = get_hostid_from_nas_data(nas_host, nas_host_data)
        skipped_shares = []
        for share in add_list[nas_host]:
            if protocol == "smb":
                rf = config['smb_user'].split('@')
                rf2 = rf[1].split('.')
                user = rf2[0] + "\\" + rf[0]
                if zone != "System" or FORCE_SMB_ACL:
                    share_results = isilon_protocols.get_smb_share(share,
                                                                   zone=zone)
                    add_rar = True
                    for sh_data in share_results.shares:
                        for rar in sh_data.run_as_root:
                            if rar.type == "user" and rar.name.lower(
                            ) == user.lower():
                                add_rar = False
                                break
                        if add_rar:
                            dprint("Adding rar to " + share)
                            new_rar_data = {'type': 'user', 'name': user}
                            sh_data.run_as_root.append(new_rar_data)
                            new_rar = {'run_as_root': sh_data.run_as_root}
                            share_update = isilon_protocols.update_smb_share(
                                new_rar, share, zone=zone)
                            fix_perms = {'permissions': sh_data.permissions}
                            share_udpate = isilon_protocols.update_smb_share(
                                fix_perms, share, zone=zone)


#                payload = {'hostId': host_id, 'shareType': protocol.upper(), 'exportPoint': share, 'user': rf[0], 'password': config['smb_password'], 'domain': rf[1]}
            elif protocol == "nfs":
                print("Adding Export: " + nas_host + ":" + share)
                export_info = isilon_protocols.get_nfs_export(
                    export_id_list[share], zone=zone)
                dprint("ROOT_MAP: " +
                       str(export_info.exports[0].map_root.user.id))
                if export_info.exports[
                        0].map_root.user.id != "USER:root" and export_info.exports[
                            0].map_root.user.id != "UID:0":
                    root_clients = export_info.exports[0].root_clients
                    nfs_rc_add_list = []
                    for rubrik_ip in addr_list:
                        found = False
                        add_ips_to_export = False
                        for rc in root_clients:
                            if '/' in rc:
                                subnet = ipaddress.ip_network(unicode(rc))
                                node_ip = ipaddress.ip_address(
                                    unicode(rubrik_ip))
                                if node_ip in subnet:
                                    found = True
                                    break
                            else:
                                if rubrik_ip == rc:
                                    found = True
                                    break
                            if not found:
                                root_clients.append(rubrik_ip)
                                add_ips_to_export = True
                        if add_ips_to_export:
                            rc_update = {'root_clients': root_clients}
                            dprint(rc_update)
                            try:
                                update_exports = isilon_protocols.update_nfs_export(
                                    rc_update,
                                    export_id_list[share],
                                    ignore_unresolvable_hosts=True,
                                    ignore_bad_paths=True,
                                    zone=zone)
                            except ApiException as e:
                                sys.stderr.write(
                                    "Exception calling update_nfs_export: " +
                                    str(e))
            payload = {
                'hostId': host_id,
                'shareType': protocol.upper(),
                'exportPoint': share
            }
            dprint("PAYLOAD: " + str(payload))
            sh_add_flag = True
            try:
                share_id = rubrik.post('internal',
                                       '/host/share',
                                       payload,
                                       timeout=60)['id']
            except rubrik_cdm.exceptions.APICallException as e:
                sys.stderr.write("Share add failed: " + str(e) + "\n")
                skipped_shares.append(share)
                sh_add_flag = False
            if sh_add_flag and config['default_nfs_fileset']:
                add_fileset_sla_to_share(rubrik, config, share_id, protocol)
        if skipped_shares:
            print("Failed Shares on " + nas_host + ": " + str(skipped_shares))