Python __main__.display.vvv() Examples
The following are 30
code examples of __main__.display.vvv().
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: lchroot.py From luna with GNU General Public License v3.0 | 6 votes |
def fetch_file(self, in_path, out_path): ''' fetch a file from chroot to local ''' super(Connection, self).fetch_file(in_path, out_path) display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self.path) in_path = pipes.quote(self._prefix_login_path(in_path)) try: p = self._buffered_exec_command('dd if=%s bs=%s' % (in_path, BUFSIZE)) except OSError: raise AnsibleError("chroot connection requires dd command in the chroot") with open(to_bytes(out_path, errors='surrogate_or_strict'), 'wb+') as out_file: try: chunk = p.stdout.read(BUFSIZE) while chunk: out_file.write(chunk) chunk = p.stdout.read(BUFSIZE) except: traceback.print_exc() raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path)) stdout, stderr = p.communicate() if p.returncode != 0: raise AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr))
Example #2
Source File: dcos_iam_user.py From ansible-dcos with Apache License 2.0 | 6 votes |
def user_update(uid, groups): """Update user groups""" display.vvv("DC/OS: IAM update user {}".format(uid)) for g in groups: display.vvv("Assigning user {} to group {}".format( uid,g)) cmd = [ 'dcos', 'security', 'org', 'groups', 'add_user', g, uid ] run_command(cmd, 'update user', stop_on_error=False)
Example #3
Source File: dcos_marathon.py From ansible-dcos with Apache License 2.0 | 6 votes |
def app_create(app_id, options): """Deploy an app via Marathon""" display.vvv("DC/OS: Marathon create app {}".format(app_id)) # create a temporary file for the options json file with tempfile.NamedTemporaryFile('w+') as f: json.dump(options, f) # force write the file to disk to make sure subcommand can read it f.flush() os.fsync(f) display.vvv(subprocess.check_output( ['cat', f.name]).decode()) cmd = [ 'dcos', 'marathon', 'app', 'add', f.name ] run_command(cmd, 'add app', stop_on_error=True)
Example #4
Source File: dcos_marathon.py From ansible-dcos with Apache License 2.0 | 6 votes |
def get_app_state(app_id): """Get the current state of an app.""" r = subprocess.check_output(['dcos', 'marathon', 'app', 'list', '--json' ], env=_dcos_path()) apps = json.loads(r) display.vvv('looking for app_id {}'.format(app_id)) state = 'absent' for a in apps: try: if app_id in a['id']: state = 'present' display.vvv('found app: {}'.format(app_id)) except KeyError: continue return state
Example #5
Source File: common.py From ansible-dcos with Apache License 2.0 | 6 votes |
def run_command(cmd, description='run command', stop_on_error=False, input=None): """Run a command and catch exceptions for Ansible.""" display.vvv("command: " + ' '.join(cmd)) from subprocess import CalledProcessError, check_output try: output = check_output(cmd, env=_dcos_path(),stderr=subprocess.STDOUT) #output = check_output(cmd, env=_dcos_path()) returncode = 0 except CalledProcessError as e: output = e.output returncode = e.returncode if stop_on_error and returncode != 0: raise AnsibleActionFail('Failed to {}: {}'.format(description, e)) return output
Example #6
Source File: common.py From ansible-dcos with Apache License 2.0 | 6 votes |
def ensure_dcos_security(): """Check whether the dcos[cli] security extension is installed.""" raw_version = '' try: r = subprocess.check_output(['dcos', 'security', '--version'], env=_dcos_path()).decode() except: display.vvv("dcos security: not installed") install_dcos_security_cli() r = subprocess.check_output(['dcos', 'security', '--version'], env=_dcos_path()).decode() v = _version(r) if v < (1, 2, 0): raise AnsibleActionFail( "DC/OS Security CLI 1.2.x is required, found {}".format(v)) display.vvv("dcos security: all prerequisites seem to be in order")
Example #7
Source File: common.py From ansible-dcos with Apache License 2.0 | 6 votes |
def ensure_dcos(): """Check whether the dcos cli is installed.""" try: r = subprocess.check_output(['dcos', '--version'], env=_dcos_path()).decode() except subprocess.CalledProcessError: raise AnsibleActionFail("DC/OS CLI is not installed!") raw_version = '' for line in r.strip().split('\n'): display.vvv(line) k, v = line.split('=') if k == 'dcoscli.version': raw_version = v v = _version(raw_version) if v < (0, 5, 0): raise AnsibleActionFail( "DC/OS CLI 0.5.x is required, found {}".format(v)) if v >= (0, 7, 0): raise AnsibleActionFail( "DC/OS CLI version > 0.7.x detected, may not work") display.vvv("dcos: all prerequisites seem to be in order")
Example #8
Source File: dcos_connection.py From ansible-dcos with Apache License 2.0 | 6 votes |
def connect_cluster(**kwargs): """Connect to a DC/OS cluster by url""" changed = False url = kwargs.get('url') if not check_cluster(kwargs.get('name'), url): if url is None: raise AnsibleActionFail( 'Not connected: you need to specify the cluster url') display.vvv('DC/OS cluster not setup, setting up') cli_args = parse_connect_options(**kwargs) display.vvv('args: {}'.format(cli_args)) subprocess.check_call(['dcos', 'cluster', 'setup', url] + cli_args, env=_dcos_path()) changed = True # ensure_auth(**kwargs) return changed
Example #9
Source File: lchroot.py From luna with GNU General Public License v3.0 | 6 votes |
def _buffered_exec_command(self, cmd, stdin=subprocess.PIPE): ''' run a command on the chroot. This is only needed for implementing put_file() get_file() so that we don't have to read the whole file into memory. compared to exec_command() it looses some niceties like being able to return the process's exit code immediately. ''' executable = C.DEFAULT_EXECUTABLE.split()[0] if C.DEFAULT_EXECUTABLE else '/bin/sh' local_cmd = [self.chroot_cmd, self.path, executable, '-c', cmd] display.vvv( "EXEC %s cmd is %s" % (local_cmd,cmd), host=self.path) local_cmd = [to_bytes(i, errors='surrogate_or_strict') for i in local_cmd] p = subprocess.Popen(local_cmd, shell=False, stdin=stdin, env={ 'PATH': '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin', 'FAKE_KERN': self.osimage.get('kernver'), 'LD_PRELOAD': 'libluna-fakeuname.so' }, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return p
Example #10
Source File: lchroot.py From luna with GNU General Public License v3.0 | 6 votes |
def put_file(self, in_path, out_path): ''' transfer a file from local to lchroot ''' super(Connection, self).put_file(in_path, out_path) display.vvv("PUT %s TO %s" % (in_path, out_path), host=self.path) out_path = pipes.quote(self._prefix_login_path(out_path)) try: with open(to_bytes(in_path, errors='surrogate_or_strict'), 'rb') as in_file: try: p = self._buffered_exec_command('dd of=%s bs=%s' % (out_path, BUFSIZE), stdin=in_file) except OSError: raise AnsibleError("lchroot connection requires dd command in the lchroot") try: stdout, stderr = p.communicate() except: traceback.print_exc() raise AnsibleError("failed to transfer file %s to %s" % (in_path, out_path)) if p.returncode != 0: raise AnsibleError("failed to transfer file %s to %s:\n%s\n%s" % (in_path, out_path, stdout, stderr)) except IOError: raise AnsibleError("file or module does not exist at: %s" % in_path)
Example #11
Source File: sshjail.py From ansible-sshjail with MIT License | 6 votes |
def match_jail(self): if self.jid is None: code, stdout, stderr = self._jailhost_command("jls -q jid name host.hostname path") if code != 0: display.vvv("JLS stdout: %s" % stdout) raise AnsibleError("jls returned non-zero!") lines = stdout.strip().split(b'\n') found = False for line in lines: if line.strip() == '': break jid, name, hostname, path = to_text(line).strip().split() if name == self.jailspec or hostname == self.jailspec: self.jid = jid self.jname = name self.jpath = path found = True break if not found: raise AnsibleError("failed to find a jail with name or hostname of '%s'" % self.jailspec)
Example #12
Source File: dcos_package.py From ansible-dcos with Apache License 2.0 | 6 votes |
def get_current_version(package, app_id): """Get the current version of an installed package.""" r = subprocess.check_output(['dcos', 'package', 'list', '--json', '--app-id='+app_id ], env=_dcos_path()) packages = json.loads(r) display.vvv('looking for package {} app_id {}'.format(package, app_id)) v = None for p in packages: try: if p['name'] == package and '/' + app_id in p['apps']: v = p['version'] except KeyError: continue display.vvv('{} current version: {}'.format(package, v)) return v
Example #13
Source File: sshjail.py From ansible-sshjail with MIT License | 6 votes |
def exec_command(self, cmd, in_data=None, executable='/bin/sh', sudoable=True): ''' run a command in the jail ''' slpcmd = False if '&& sleep 0' in cmd: slpcmd = True cmd = self._strip_sleep(cmd) if 'sudo' in cmd: cmd = self._strip_sudo(executable, cmd) cmd = ' '.join([executable, '-c', pipes.quote(cmd)]) if slpcmd: cmd = '%s %s %s %s' % (self.get_jail_connector(), self.get_jail_id(), cmd, '&& sleep 0') else: cmd = '%s %s %s' % (self.get_jail_connector(), self.get_jail_id(), cmd) if self._play_context.become: # display.debug("_low_level_execute_command(): using become for this command") cmd = self._play_context.make_become_cmd(cmd) # display.vvv("JAIL (%s) %s" % (local_cmd), host=self.host) return super(Connection, self).exec_command(cmd, in_data, True)
Example #14
Source File: dcos_edgelb.py From ansible-dcos with Apache License 2.0 | 6 votes |
def pool_update(pool_id, instance_name, options): """Update an pool""" display.vvv("DC/OS: Edgelb update pool {}".format(pool_id)) # create a temporary file for the options json file with tempfile.NamedTemporaryFile('w+') as f: json.dump(options, f) # force write the file to disk to make sure subcommand can read it f.flush() os.fsync(f) display.vvv(subprocess.check_output( ['cat', f.name]).decode()) cmd = [ 'dcos', 'edgelb', 'update', '--name=' + instance_name, f.name ] run_command(cmd, 'update pool', stop_on_error=True)
Example #15
Source File: dcos_edgelb.py From ansible-dcos with Apache License 2.0 | 6 votes |
def pool_create(pool_id, instance_name, options): """Create a pool""" display.vvv("DC/OS: edgelb create pool {}".format(pool_id)) # create a temporary file for the options json file with tempfile.NamedTemporaryFile('w+') as f: json.dump(options, f) # force write the file to disk to make sure subcommand can read it f.flush() os.fsync(f) display.vvv(subprocess.check_output( ['cat', f.name]).decode()) cmd = [ 'dcos', 'edgelb', 'create', '--name=' + instance_name, f.name ] run_command(cmd, 'update pool', stop_on_error=True)
Example #16
Source File: dcos_edgelb.py From ansible-dcos with Apache License 2.0 | 6 votes |
def get_pool_state(pool_id, instance_name): """Get the current state of a pool.""" r = subprocess.check_output([ 'dcos', 'edgelb', 'list', '--name=' + instance_name, '--json' ], env=_dcos_path()) pools = json.loads(r) display.vvv('looking for pool_id {}'.format(pool_id)) state = 'absent' for p in pools: try: if pool_id in p['name']: state = 'present' display.vvv('found pool: {}'.format(pool_id)) except KeyError: continue return state
Example #17
Source File: dcos_secret.py From ansible-dcos with Apache License 2.0 | 6 votes |
def secret_create(path, value, store): """Create a secret""" display.vvv("DC/OS: create secret {} with {}".format(path, value)) cmd = [ 'dcos', 'security', 'secrets', 'create', '--store-id', store, '--value', value, path ] run_command(cmd, 'create secret', stop_on_error=True)
Example #18
Source File: dcos_secret.py From ansible-dcos with Apache License 2.0 | 6 votes |
def secret_update(path, value, store): """Update a secret""" display.vvv("DC/OS: update secret {} with {}".format(path, value)) cmd = [ 'dcos', 'security', 'secrets', 'update', '--store-id', store, '--value', value, path ] run_command(cmd, 'update secret', stop_on_error=True)
Example #19
Source File: dcos_iam_group.py From ansible-dcos with Apache License 2.0 | 6 votes |
def group_update(gid, permissions): """Update group permissions""" display.vvv("DC/OS: IAM update group {}".format(gid)) for p in permissions: display.vvv("Granting {} permission on {} to group {}".format( p['rid'], p['action'], gid)) cmd = [ 'dcos', 'security', 'org', 'groups', 'grant', gid, p['rid'], p['action'] ] run_command(cmd, 'update group', stop_on_error=False)
Example #20
Source File: dcos_iam_serviceaccount.py From ansible-dcos with Apache License 2.0 | 6 votes |
def service_account_update(sid, groups): """Update service_account groups""" display.vvv("DC/OS: IAM update service_account {}".format(sid)) for g in groups: display.vvv("Assigning service_account {} to group {}".format( sid,g)) cmd = [ 'dcos', 'security', 'org', 'groups', 'add_user', g, sid ] run_command(cmd, 'update service_account', stop_on_error=False)
Example #21
Source File: lchroot.py From luna with GNU General Public License v3.0 | 5 votes |
def _connect(self): ''' connect to the chroot; nothing to do here ''' super(Connection, self)._connect() if not self._connected: display.vvv("THIS IS A LOCAL CHROOT DIR", host=self.path) self._connected = True
Example #22
Source File: dcos_iam_group.py From ansible-dcos with Apache License 2.0 | 5 votes |
def group_delete(gid): """Delete a group""" display.vvv("DC/OS: IAM delete group {}".format(gid)) cmd = [ 'dcos', 'security', 'org', 'groups', 'delete', gid, ] run_command(cmd, 'delete group', stop_on_error=True)
Example #23
Source File: dcos_iam_user.py From ansible-dcos with Apache License 2.0 | 5 votes |
def get_user_state(uid): """Get the current state of a user.""" r = subprocess.check_output([ 'dcos', 'security', 'org', 'users', 'show', '--json' ], env=_dcos_path() ) users = json.loads(r) display.vvv('looking for uid {}'.format(uid)) state = 'absent' for g in users: try: if uid in g: state = 'present' display.vvv('found uid: {}'.format(uid)) except KeyError: continue return state
Example #24
Source File: dcos_iam_group.py From ansible-dcos with Apache License 2.0 | 5 votes |
def group_create(gid, description): """Create a group""" display.vvv("DC/OS: IAM create group {}".format(gid)) cmd = [ 'dcos', 'security', 'org', 'groups', 'create', '--description', '\'' + description + '\'', gid, ] run_command(cmd, 'create group', stop_on_error=True)
Example #25
Source File: dcos_iam_user.py From ansible-dcos with Apache License 2.0 | 5 votes |
def user_delete(uid): """Delete a user""" display.vvv("DC/OS: IAM delete user {}".format(uid)) cmd = [ 'dcos', 'security', 'org', 'users', 'delete', uid, ] run_command(cmd, 'delete user', stop_on_error=True)
Example #26
Source File: dcos_marathon.py From ansible-dcos with Apache License 2.0 | 5 votes |
def app_remove(app_id): """Remove an app via Marathon""" display.vvv("DC/OS: Marathon remove app {}".format(app_id)) cmd = [ 'dcos', 'marathon', 'app', 'remove', '/' + app_id, ] run_command(cmd, 'remove app', stop_on_error=True)
Example #27
Source File: sshjail.py From ansible-sshjail with MIT License | 5 votes |
def _copy_file(self, from_file, to_file): copycmd = self._play_context.make_become_cmd(' '.join(['cp', from_file, to_file])) display.vvv(u"REMOTE COPY {0} TO {1}".format(from_file, to_file), host=self.inventory_hostname) code, stdout, stderr = self._jailhost_command(copycmd) if code != 0: raise AnsibleError("failed to copy file from %s to %s:\n%s\n%s" % (from_file, to_file, stdout, stderr))
Example #28
Source File: logging.py From mitogen with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setup(): """ Install handlers for Mitogen loggers to redirect them into the Ansible display framework. Ansible installs its own logging framework handlers when C.DEFAULT_LOG_PATH is set, therefore disable propagation for our handlers. """ l_mitogen = logging.getLogger('mitogen') l_mitogen_io = logging.getLogger('mitogen.io') l_ansible_mitogen = logging.getLogger('ansible_mitogen') l_operon = logging.getLogger('operon') for logger in l_mitogen, l_mitogen_io, l_ansible_mitogen, l_operon: logger.handlers = [Handler(display.vvv)] logger.propagate = False if display.verbosity > 2: l_ansible_mitogen.setLevel(logging.DEBUG) l_mitogen.setLevel(logging.DEBUG) else: # Mitogen copies the active log level into new children, allowing them # to filter tiny messages before they hit the network, and therefore # before they wake the IO loop. Explicitly setting INFO saves ~4% # running against just the local machine. l_mitogen.setLevel(logging.ERROR) l_ansible_mitogen.setLevel(logging.ERROR) if display.verbosity > 3: l_mitogen_io.setLevel(logging.DEBUG)
Example #29
Source File: strace.py From ansible-tools with Apache License 2.0 | 5 votes |
def exec_command(self, cmd, in_data=None, sudoable=True): ''' run a command on the remote host ''' super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable) display.vvv(u"ESTABLISH SSH CONNECTION FOR USER: {0}".format(self._play_context.remote_user), host=self._play_context.remote_addr) ssh_executable = self._play_context.ssh_executable use_tty = self.get_option('use_tty') if not in_data and sudoable and use_tty: args = (ssh_executable, '-tt', self.host, cmd) else: args = (ssh_executable, self.host, cmd) cmd = self._build_command(*args) # find the index for the python interpreter pyx = None for idx,_cmd in enumerate(cmd): if 'python' in _cmd: pyx = idx if pyx: cmd[pyx] = cmd[pyx].replace( '/usr/bin/python', '/usr/bin/strace -s 100000 -ffttvo /tmp/strace.out/pid /usr/bin/python' ) (returncode, stdout, stderr) = self._run(cmd, in_data, sudoable=sudoable) return (returncode, stdout, stderr)
Example #30
Source File: ssh_citrix_adc.py From citrix-adc-ansible-modules with GNU General Public License v3.0 | 5 votes |
def exec_command(self, cmd, in_data=None, sudoable=True): ''' run a command on the remote host ''' # Adding the 'shell' command for the citrix adc cli if cmd.startswith('ssh_citrix_adc'): cmd = cmd.replace('ssh_citrix_adc', '') else: cmd = type(cmd)("shell ") + cmd # we can only use tty when we are not pipelining the modules. piping # data into /usr/bin/python inside a tty automatically invokes the # python interactive-mode but the modules are not compatible with the # interactive-mode ("unexpected indent" mainly because of empty lines) ssh_executable = self._play_context.ssh_executable msg = u"ESTABLISH SSH CONNECTION WITH ssh_citrix_adc FOR USER: {0}, cmd: {1}".format(self._play_context.remote_user, cmd) display.vvv(msg, host=self._play_context.remote_addr) # -tt can cause various issues in some environments so allow the user # to disable it as a troubleshooting method. use_tty = self.get_option('use_tty') if not in_data and sudoable and use_tty: args = (ssh_executable, '-tt', self.host, cmd) else: args = (ssh_executable, self.host, cmd) cmd = self._build_command(*args) (returncode, stdout, stderr) = self._run(cmd, in_data, sudoable=sudoable) ################################## # Removing the stdout 'Done' from citrix adc cli # that can cause errors in calling scp with Done/ as # first folder. stdout = stdout.replace(" Done\n", '') ################################# return (returncode, stdout, stderr)