zamotivator

Untitled

Aug 5th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import cli
  4.  
  5. class NodeName(cli.Argument):
  6. def __init__(self, add):
  7. super(Name, self).__init__(type=str)
  8. self._add = add
  9.  
  10. def validate(self, data):
  11. available = data in node_list
  12. return self._add == available
  13.  
  14. def node_list():
  15. print "node list"
  16.  
  17. def node_attach(dry_run=False, name=None, connect_string=None, kind='system', force=False):
  18. print "node_attach(name=%s, connect_string=%s, kind=%s)" % (name,
  19. connect_string,
  20. kind)
  21. def node_detach(dry_run=False, name=None):
  22. print "node_detach(name=%s)" % name
  23.  
  24.  
  25. node = cli.root.add_command('node')
  26. node.add_option('-d' , '--dry-run', name="dry_run")
  27.  
  28. node_list = node.add_command('list', action=node_list, inherit_parent=False)
  29.  
  30. node_attach = node.add_command('attach', action=node_attach)
  31. node_attach.add_option(name='name', type=NodeName(False))
  32. node_attach.add_option(name='connect_string', type=str,
  33. validator=cli.validator.regex('([a-zA-Z0-9]+@)?[a-zA-Z0-9.]+(:[a-zA-Z0-9]+)?'))
  34. node_attach.add_option('-k', '--kind', name='kind',
  35. type=choice('system', 'user'),
  36. required=True)
  37. node_attach.add_option('-f', '--force', help='replace if exists')
  38.  
  39. node_detach = node.add_command('detach', action=node_detach)
  40. node_detach.add_option(name='name', type=NodeName(True))
  41.  
  42.  
  43. if __name__ == '__main__':
  44. dispatch()
Advertisement
Add Comment
Please, Sign In to add comment