ec2.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from mico.lib.aws import *
  2. USERDATA = """#cloud-config
  3. hostname: %s
  4. fqdn: %s
  5. manage_etc_hosts: true
  6. locale: C
  7. timezone: Europe/Madrid
  8. apt_update: true
  9. apt_upgrade: true
  10. """
  11. def main(*args):
  12. for arg in args:
  13. deploy(arg)
  14. @async
  15. def deploy(host):
  16. """Generic deploy system for a number of hosts.
  17. Example::
  18. deploy('host1', 'host2')
  19. """
  20. host, domain = host.split('.', 1) if '.' in host else (host, 'localdomain')
  21. sg_test = sg_ensure(
  22. name = "sec-test",
  23. description = "security group to test mico",
  24. rules = [
  25. sg_rule(
  26. protocol = "tcp",
  27. source = "0.0.0.0/0",
  28. port = "22"
  29. ),
  30. sg_rule(
  31. protocol = "tcp",
  32. source = "0.0.0.0/0",
  33. port = "80"
  34. )
  35. ]
  36. )
  37. instance = ec2_ensure(
  38. ami = "ami-3d4ff254",
  39. name = host,
  40. instance_type = "t1.micro",
  41. user_data = USERDATA % ( host, "%s.%s" % (host, domain,) ),
  42. key_name = "root-us-east-virginia",
  43. security_groups = [ sg_test ]
  44. )