Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import cli
- class NodeName(cli.Argument):
- def __init__(self, add):
- super(Name, self).__init__(type=str)
- self._add = add
- def validate(self, data):
- available = data in node_list
- return self._add == available
- def node_list():
- print "node list"
- def node_attach(dry_run=False, name=None, connect_string=None, kind='system', force=False):
- print "node_attach(name=%s, connect_string=%s, kind=%s)" % (name,
- connect_string,
- kind)
- def node_detach(dry_run=False, name=None):
- print "node_detach(name=%s)" % name
- node = cli.root.add_command('node')
- node.add_option('-d' , '--dry-run', name="dry_run")
- node_list = node.add_command('list', action=node_list, inherit_parent=False)
- node_attach = node.add_command('attach', action=node_attach)
- node_attach.add_option(name='name', type=NodeName(False))
- node_attach.add_option(name='connect_string', type=str,
- validator=cli.validator.regex('([a-zA-Z0-9]+@)?[a-zA-Z0-9.]+(:[a-zA-Z0-9]+)?'))
- node_attach.add_option('-k', '--kind', name='kind',
- type=choice('system', 'user'),
- required=True)
- node_attach.add_option('-f', '--force', help='replace if exists')
- node_detach = node.add_command('detach', action=node_detach)
- node_detach.add_option(name='name', type=NodeName(True))
- if __name__ == '__main__':
- dispatch()
Advertisement
Add Comment
Please, Sign In to add comment