Skip to content

Instantly share code, notes, and snippets.

@marcoceppi
Created June 29, 2016 08:35
Show Gist options
  • Save marcoceppi/688ba2536451326c0a1625390989aabe to your computer and use it in GitHub Desktop.
Save marcoceppi/688ba2536451326c0a1625390989aabe to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
sys.path.append('lib')
from charms.reactive import main
from charms.reactive import set_state
from charmhelpers.core.hookenv import action_fail
"""
`set_state` only works here because it's flushed to disk inside the `main()`
loop. remove_state will need to be called inside the action method.
"""
set_state('vpe.add-corporation')
try:
main()
except Exception as e:
action_fail(repr(e))
@when('vpe.add-corporation')
def add_corporation():
'''
Create and Activate the network corporation
'''
domain_name = action_get('domain-name')
iface_name = action_get('iface-name')
# HACK: python's list, used deeper, throws an exception on ints in a tuple
vlan_id = str(action_get('vlan-id'))
cidr = action_get('cidr')
area = action_get('area')
subnet_cidr = action_get('subnet-cidr')
subnet_area = action_get('subnet-area')
iface_vlanid = '%s.%s' % (iface_name, vlan_id)
status_set('maintenance', 'adding corporation {}'.format(domain_name))
try:
# stuff
except subprocess.CalledProcessError as e:
delete_corporation()
action_fail('Command failed: %s (%s)' %
(' '.join(e.cmd), str(e.output)))
finally:
remove_state('vpe.add-corporation')
status_set('active', 'ready!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment