예제 #1
0
파일: apitest.py 프로젝트: raykuan/docs
if (send_oid):
    s.set_originator_id(originator_id)

# Set the Type of API Server.
#
response = s.set_server_type(server_type)

if (response and response.results_errno() != 0) :
    r = response.results_reason()
    print ("Unable to set server transport" + r + "\n")
    sys.exit (2)

if(set_timeout == 1) :

    if(timeout > 0) :
        s.set_timeout(timeout)
    
    else :
        print ("Invalid value for connection timeout." + " Connection timeout value should be greater than 0.\n") 
        sys.exit (2)

#Set the style of the server

if(host_equiv == 1) :
    s.set_style("HOSTS")


if (use_cba == 1) :
    response = s.set_style("CERTIFICATE")
    if (response):
        print("Unable to set style: " + response.results_reason() + "\n")
예제 #2
0
    def __init__(self, name, init_config, agentConfig, instances=[]):
        super(NetappIntegrationCheck, self).__init__(name, init_config,
                                                     agentConfig, instances)

        self.svms = {}

        for i in instances:
            if 'name' in i is False:
                raise Exception(
                    'Must specify a unique name for each instance.')

            if 'host' in i is False:
                raise Exception(
                    'Must specify a NetApp cluster head to connect to.')

            if 'username' in i is False:
                raise Exception('Must specify a username for ONTAP.')

            if 'password' in i and 'password_file' in i:
                raise Exception(
                    'Must specify either password or password_file, not both.')

            if ('password' in i or 'password_file' in i) is False:
                raise Exception(
                    'Must specify a password or password_file for ONTAP.')

            if 'apiVersionMajor' in i is False:
                raise Exception('Must specify an apiVersionMajor.')

            if 'apiVersionMinor' in i is False:
                raise Exception('Must specify an apiVersionMinor.')

            if 'password_file' in i:
                try:
                    with open(i.get('password_file'), 'r') as pf:
                        password = pf.read().strip()
                except Exception as e:
                    self.log.critical(
                        "Unable to open password_file %s, error %s" %
                        (i.get('password_file'), repr(e)))
                    return
            else:
                password = i.get('password')

            api_version_major, api_version_minor = i.get(
                'apiVersionMajor'), i.get('apiVersionMinor')

            try:
                api_version_major = int(api_version_major)
            except (TypeError, ValueError):
                raise Exception(
                    'Must specify an integer value for apiVersionMajor. Configured value is %s'
                    % repr(api_version_major))

            try:
                api_version_minor = int(api_version_minor)
            except (TypeError, ValueError):
                raise Exception(
                    'Must specify an integer value for apiVersionMinor. Configured value is %s'
                    % repr(api_version_minor))

            __svm__ = NaServer(i['host'], i['apiVersionMajor'],
                               i['apiVersionMinor'])
            __svm__.set_style('LOGIN')
            __svm__.set_transport_type('HTTPS')
            __svm__.set_admin_user(i['username'], password)
            __svm__.set_port(int(i.get('port', 443)))
            __svm__.set_timeout(10)

            self.svms[i['name']] = __svm__
if (send_oid):
    s.set_originator_id(originator_id)

# Set the Type of API Server.
#
response = s.set_server_type(server_type)

if (response and response.results_errno() != 0):
    r = response.results_reason()
    print("Unable to set server transport" + r + "\n")
    sys.exit(2)

if (set_timeout == 1):

    if (timeout > 0):
        s.set_timeout(timeout)

    else:
        print("Invalid value for connection timeout." +
              " Connection timeout value should be greater than 0.\n")
        sys.exit(2)

#Set the style of the server

if (host_equiv == 1):
    s.set_style("HOSTS")

if (use_cba == 1):
    response = s.set_style("CERTIFICATE")
    if (response):
        print("Unable to set style: " + response.results_reason() + "\n")
예제 #4
0
        (ntap_user, ntap_password) = get_creds_from_file(creds_file)
    if ntap_user == "":
        if int(sys.version[0]) < 3:
            ntap_user = raw_input("NTAP User: "******"NTAP User: "******"":
        ntap_password = getpass.getpass("NTAP Password: "******"create":
        snap_api = NaElement('snapshot-list-info')
        snap_api.child_add_string('volume', volume)
        results = netapp.invoke_elem(snap_api)
        ntap_invoke_err_check(results)
        snap_info = results.child_get('snapshots').children_get()
        for s in snap_info:
            name = s.child_get_string("name")
            if name == snap_name:
                ntap_delete_snap(netapp, volume, snap_name)