Ejemplo n.º 1
0
def clean():
    LOGGER.info('clean...')
    try:
        iptables.flush_fq_chain()
        try:
            LOGGER.info('iptables -L -v -n')
            LOGGER.info(shell.check_output(shlex.split('iptables -L -v -n')))
        except subprocess.CalledProcessError, e:
            LOGGER.error('failed to dump filter table: %s' % (sys.exc_info()[1]))
            LOGGER.error(e.output)
        try:
            LOGGER.info('iptables -t nat -L -v -n')
            LOGGER.info(shell.check_output(shlex.split('iptables -t nat -L -v -n')))
        except subprocess.CalledProcessError, e:
            LOGGER.error('failed to dump nat table: %s' % (sys.exc_info()[1]))
            LOGGER.error(e.output)
Ejemplo n.º 2
0
def clean():
    LOGGER.info('clean...')
    try:
        iptables.flush_fq_chain()
        try:
            LOGGER.info('iptables -L -v -n')
            LOGGER.info(shell.check_output(shlex.split('iptables -L -v -n')))
        except subprocess.CalledProcessError, e:
            LOGGER.error('failed to dump filter table: %s' % (sys.exc_info()[1]))
            LOGGER.error(e.output)
        try:
            LOGGER.info('iptables -t nat -L -v -n')
            LOGGER.info(shell.check_output(shlex.split('iptables -t nat -L -v -n')))
        except subprocess.CalledProcessError, e:
            LOGGER.error('failed to dump nat table: %s' % (sys.exc_info()[1]))
            LOGGER.error(e.output)
Ejemplo n.º 3
0
def shell_execute(command):
    LOGGER.info('execute: %s' % command)
    try:
        output = shell.check_output(shlex.split(command) if isinstance(command, basestring) else command)
        LOGGER.info('succeed, output: %s' % output)
    except subprocess.CalledProcessError, e:
        LOGGER.error('failed, output: %s' % e.output)
        raise
Ejemplo n.º 4
0
def shell_execute(command):
    LOGGER.info('execute: %s' % command)
    output = ''
    try:
        output = shell.check_output(shlex.split(command) if isinstance(command, basestring) else command)
        LOGGER.info('succeed, output: %s' % output)
    except subprocess.CalledProcessError, e:
        LOGGER.error('failed, output: %s' % e.output)
Ejemplo n.º 5
0
def dump_table(table):
    if tables and tables.has_key(table):
        return tables[table]
    command = 'iptables -t %s -L -v -n' % table
    LOGGER.debug('command: %s' % command)
    output = shell.check_output(shlex.split(command))
    LOGGER.debug('output: %s' % output)
    res = parse(output)
    tables[table] = res
    return res
Ejemplo n.º 6
0
def get_default_dns_server():
    try:
        default_dns_server = shell.check_output(['getprop', 'net.dns1']).strip()
        if default_dns_server:
            return default_dns_server
        else:
            return ''
    except:
        LOGGER.exception('failed to get default dns server')
        return ''
Ejemplo n.º 7
0
    def _on_status_action(self, event):
        """
        Add a juju status action.

        """
        logger.debug('Running juju status.')

        user = self._stored.cloud_user
        out = check_output('juju status', user=user)
        event.set_results({"juju_status": out})
Ejemplo n.º 8
0
def get_default_dns_server():
    try:
        default_dns_server = shell.check_output(['getprop',
                                                 'net.dns1']).strip()
        if default_dns_server:
            return default_dns_server
        else:
            return ''
    except:
        LOGGER.exception('failed to get default dns server')
        return ''
Ejemplo n.º 9
0
    def _ensure_juju(self):
        """
        Ensure that juju is installed.

        TODO: make this more robust and able to recover from a
        mid-process crash.

        """
        user = self._stored.cloud_user

        if 'juju' in check_output('snap list'):
            return

        # Bootstrap and add a model.
        self.unit.status = MaintenanceStatus('Bootstrapping Juju.')
        check('snap install juju --classic')
        check('juju bootstrap microk8s micro', user=user)
        check('juju add-model testing', user=user)
Ejemplo n.º 10
0
def pull(src, dst, name, filter=None, yes=False):
    _ip = list(ip(name))[0]
    logging.info('targeting:\n %s', _ip)
    script = _tar_script(src, filter, echo_only=True)
    cmd = ('cat %(script)s |ssh' + ssh_args +
           'ubuntu@%(_ip)s bash -s') % locals()
    logging.info('going to pull:')
    logging.info(util.strings.indent(shell.check_output(cmd), 1))
    shell.check_call('rm -rf', os.path.dirname(script))
    if is_cli and not yes:
        logging.info('\nwould you like to proceed? y/n\n')
        assert pager.getch() == 'y', 'abort'
    script = _tar_script(src, filter)
    cmd = ('cd %(dst)s && cat %(script)s | ssh' + ssh_args +
           'ubuntu@%(_ip)s bash -s | tar xf -') % locals()
    try:
        shell.check_call(cmd)
    except:
        logging.info('failure for: %s', _ip)
        sys.exit(1)
    finally:
        shell.check_call('rm -rf', os.path.dirname(script))
Ejemplo n.º 11
0
    def _ensure_microk8s(self):
        """
        Ensure that microk8s is installed.

        TODO: make this more robust and able to recover from a
        mid-process crash.

        """
        user = self._stored.cloud_user

        if 'microk8s' in check_output('snap list'):
            return

        # Install and check microk8s
        self.unit.status = MaintenanceStatus('Installing microk8s.')
        check('snap install microk8s --classic')
        check('usermod -a -G microk8s {}'.format(user))
        check('microk8s status --wait-ready', user=user)
        check('microk8s.kubectl get all --all-namespaces', user=user)

        # Enable components
        self.unit.status = MaintenanceStatus('Enabling microk8s components.')
        check('microk8s.enable dns storage', user=self.config['cloud_user'])
Ejemplo n.º 12
0
def dump_table(table):
    command = 'iptables -t %s -L -v -n' % table
    LOGGER.debug('command: %s' % command)
    output = shell.check_output(shlex.split(command))
    LOGGER.debug('output: %s' % output)
    return parse(output)
Ejemplo n.º 13
0
def dump_table(table):
    command = "iptables -t %s -L -v -n" % table
    LOGGER.debug("command: %s" % command)
    output = shell.check_output(shlex.split(command))
    LOGGER.debug("output: %s" % output)
    return parse(output)
Ejemplo n.º 14
0
def dump_table(table):
    command = 'iptables -t %s -L -v -n' % table
    LOGGER.debug('command: %s' % command)
    output = shell.check_output(shlex.split(command))
    LOGGER.debug('output: %s' % output)
    return parse(output)