Ubuntu Pastebin

Paste from Marco Ceppi at Tue, 26 Jan 2016 16:05:29 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
@hook('config-changed')
def validate_config():
    try:
        if ('pass', 'vpe-router', 'user') not in cfg:
            raise Exception('vpe-router, user, and pass need to be set')

        out, err = router.ssh(['whoami'], cfg.get('vpe-router'),
                              cfg.get('user'), cfg.get('pass'))
        if out.strip() != cfg.get('user'):
            raise Exception('invalid credentials')
    except Exception as e:
        remove_state('vpe.configured')
        set_state('blocked', 'validation failed: %s' % e)
    else:
        set_state('vpe.configured')


@when_not('vpe.configured')
def not_ready_add():
    actions = [
        'vpe.add-corporation',
        'vpe.connect-domains',
        'vpe.delete-domain-connections',
        'vpe.remove-corporation',
    ]

    if helpers.any_states(*actions):
        action_fail('VPE is not configured')

    status_set('blocked', 'VPE is not configured')


@when('vpe.configured')
@when('vpe.add-corporation')
def add_corporation():
    pass
Download as text