예제 #1
0
def connect_svm(in_args):

    # type and syntax checking on command line args
    obj_regexp = re.compile(
        r'^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$|^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](\.[a-zA-Z0-9\-]{2,}){0,6}$'
    )
    if (not (obj_regexp.match(in_args.svm))):
        sys.exit(
            "error: the svm parameter must be either an IP address or a hostname"
        )

    # connect to svm
    obj_svm = NaServer(in_args.svm, 1, 3)
    obj_svm.set_transport_type('HTTPS')
    if (in_args.cert is None):
        obj_svm.set_style('LOGIN')
        string_username = raw_input("login as: ")
        string_password = getpass.getpass()
        obj_svm.set_admin_user(string_username, string_password)
    else:
        result = obj_svm.set_style('CERTIFICATE')
        obj_svm.set_server_cert_verification(0)
        obj_svm.set_client_cert_and_key(in_args.cert[0], in_args.cert[1])

    # check that the api is reachable
    result = obj_svm.invoke("system-get-version")
    if (result.results_status() == "failed"):
        sys.exit("error: cannot connect to filer; " + result.results_reason())

    return obj_svm
예제 #2
0
파일: apitest.py 프로젝트: raykuan/docs
    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")
        sys.exit(2)
    response = s.set_client_cert_and_key(cert_file, client_key)
    if (response):
        print(response.results_reason() + "\n")
        sys.exit(2)

if (dossl or need_server_cert_verification):
    response = s.set_server_cert_verification(need_server_cert_verification)
    if (response):
        print(response.results_reason() + "\n")
        sys.exit(2)
    if (need_server_cert_verification):
        response = s.set_hostname_verification(need_hostname_verification)
        if (response):
            print(response.results_reason() + "\n")
            sys.exit(2)
    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")
        sys.exit(2)
    response = s.set_client_cert_and_key(cert_file, client_key)
    if (response):
        print(response.results_reason() + "\n")
        sys.exit(2)

if (dossl or need_server_cert_verification):
    response = s.set_server_cert_verification(need_server_cert_verification)
    if (response):
        print(response.results_reason() + "\n")
        sys.exit(2)
    if (need_server_cert_verification):
        response = s.set_hostname_verification(need_hostname_verification)
        if (response):
            print(response.results_reason() + "\n")
            sys.exit(2)
예제 #4
0
#!/usr/bin/env python

import sys
sys.path.append("NMSDKpy")
from NaServer import *

cluster = "svlngen4-c01-trad-gen001"
transport = "HTTPS"
port = 443 
style = "CERTIFICATE"
cert = "devops_cert.pem"
key = "devops_cert.key"

s = NaServer(cluster, 1, 30)
s.set_transport_type(transport)
s.set_port(port)
s.set_style(style)
s.set_server_cert_verification(0)
s.set_client_cert_and_key(cert, key)

api = NaElement("system-get-version")
output = s.invoke_elem(api)
if (output.results_status() == "failed"):
    r = output.results_reason()
    print("Failed: " + str(r))
    sys.exit(2)

ontap_version = output.child_get_string("version")
print ("V: " + ontap_version)