@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