Example #1
0
    def get_catalog(self, uriPath, xml=False):

        if (uriPath is None):
            uriPath = ""
        elif (uriPath.startswith("/") is False):
            uriPath = "/" + uriPath

        command = singletonURIHelperInstance.getUri(
            self.COMPONENT_TYPE, "catalog")
        port = self.__port
        if(len(uriPath) == 0):
            port = common.getenv('VIPR_UI_PORT')
        (s, h) = common.service_json_request(self.__ipAddr, port, "GET",
                                             command.format(uriPath),
                                             None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')

        if (inactive):
            return None
        if (xml):
            (s, h) = common.service_json_request(self.__ipAddr, port, "GET",
                                                 command.format(uriPath),
                                                 None, None, xml)
            return s
        else:
            return o
Example #2
0
    def get_catalog(self, uriPath, xml=False):

        if (uriPath is None):
            uriPath = ""
        elif (uriPath.startswith("/") is False):
            uriPath = "/" + uriPath

        command = singletonURIHelperInstance.getUri(self.COMPONENT_TYPE,
                                                    "catalog")
        port = self.__port
        if (len(uriPath) == 0):
            port = common.getenv('VIPR_UI_PORT')
        (s, h) = common.service_json_request(self.__ipAddr, port, "GET",
                                             command.format(uriPath), None)
        o = common.json_decode(s)
        inactive = common.get_node_value(o, 'inactive')

        if (inactive):
            return None
        if (xml):
            (s, h) = common.service_json_request(self.__ipAddr, port, "GET",
                                                 command.format(uriPath), None,
                                                 None, xml)
            return s
        else:
            return o
Example #3
0
import schedulepolicy
import objectuser
import schedevent
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

from requests.packages.urllib3.exceptions import InsecurePlatformWarning
warnings.filterwarnings(
    'ignore',
    message='BaseException.message has been deprecated as of Python 2.6',
    category=DeprecationWarning,
    module='argparse')

# Fetch ViPR environment variables defined (if any)

vipr_ip = common.getenv('VIPR_HOSTNAME')
vipr_port = common.getenv('VIPR_PORT')
vipr_ui_port = common.getenv('VIPR_UI_PORT')
vipr_cli_dir = common.getenv('VIPR_CLI_INSTALL_DIR')
vipr_proxy_token = common.getenv('VIPR_PROXY_TOKEN')
vipr_username = common.getenv('VIPR_USERNAME')
vipr_password = common.getenv('VIPR_PASSWORD')
# parser having common arguments across all modules

common_parser = argparse.ArgumentParser()
common_parser.add_argument('-hostname', '-hn',
                           metavar='<hostname>',
                           default=vipr_ip,
                           dest='ip',
                           help='Hostname (fully qualified domain name) ' +
                           'or IPv4 address (i.e. 192.0.2.0) or IPv6 address' +
Example #4
0
import quotadirectory
import sanfabrics
import keystore
import truststore

import warnings

warnings.filterwarnings(
    'ignore',
    message='BaseException.message has been deprecated as of Python 2.6',
    category=DeprecationWarning,
    module='argparse')

# Fetch ViPR environment variables defined (if any)

vipr_ip = common.getenv('VIPR_HOSTNAME')
vipr_port = common.getenv('VIPR_PORT')
vipr_ui_port = common.getenv('VIPR_UI_PORT')
vipr_cli_dir = common.getenv('VIPR_CLI_INSTALL_DIR')
# parser having common arguments across all modules

common_parser = argparse.ArgumentParser()
common_parser.add_argument('-hostname',
                           '-hn',
                           metavar='<hostname>',
                           default=vipr_ip,
                           dest='ip',
                           help='Hostname (fully qualifiled domain name) ' +
                           'or IPv4 address (i.e. 192.0.2.0) or IPv6 address' +
                           ' inside quotes and brackets ' +
                           '(i.e. "[2001:db8::1]") of ViPR')
import truststore
import vnasserver
import computeimageserver
import bucket
import warnings


warnings.filterwarnings(
    'ignore',
    message='BaseException.message has been deprecated as of Python 2.6',
    category=DeprecationWarning,
    module='argparse')

# Fetch ViPR environment variables defined (if any)

vipr_ip = common.getenv('VIPR_HOSTNAME')
vipr_port = common.getenv('VIPR_PORT')
vipr_ui_port = common.getenv('VIPR_UI_PORT')
vipr_cli_dir = common.getenv('VIPR_CLI_INSTALL_DIR')
# parser having common arguments across all modules

common_parser = argparse.ArgumentParser()
common_parser.add_argument('-hostname', '-hn',
                           metavar='<hostname>',
                           default=vipr_ip,
                           dest='ip',
                           help='Hostname (fully qualifiled domain name) ' +
                           'or IPv4 address (i.e. 192.0.2.0) or IPv6 address' +
                           ' inside quotes and brackets ' +
                           '(i.e. "[2001:db8::1]") of ViPR')
common_parser.add_argument('-port', '-po',
    def authenticate_user(self, username, password, cookiedir, cookiefile):
        '''
        Makes REST API call to generate the cookiefile for the 
        specified user after validation.
        Returns:
            SUCCESS OR FAILURE
        '''
        SEC_REDIRECT                = 302 
        SEC_AUTHTOKEN_HEADER        = 'X-SDS-AUTH-TOKEN' 
        LB_API_PORT                 = 4443    # Port on which load-balancer/reverse-proxy listens to all incoming requests for ViPR REST APIs
        APISVC_PORT                 = 8443    # Port on which apisvc listens to incoming requests
        
        cookiejar=cookielib.LWPCookieJar()

        url = 'https://'+str(self.__ipAddr)+':'+str(self.__port)+self.URI_AUTHENTICATION

        try:
            if(self.__port == APISVC_PORT):
                login_response = requests.get(url, headers=self.HEADERS, verify=False,
                                          auth=(username,password), cookies=cookiejar, allow_redirects=False, timeout=common.TIMEOUT_SEC)
                if(login_response.status_code == SEC_REDIRECT):
                    location = login_response.headers['Location'] 
                    if(not location): 
                       raise SOSError(SOSError.HTTP_ERR, "The redirect location of the authentication service is not provided") 
                    # Make the second request 
                    login_response = requests.get(location, headers=self.HEADERS, verify=False, cookies=cookiejar, 
                                                        allow_redirects=False, timeout=common.TIMEOUT_SEC) 
                    if(not login_response.status_code == requests.codes['unauthorized']): 
                        raise SOSError(SOSError.HTTP_ERR, "The authentication service failed to reply with 401")
     
                    # Now provide the credentials 
                    login_response = requests.get(location, headers=self.HEADERS, auth=(username,password), verify=False, 
                                               cookies=cookiejar, allow_redirects=False, timeout=common.TIMEOUT_SEC) 
                    if(not login_response.status_code == SEC_REDIRECT): 
                        raise SOSError(SOSError.HTTP_ERR, "Access forbidden: Authentication required") 
                    location = login_response.headers['Location'] 
                    if(not location): 
                        raise SOSError(SOSError.HTTP_ERR, "The authentication service failed to provide the location of the service URI when redirecting back") 
                    authToken = login_response.headers[SEC_AUTHTOKEN_HEADER] 
                    if (not authToken): 
                        raise SOSError(SOSError.HTTP_ERR, "The token is not generated by authentication service") 
                    # Make the final call to get the page with the token 
                    newHeaders = self.HEADERS 
                    newHeaders[SEC_AUTHTOKEN_HEADER] = authToken 
                    login_response = requests.get(location, headers=newHeaders, verify=False, cookies=cookiejar, 
                                              allow_redirects=False, timeout=common.TIMEOUT_SEC) 
                    if(login_response.status_code != requests.codes['ok']): 
                        raise SOSError(SOSError.HTTP_ERR, "Login failure code: " + str(login_response.status_code) + " Error: " + login_response.text)
            elif(self.__port == LB_API_PORT):
                login_response = requests.get(url, headers=self.HEADERS, verify=False, cookies=cookiejar, allow_redirects=False)
                if(login_response.status_code == requests.codes['unauthorized']):
                    # Now provide the credentials
                    login_response = requests.get(url, headers=self.HEADERS, auth=(username,password), verify=False, cookies=cookiejar, allow_redirects=False)
                authToken = login_response.headers[SEC_AUTHTOKEN_HEADER] 
            else:
                raise SOSError(SOSError.HTTP_ERR, "Incorrect port number.  Load balanced port is: " +
                    str(LB_API_PORT) +
                    ", api service port is: " +
                    str(APISVC_PORT) +
                    ".")

            if (not authToken):
                raise SOSError(SOSError.HTTP_ERR, "The token is not generated by authentication service")    

            if (login_response.status_code != requests.codes['ok']):
                error_msg=None
                if(login_response.status_code == 401):
                    error_msg = "Access forbidden: Authentication required"
                elif(login_response.status_code == 403):
                    error_msg = "Access forbidden: You don't have sufficient privileges to perform this operation"
                elif(login_response.status_code == 500):
                    error_msg="Bourne internal server error"
                elif(login_response.status_code == 404):
                    error_msg="Requested resource is currently unavailable"
                elif(login_response.status_code == 405):
                    error_msg = "GET method is not supported by resource: " + url
                elif(login_response.status_code == 503):
                    error_msg = "Service temporarily unavailable: The server is temporarily unable to service your request"
                else:
                    error_msg=login_response.text
                    if isinstance(error_msg, unicode):
                        error_msg = error_msg.encode('utf-8')
                raise SOSError(SOSError.HTTP_ERR, "HTTP code: " +
                    str(login_response.status_code) +
                    ", response: " + str(login_response.reason) +
                    " [" + str(error_msg) + "]")
        
        except (SSLError, socket.error, ConnectionError, Timeout) as e:
            raise SOSError(SOSError.HTTP_ERR, str(e))

        
        form_cookiefile= None
        parentshellpid = None
        installdir_cookie = None
        if sys.platform.startswith('linux'):
            parentshellpid = os.getpid()
            if(cookiefile is None):
                if (parentshellpid is not None):
                    cookiefile=str(username)+'cookie'+str(parentshellpid)
                else:
                    cookiefile=str(username)+'cookie'
            form_cookiefile = cookiedir+'/'+cookiefile
            if (parentshellpid is not None):
                installdir_cookie = '/cookie/'+str(parentshellpid)
            else:
                installdir_cookie = '/cookie/cookiefile' 
        elif sys.platform.startswith('win'):
            if (cookiefile is None):
                cookiefile=str(username)+'cookie'
            form_cookiefile = cookiedir+'\\'+cookiefile
            installdir_cookie = '\\cookie\\cookiefile'
        else:
            if (cookiefile is None):
                cookiefile=str(username)+'cookie'
            form_cookiefile = cookiedir+'/'+cookiefile
            installdir_cookie = '/cookie/cookiefile'
	try:
            if(common.create_file(form_cookiefile)):
                tokenFile = open(form_cookiefile , "w") 
                if(tokenFile):
                    tokenFile.write(authToken) 
                    tokenFile.close()
                else:
                    raise SOSError(SOSError.NOT_FOUND_ERR,
                            " Failed to save the cookie file path "
                            + form_cookiefile) 

	except (OSError) as e:
               raise SOSError(e.errno, cookiedir +" "+e.strerror)
	except IOError as e:
		raise SOSError(e.errno , e.strerror)



        if (common.create_file(form_cookiefile)):
            #cookiejar.save(form_cookiefile, ignore_discard=True, ignore_expires=True);
            sos_cli_install_dir= common.getenv('VIPR_CLI_INSTALL_DIR')
            if (sos_cli_install_dir):
                if (not os.path.isdir(sos_cli_install_dir)):  
                    raise SOSError(SOSError.NOT_FOUND_ERR,
                     sos_cli_install_dir+" : Not a directory")    
                config_file = sos_cli_install_dir+installdir_cookie
                if (common.create_file(config_file)):
                    fd = open(config_file,'w+')
                    if (fd):
                        fd_content=os.path.abspath(form_cookiefile)+'\n'
                        fd.write(fd_content)
                        fd.close()
                        ret_val=username+' : Authenticated Successfully\n'+ \
                        form_cookiefile+' : Cookie saved successfully'
                    else:
                        raise SOSError(SOSError.NOT_FOUND_ERR,
                            config_file+" : Failed to save the cookie file path " 
                            + form_cookiefile)
                else:
                    raise SOSError(SOSError.NOT_FOUND_ERR,
                        config_file+" : Failed to create file")
            
            else:
                raise SOSError(SOSError.NOT_FOUND_ERR,
                    "VIPR_CLI_INSTALL_DIR is not set. Please check viprcli.profile")
        return ret_val
Example #7
0
    '--email',
    type=str,
    action='store',
    help=
    'email address to validate. May carry multiple addresses, comma-separated, no spaces'
)
parser.add_argument(
    '-o',
    '--outfile',
    type=argparse.FileType('w'),
    default='-',
    help='filename to write validation results to (in .CSV format)')
parser.add_argument('--skip_precheck',
                    action='store_true',
                    help='Skip the precheck of input file email syntax')
args = parser.parse_args()

apiKey = getenv_check('SPARKPOST_API_KEY')  # API key is mandatory
host = hostCleanup(getenv('SPARKPOST_HOST', default='api.sparkpost.com'))
url = host + '/api/v1/recipient-validation/single/'

snooze = 10
if args.email:
    cmdInfile = io.StringIO(args.email.replace(',', '\n'))
    cmdInfile.name = 'from command line'
    processFile(cmdInfile, args.outfile, url, apiKey, snooze,
                args.skip_precheck)
else:
    processFile(args.infile, args.outfile, url, apiKey, snooze,
                args.skip_precheck)
Example #8
0
import objectuser
import schedevent
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning

from requests.packages.urllib3.exceptions import InsecurePlatformWarning

warnings.filterwarnings(
    'ignore',
    message='BaseException.message has been deprecated as of Python 2.6',
    category=DeprecationWarning,
    module='argparse')

# Fetch ViPR environment variables defined (if any)

vipr_ip = common.getenv('VIPR_HOSTNAME')
vipr_port = common.getenv('VIPR_PORT')
vipr_ui_port = common.getenv('VIPR_UI_PORT')
vipr_cli_dir = common.getenv('VIPR_CLI_INSTALL_DIR')
vipr_proxy_token = common.getenv('VIPR_PROXY_TOKEN')
vipr_username = common.getenv('VIPR_USERNAME')
vipr_password = common.getenv('VIPR_PASSWORD')
# parser having common arguments across all modules

common_parser = argparse.ArgumentParser()
common_parser.add_argument('-hostname',
                           '-hn',
                           metavar='<hostname>',
                           default=vipr_ip,
                           dest='ip',
                           help='Hostname (fully qualified domain name) ' +