Example #1
0
def main():
    settings_file_name = 'maas.yaml'
    with open(settings_file_name) as f:
        cfg = yaml.load(f)

    out = run('maas maas nodes list', quiet=True)
    print('.')
    nodes = json.loads(out)

    result = {}

    for node in nodes:
        hostname = node['hostname']
        if hostname.endswith('.maas'):
            hostname = hostname[0:-len('.maas')]

        pdu = json.loads(run('maas maas node power-parameters ' + node['system_id'], quiet=True))
        print('.')

        for i in node['interface_set']:
            result[i['mac_address']] = {
                'hostname': hostname,
                'pdu_index': int(pdu['power_address']),
            }
    cfg['nodes'] = result
    with open(settings_file_name, 'w') as f:
        yaml.dump(cfg, f, default_flow_style=False)
Example #2
0
def main():
    # for n in range(40, 45):
    #     sudo('ip addr add 192.168.1.{} dev eth1'.format(n))
    #
    # run('ip addr')

    sudo('lxd init')
    run('lxc launch ubuntu:14.04 my-ubuntu')
    sudo('ip route add 192.168.1.42 dev lxdbr0  scope link metric 1')
    sudo('sudo ip route add 192.168.1.0/24 dev eth1 metric 99')
    sudo('ip route del 192.168.1.42 dev lxdbr0  scope link')
Example #3
0
def download_and_run(r):
    for url, cmds in r.settings.get('download_and_run', {}).items():
        filename = os.path.basename(urlparse(url).path)
        filename = os.path.join('/tmp/boblify/', filename)
        try:
            os.makedirs('/tmp/boblify/')
        except OSError:
            pass

        shelly.download(url, filename)
        for cmd in cmds:
            shelly.run(cmd.format(filename=filename))
Example #4
0
def main(controller, series):
    clean(controller)
    bootstrap(controller, params={
        'bootstrap-series': series
    })

    juju('switch {}:controller'.format(controller))
    juju('enable-ha')

    return

    juju_bin = run('which juju', quiet=True).rstrip()
    run('cp {} /tmp'.format(juju_bin), quiet=True)
    run('cp {}d /tmp'.format(juju_bin), quiet=True)

    out = juju('add-user testuser', quiet=True)
    for line in out.splitlines():
        if re.search('juju register', line):
            cmd = line
            break

    sudo('/tmp/juju {}'.format(cmd), user='******')
    sudo('/tmp/juju ensure-availability', user='******')
Example #5
0
def juju(cmd, quiet=False, write_to=None, fail_ok=False, silent=False):
    if silent:
        quiet = True
    if not silent:
        print("juju cmd:", cmd)
    offline_cmds = [
        'destroy-environment',
        'switch',
        'bootstrap',
    ]
    offline = False
    for c in offline_cmds:
        if cmd.startswith(c):
            offline = True
            break
    if not (offline or fail_ok):
        wait_for_connection()

    return run("juju " + cmd, quiet, write_to, fail_ok)
Example #6
0
    def maas(self, cmd, quiet=False):
        cmd = 'maas {profile} ' + cmd

        rc = 1
        tries_remaining = 20
        out = ''
        while rc and tries_remaining:
            tries_remaining -= 1
            out, rc = shelly.run(cmd.format(**self.settings), timeout=5,
                                 fail_ok=True, quiet=quiet)
            if rc:
                print('command failed (rc={}), {} attempts remaining'.format(
                        rc, tries_remaining))
            time.sleep(5)

        try:
            return json.loads(out)
        except ValueError:
            return []
Example #7
0
def _bootstrapped(controller):
    if v2():
        out, rc = juju('list-controllers', fail_ok=True, quiet=True)
        if controller in out:
            return True
    else:
        out, rc = run('timeout 1 juju status -e {}'.format(controller), fail_ok=True, quiet=True)
        if rc == 0:
            return True

    if 'ERROR Unable to connect to environment' in out:
        if not 'cannot connect to API servers without admin-secret' in out:
            return "dead"

        return False

    if rc != 0:
        return "dead"

    return False
Example #8
0
def status():
    wait_for_connection()
    return yaml.load(run('juju status --format yaml', quiet=True))
Example #9
0
def bootstrapped():
    out, rc = run('timeout 1 juju status', fail_ok=True, quiet=True)
    return rc == 0
Example #10
0
                        watch(watching, name, unit['workload-status']['message'])
                    else:
                        watch(watching, name, '')

                    if unit_state not in ['started', 'idle']:
                        keep_trying = True
                        continue
        except KeyError as e:
            print(e)
            print("continuing...")


if __name__ == '__main__':
    start_at = 0
    if start_at <= 1:
        run('go install  -v github.com/juju/juju/...')
        juju('destroy-environment --force amzeu', fail_ok=True)
        juju('switch amzeu')
        juju('bootstrap --upload-tools')
        # juju('set-env logging-config=juju.state.presence=TRACE')
        juju(r'set-env logging-config=\<root\>=TRACE')
        wait()

    if start_at <= 2:
        # I don't know why, but deploying a charm before doing ensure-availability
        # seems to help us not get stuck in the waiting for has-vote state.
        juju('deploy ubuntu')
        wait()

    if start_at <= 3:
        juju('ensure-availability -n 3')
Example #11
0
 def run(self, cmd, fail_ok=False):
     return shelly.run(cmd.format(**self.settings), fail_ok=fail_ok)
Example #12
0
# -*- coding: utf-8 -*-
__author__ = 'nshahzad'

import shelly


shelly.run('multitail', ['/var/log/system.log'])