示例#1
0
def get_isilon_client(host, username, password):
    configuration = isilon.Configuration()
    configuration.host = host
    configuration.username = username
    configuration.password = password
    configuration.verify_ssl = False  # BAD
    return isilon.NamespaceApi(isilon.ApiClient(configuration))
def main():
    # configure username and password
    configuration = isi_sdk.Configuration()
    configuration.username = test_constants.USERNAME
    configuration.password = test_constants.PASSWORD
    configuration.verify_ssl = test_constants.VERIFY_SSL
    configuration.host = test_constants.HOST

    # configure client connection
    api_client = isi_sdk.ApiClient(configuration)
    antivirus_api = isi_sdk.AntivirusApi(api_client)

    settings = antivirus_api.get_antivirus_settings()
    print("Settings=" + str(settings))

    settings.settings.repair = not settings.settings.repair
    antivirus_api.update_antivirus_settings(settings.settings)

    # verify it worked
    updated = antivirus_api.get_antivirus_settings()

    print("It worked: " +
          str(settings.settings.repair == updated.settings.repair))

    print("Done.")
示例#3
0
def main():
    # configure username and password
    configuration = isi_sdk.Configuration()
    configuration.username = test_constants.USERNAME
    configuration.password = test_constants.PASSWORD
    configuration.verify_ssl = test_constants.VERIFY_SSL
    configuration.host = test_constants.HOST

    # configure client connection
    api_client = isi_sdk.ApiClient(configuration)
    antivirus_api = isi_sdk.AntivirusApi(api_client)

    # create scan item
    new_scan_item = isi_sdk.AntivirusScanItem(file="/ifs/README.txt")

    # You'll have to specify an antivirus icap server before this will work.
    # POST the following body to /platform/3/antivirus/servers to enable it.
    # {
    #     "url": "icap://YOUR_ICAP_SERVER_ADDRESS",
    #     "enabled": True
    # }

    scan_result = \
        antivirus_api.create_antivirus_scan_item(
            antivirus_scan_item=new_scan_item)

    print("Scan result == " + str(scan_result))
    print("Done.")
 def Conn(self, host):
     configuration = isi_sdk_8_0.Configuration()
     configuration.host = 'https://{0}:8080'.format(host)
     configuration.username = self.user
     configuration.password = self.password
     configuration.verify_ssl = False
     ISIClient = isi_sdk_8_0.ApiClient(configuration)
     return ISIClient
def main():
    # configure username and password
    configuration = isi_sdk.Configuration()
    configuration.username = test_constants.USERNAME
    configuration.password = test_constants.PASSWORD
    configuration.verify_ssl = test_constants.VERIFY_SSL
    configuration.host = test_constants.HOST

    # configure client connection
    api_client = isi_sdk.ApiClient(configuration)
    clusterApi = isi_sdk.ClusterApi(api_client)

    timezone = clusterApi.get_cluster_timezone()

    print("TimeZone: " + str(timezone))

    print("Done.")
示例#6
0
def main():
    # configure username and password
    configuration = isi_sdk.Configuration()
    configuration.username = test_constants.USERNAME
    configuration.password = test_constants.PASSWORD
    configuration.verify_ssl = test_constants.VERIFY_SSL
    configuration.host = test_constants.HOST

    # configure client connection
    api_client = isi_sdk.ApiClient(configuration)
    api_instance = isi_sdk.NetworkGroupnetsApi(api_client)

    try:
        api_response = \
            api_instance.list_subnets_subnet_pools('groupnet0', 'subnet0')
        print(api_response)

    except ApiException as e:
        print("Exception when calling list_subnets_subnet_pools: %s\n" % e)
示例#7
0
def main():
    # configure username and password
    configuration = isi_sdk.Configuration()
    configuration.username = test_constants.USERNAME
    configuration.password = test_constants.PASSWORD
    configuration.verify_ssl = test_constants.VERIFY_SSL
    configuration.host = test_constants.HOST

    # configure client connection
    api_client = isi_sdk.ApiClient(configuration)
    auth_api = isi_sdk.AuthApi(api_client)

    accessUser = "******"
    path = "/ifs/data"

    get_access_user_resp = auth_api.get_auth_access_user(
        auth_access_user=accessUser, path=path)

    print("It worked: " + str(get_access_user_resp.access[0].id == accessUser))

    print("Done.")
示例#8
0
def main():
    # configure username and password
    configuration = isi_sdk.Configuration()
    configuration.username = test_constants.USERNAME
    configuration.password = test_constants.PASSWORD
    configuration.verify_ssl = test_constants.VERIFY_SSL
    configuration.host = test_constants.HOST

    # configure client connection
    api_client = isi_sdk.ApiClient(configuration)
    antivirus_api = isi_sdk.AntivirusApi(api_client)

    # update quarantine path
    update_quarantine_path_params = isi_sdk.AntivirusQuarantinePathParams()
    update_quarantine_path_params.quarantined = True

    quarantine_path = "ifs/README.txt"
    antivirus_api.update_antivirus_quarantine_path(
        antivirus_quarantine_path=quarantine_path,
        antivirus_quarantine_path_params=update_quarantine_path_params)

    # get it back and check that it worked
    get_quarantine_path_resp = \
        antivirus_api.get_antivirus_quarantine_path(quarantine_path)
    print("It worked == " + str(get_quarantine_path_resp.quarantined ==
                                update_quarantine_path_params.quarantined))

    # now unquarantine it
    update_quarantine_path_params.quarantined = False
    antivirus_api.update_antivirus_quarantine_path(
        antivirus_quarantine_path=quarantine_path,
        antivirus_quarantine_path_params=update_quarantine_path_params)

    # verify it is no longer quarantined
    get_quarantine_path_resp = \
        antivirus_api.get_antivirus_quarantine_path(quarantine_path)
    print("It worked == " + str(get_quarantine_path_resp.quarantined ==
                                update_quarantine_path_params.quarantined))

    print("Done.")
示例#9
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)
示例#10
0
def main():
    # configure username and password
    configuration = isi_sdk.Configuration()
    configuration.username = test_constants.USERNAME
    configuration.password = test_constants.PASSWORD
    configuration.verify_ssl = test_constants.VERIFY_SSL
    configuration.host = test_constants.HOST

    # configure client connection
    api_client = isi_sdk.ApiClient(configuration)
    auth_api = isi_sdk.AuthApi(api_client)

    new_auth_group = isi_sdk.AuthGroupCreateParams(name='admins')

    print("Creating group %s" % new_auth_group.name)
    try:
        create_auth_group_resp = auth_api.create_auth_group(new_auth_group)
        print("Created: %s" % create_auth_group_resp.id)
    except isi_sdk.rest.ApiException as err:
        if err.status == 409:
            print("Group %s already exists" % new_auth_group.name)
        else:
            raise err

    auth_groups = auth_api.list_auth_groups()

    found_new_group = False
    for group in auth_groups.groups:
        if group.name == new_auth_group.name:
            found_new_group = True

    print("Found it: " + str(found_new_group))

    auth_groups = auth_api.get_auth_group(auth_group_id=new_auth_group.name)

    found_new_group = False
    for group in auth_groups.groups:
        if group.name == new_auth_group.name:
            found_new_group = True

    print("Found it again: " + str(found_new_group))

    auth_group = isi_sdk.AuthGroup()
    # The only updatable value according to the description is the gid, but when i
    # try to change it, the response is that I need to include a force parameter,
    # but there is no force parameter in the description. Seems like a bug.
    auth_api.update_auth_group(auth_group_id=new_auth_group.name,
                               auth_group=auth_group)

    # try adding a member
    group_member = isi_sdk.GroupMember(name='admin', type='user')

    auth_groups_api = isi_sdk.AuthGroupsApi(api_client)
    try:
        auth_groups_api.create_group_member(group=new_auth_group.name,
                                            group_member=group_member)
    except isi_sdk.rest.ApiException as err:
        body = json.loads(err.body)
        if 'User is already in local group' in body['errors'][0]['message']:
            print('User %s is already in local group' % group_member.name)
        else:
            raise err
    except ValueError as err:
        print('Resource ID was not returned in response')

    group_members = auth_groups_api.list_group_members(
        group=new_auth_group.name)
    found_member = False
    for member in group_members.members:
        if member.name == group_member.name:
            found_member = True

    print("Found member: " + str(found_member))

    # delete the member
    auth_groups_api.delete_group_member(
        group=new_auth_group.name, group_member_id=group_members.members[0].id)

    group_members = auth_groups_api.list_group_members(
        group=new_auth_group.name)
    found_member = False
    for member in group_members.members:
        if member.name == group_member.name:
            found_member = True

    print("Deleted member: " + str(found_member == False))

    auth_api.delete_auth_group(new_auth_group.name)

    auth_groups = auth_api.list_auth_groups()
    found_new_group = False
    for group in auth_groups.groups:
        if group.name == new_auth_group.name:
            found_new_group = True

    print("Deleted it: " + str(found_new_group == False))

    print("Done.")
示例#11
0
from __future__ import print_function
from pprint import pprint
import time
import urllib3

import isi_sdk_8_0
from isi_sdk_8_0.rest import ApiException

urllib3.disable_warnings()

# configure cluster connection: basicAuth
configuration = isi_sdk_8_0.Configuration()
configuration.host = 'http://MYURL:8080'
configuration.username = '******'
configuration.password = '******'
configuration.verify_ssl = False

# create an instance of the API class
print('setting up api client')
try:
    print('get the client')
    api_client = isi_sdk_8_0.ApiClient(configuration)
except:
    print('unable to start api client')
else:
    try:
        # api_instance = isi_sdk_8_0.ProtocolsApi(api_client)
        myNamespaceAPIInstance = isi_sdk_8_0.NamespaceApi(api_client)
    except:
        print('exception setting up api instances')
    else:
def main():
    # configure username and password
    configuration = isi_sdk.Configuration()
    configuration.username = test_constants.USERNAME
    configuration.password = test_constants.PASSWORD
    configuration.verify_ssl = test_constants.VERIFY_SSL
    configuration.host = test_constants.HOST

    # configure client connection
    api_client = isi_sdk.ApiClient(configuration)
    antivirus_api = isi_sdk.AntivirusApi(api_client)

    # create a new policy
    new_policy = isi_sdk.AntivirusPolicy()
    new_policy.paths = ["/ifs/data/Isilon_Support"]
    new_policy.name = "ifs_data_support"

    # use force because path already exists as policy so would normally fail
    create_resp = antivirus_api.create_antivirus_policy(new_policy)
    print("Created=" + str(create_resp.id))

    # get it by id
    get_policy_resp = antivirus_api.get_antivirus_policy(create_resp.id)

    # update it with a PUT
    policy = get_policy_resp.policies[0]

    update_policy = isi_sdk.AntivirusPolicy()

    # toggle the browsable parameter
    update_policy.enabled = not policy.enabled

    antivirus_api.update_antivirus_policy(antivirus_policy_id=policy.id,
                                          antivirus_policy=update_policy)


    # get it back and check that it worked
    get_policy_resp = antivirus_api.get_antivirus_policy(policy.id)

    print("It worked == " +
          str(get_policy_resp.policies[0].enabled == update_policy.enabled))

    # get all policies
    antivirus_policies = antivirus_api.list_antivirus_policies()
    print("Antivirus Policies:\n" + str(antivirus_policies))

    # now delete it
    print("Deleting it.")
    antivirus_api.delete_antivirus_policy(antivirus_policy_id=create_resp.id)

    # verify that it is deleted
    # Note: my Error data model is not correct yet,
    # so get on a non-existent antivirus policy id throws exception.
    # Ideally it would just return an error response
    try:
        print("Verifying delete.")
        resp = antivirus_api.get_antivirus_policy(
            antivirus_policy_id=create_resp.id)
        print("Response should be 404, not: " + str(resp))
    except isi_sdk.rest.ApiException:
        pass

    print("Done.")
示例#13
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))