Python __main__.display.vvvv() Examples

The following are 16 code examples of __main__.display.vvvv(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module __main__.display , or try the search function .
Example #1
Source File: Example4.LookUpPlugin.py    From Implementing-DevOps-with-Ansible-2 with MIT License 6 votes vote down vote up
def run(self, terms, variables=None, **kwargs):

        ret = []
        # Perform iteration
        for term in terms:

            display.debug("File lookup term: %s" % term)

            # Find the file in the expected search path
            lookupfile = self.find_file_in_search_path(variables, 'files', term)
            display.vvvv(u"File lookup using %s as file" % lookupfile)
            try:
                if lookupfile:
                    contents, show_data = self._loader._get_file_contents(lookupfile)
                    ret.append(contents.rstrip())
                else:
                    raise AnsibleParserError()

            except AnsibleParserError:
                raise AnsibleError("could not locate file in lookup: %s" % term) 
Example #2
Source File: csvtojson.py    From infra-ansible with Apache License 2.0 6 votes vote down vote up
def get_user_groups(self, rows):

        display.vvvv(u"Getting user groups")

        userGroupsDict = {}

        userGroupList = []

        for row in rows:
            if row['group'] not in userGroupsDict :
                userGroupsDict[row['group']] = []

            userGroupsDict[row['group']].append(row['user_name'])

        for key in userGroupsDict :
            userGroupList.append({ "name": key, "members": userGroupsDict[key]})

        return json.dumps(userGroupList) 
Example #3
Source File: csvtojson.py    From infra-ansible with Apache License 2.0 6 votes vote down vote up
def get_user_groups(self, rows):

        display.vvvv(u"Getting user groups")

        userGroupsDict = {}

        userGroupList = []

        for row in rows:
            if row['group'] not in userGroupsDict :
                userGroupsDict[row['group']] = []

            userGroupsDict[row['group']].append(row['user_name'])

        for key in userGroupsDict :
            userGroupList.append({ "name": key, "members": userGroupsDict[key]})

        return json.dumps(userGroupList) 
Example #4
Source File: csvtojson.py    From infra-ansible with Apache License 2.0 5 votes vote down vote up
def get_users(self, rows):

        display.vvvv(u"Getting users")

        return json.dumps(rows)

    # get json for groups - need to maniuplate the rows a bit.
    # take username, group and transfrom to { name: mygroup, members: [ user_name: user1 }, { user_name: user2 } ]} 
Example #5
Source File: csvtojson.py    From infra-ansible with Apache License 2.0 5 votes vote down vote up
def get_users(self, rows):

        display.vvvv(u"Getting users")

        return json.dumps(rows)

    # get json for groups - need to maniuplate the rows a bit.
    # take username, group and transfrom to { name: mygroup, members: [ user_name: user1 }, { user_name: user2 } ]} 
Example #6
Source File: csvtojson.py    From infra-ansible with Apache License 2.0 5 votes vote down vote up
def get_users(self, rows):

        display.vvvv(u"Getting users")

        return json.dumps(rows)

    # get json for groups - need to maniuplate the rows a bit.
    # take username, group and transfrom to { name: mygroup, members: [ user_name: user1 }, { user_name: user2 } ]} 
Example #7
Source File: ftd.py    From FTDAnsible with GNU General Public License v3.0 5 votes vote down vote up
def _lookup_login_url(self, payload):
        """ Try to find correct login URL and get api token using this URL.

        :param payload: Token request payload
        :type payload: dict
        :return: token generation response
        """
        preconfigured_token_path = self._get_api_token_path()
        if preconfigured_token_path:
            token_paths = [preconfigured_token_path]
        else:
            token_paths = self._get_known_token_paths()

        for url in token_paths:
            try:
                response = self._send_login_request(payload, url)

            except ConnectionError as e:
                display.vvvv('REST:request to {0} failed because of connection error: {1}'.format(url, e))
                # In the case of ConnectionError caused by HTTPError we should check response code.
                # Response code 400 returned in case of invalid credentials so we should stop attempts to log in and
                # inform the user.
                if hasattr(e, 'http_code') and e.http_code == 400:
                    raise
            else:
                if not preconfigured_token_path:
                    self._set_api_token_path(url)
                return response

        raise ConnectionError(INVALID_API_TOKEN_PATH_MSG if preconfigured_token_path else MISSING_API_TOKEN_PATH_MSG) 
Example #8
Source File: ftd.py    From FTDAnsible with GNU General Public License v3.0 5 votes vote down vote up
def _display(self, http_method, title, msg=''):
        display.vvvv('REST:{0}:{1}:{2}\n{3}'.format(http_method, self.connection._url, title, msg)) 
Example #9
Source File: arubaoscx_rest.py    From aruba-ansible-modules with Apache License 2.0 5 votes vote down vote up
def _connect(self):
        if self._connected:
            return
        display.vvvv("Opening the rest session now")
        payload = {'action': 'login', 'username': self._username, 'password': self._password}
        self._http_session_handle = requests.session()
        self._http_session_handle.trust_env = False
        response = self._http_session_handle.post(self._login_url, data=payload, verify=False)
        display.vvvv("Login response")
        display.vvvv(response.text)
        display.vvvv("The session object is")
        display.vvvv("=== ======= ====== ==")
        display.vvvv(str(self._http_session_handle))
        self._connected = True 
Example #10
Source File: arubaoscx_rest.py    From aruba-ansible-modules with Apache License 2.0 5 votes vote down vote up
def reset(self):
        '''
        Reset the connection
        '''
        if self._socket_path:
            display.vvvv('resetting persistent connection for socket_path %s' % self._socket_path, host=self.host)
            self.close()
        display.vvvv('reset call on connection instance', host=self.host) 
Example #11
Source File: arubaoscx_rest.py    From aruba-ansible-modules with Apache License 2.0 5 votes vote down vote up
def close(self):
        if self._connected:
            response = self._http_session_handle.post(self._logout_url, verify=False)
            display.debug("Hi! Closing the http connection now")
            display.vvvv(response.text)
            display.display("Closed the http connection!")
            self._connected = False 
Example #12
Source File: arubaoss.py    From aruba-ansible-modules with Apache License 2.0 5 votes vote down vote up
def run(self, tmp=None, task_vars=None):
        del tmp  # tmp no longer has any effect

        socket_path = None

        if self._play_context.connection == 'local' or self._play_context.connection == 'network_cli':
            provider = load_provider(arubaoss_provider_spec, self._task.args)
            transport = provider['transport'] or 'aossapi'

            display.vvvv('connection transport is %s for %s' % (transport, self._play_context.remote_addr))
            if not provider.get('api_version') is None:
                api = provider.get('api_version')
                if api not in ['v1.0','v2.0','v2.1','v2.2','v3.0','v3.1','v4.0','v5.0']:
                    provider['api_version'] = None
                    display.vvvv('%s is not valid api version. using aossapi v6.0 instead' % api)
                else:
                    display.vvvv('%s is not latest version (v6.0), arubaoss module may not work as intended' % api)


            if transport == 'cli':
                return dict(
                        failed=True,
                        msg='invalid connection specified, expected connection=local, '
                        'got %s' % self._play_context.connection)
            else:
                self._task.args['provider'] = ActionModule.aossapi_implementation(provider, self._play_context)

        result = super(ActionModule, self).run(task_vars=task_vars)
        return result 
Example #13
Source File: csvtojson.py    From infra-ansible with Apache License 2.0 4 votes vote down vote up
def run(self, terms, variables=None, **kwargs):

        ret = []

        cwd = os.getcwd()

        for term in terms:

            params = term.split()

            paramvals = {
                'file' : 'users.csv',
                'var' : 'users'
            }

            # parameters specified?
            try:
                for param in params:
                    name, value = param.split('=')
                    assert(name in paramvals)
                    paramvals[name] = value
                    display.vvvv(u"Param: %s : %s" % (name, value))
            except (ValueError, AssertionError) as e:
                raise AnsibleError(e)

            if os.path.isabs(paramvals['file']):
              lookupfile = paramvals['file']
            else:
              lookupfile = cwd + '/' + paramvals['file']

            display.vvvv(u"File lookup using %s as file" % paramvals['file'])
            try:
                if lookupfile:
                    #read csv into rows
                    with open(lookupfile) as f:
                        reader = csv.DictReader(f)
                        rows = list(reader)

                    # do output for users or groups
                    if(paramvals['var'] == 'user_groups'):
                        ret.append(self.get_user_groups(rows))
                    else:
                        ret.append(self.get_users(rows))

                else:
                    raise AnsibleParserError()
            except AnsibleParserError:
                raise AnsibleError("could not locate file in lookup: %s" % paramvals['file'])

        return ret

    # get json for users - file should already support this format 
Example #14
Source File: csvtojson.py    From infra-ansible with Apache License 2.0 4 votes vote down vote up
def run(self, terms, variables=None, **kwargs):

        ret = []

        cwd = os.getcwd()

        for term in terms:

            params = term.split()

            paramvals = {
                'file' : 'users.csv',
                'var' : 'users'
            }

            # parameters specified?
            try:
                for param in params:
                    name, value = param.split('=')
                    assert(name in paramvals)
                    paramvals[name] = value
                    display.vvvv(u"Param: %s : %s" % (name, value))
            except (ValueError, AssertionError) as e:
                raise AnsibleError(e)

            if os.path.isabs(paramvals['file']):
              lookupfile = paramvals['file']
            else:
              lookupfile = cwd + '/' + paramvals['file']

            display.vvvv(u"File lookup using %s as file" % paramvals['file'])
            try:
                if lookupfile:
                    #read csv into rows
                    with open(lookupfile) as f:
                        reader = csv.DictReader(f)
                        rows = list(reader)

                    # do output for users or groups
                    if(paramvals['var'] == 'user_groups'):
                        ret.append(self.get_user_groups(rows))
                    else:
                        ret.append(self.get_users(rows))

                else:
                    raise AnsibleParserError()
            except AnsibleParserError:
                raise AnsibleError("could not locate file in lookup: %s" % paramvals['file'])

        return ret

    # get json for users - file should already support this format 
Example #15
Source File: csvtojson.py    From infra-ansible with Apache License 2.0 4 votes vote down vote up
def run(self, terms, variables=None, **kwargs):

        ret = []

        cwd = os.getcwd()

        for term in terms:

            params = term.split()

            paramvals = {
                'file' : 'users.csv',
                'var' : 'users'
            }

            # parameters specified?
            try:
                for param in params:
                    name, value = param.split('=')
                    assert(name in paramvals)
                    paramvals[name] = value
                    display.vvvv(u"Param: %s : %s" % (name, value))
            except (ValueError, AssertionError) as e:
                raise AnsibleError(e)

            if os.path.isabs(paramvals['file']):
              lookupfile = paramvals['file']
            else:
              lookupfile = cwd + '/' + paramvals['file']

            display.vvvv(u"File lookup using %s as file" % paramvals['file'])
            try:
                if lookupfile:
                    #read csv into rows
                    with open(lookupfile) as f:
                        reader = csv.DictReader(f)
                        rows = list(reader)

                    # do output for users or groups
                    if(paramvals['var'] == 'user_groups'):
                        ret.append(self.get_user_groups(rows))
                    else:
                        ret.append(self.get_users(rows))

                else:
                    raise AnsibleParserError()
            except AnsibleParserError:
                raise AnsibleError("could not locate file in lookup: %s" % paramvals['file'])

        return ret

    # get json for users - file should already support this format 
Example #16
Source File: ce.py    From CloudEngine-Ansible with GNU General Public License v3.0 4 votes vote down vote up
def run(self, tmp=None, task_vars=None):
        if self._play_context.connection != 'local':
            return dict(
                failed=True,
                msg='invalid connection specified, expected connection=local, '
                    'got %s' % self._play_context.connection
            )

        provider = self.load_provider()
        transport = provider['transport'] or 'cli'

        display.vvvv('connection transport is %s' % transport, self._play_context.remote_addr)

        if transport == 'cli':
            pc = copy.deepcopy(self._play_context)
            pc.connection = 'network_cli'
            pc.network_os = 'ce'
            pc.remote_addr = provider['host'] or self._play_context.remote_addr
            pc.port = int(provider['port']) or int(self._play_context.port) or 22
            pc.remote_user = provider['username'] or self._play_context.connection_user
            pc.password = provider['password'] or self._play_context.password
            pc.timeout = provider['timeout'] or self._play_context.timeout
            self._task.args['provider'] = provider.update(
                host=pc.remote_addr,
                port=pc.port,
                username=pc.remote_user,
                password=pc.password
                #ssh_keyfile=pc.private_key_file
            )
            display.vvv('using connection plugin %s' % pc.connection, pc.remote_addr)
            connection = self._shared_loader_obj.connection_loader.get('persistent', pc, sys.stdin)
            socket_path = self._get_socket_path(pc)
            display.vvvv('socket_path: %s' % socket_path, pc.remote_addr)

            if not os.path.exists(socket_path):
                # start the connection if it isn't started
                rc, out, err = connection.exec_command('open_shell()')
                display.vvvv('open_shell() returned %s %s %s' % (rc, out, err))
                if rc != 0:
                    return {'failed': True,
                            'msg': 'unable to open shell. Please see: ' +
                            'https://docs.ansible.com/ansible/network_debug_troubleshooting.html#unable-to-open-shell',
                            'rc': rc}
            else:
                # make sure we are in the right cli context which should be
                # enable mode and not config module
                rc, out, err = connection.exec_command('prompt()')
                while str(out).strip().endswith(']'):
                    display.vvvv('wrong context, sending exit to device', self._play_context.remote_addr)
                    connection.exec_command('return')
                    rc, out, err = connection.exec_command('prompt()')

            task_vars['ansible_socket'] = socket_path

        # make sure a transport value is set in args
        self._task.args['transport'] = transport
        self._task.args['provider'] = provider

        result = super(ActionModule, self).run(tmp, task_vars)
        return result