Set of scripts to build Android for LG G6 (h870) leveraging OVH Public Cloud

__main__.py 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import uuid
  2. import sys
  3. import time
  4. import ovh
  5. from . import config
  6. if __name__ == '__main__':
  7. client = ovh.Client(
  8. endpoint=config.ovh_endpoint,
  9. application_key=config.ovh_application_key,
  10. application_secret=config.ovh_application_secret,
  11. consumer_key=config.ovh_consumer_key,
  12. )
  13. if len(sys.argv) < 2:
  14. sys.exit(1)
  15. # Create VM
  16. if sys.argv[1] == 'init':
  17. # Get image id
  18. result = client.get(
  19. '/cloud/project/' + config.ovh_public_cloud_project + '/image',
  20. flavorType=config.ovh_public_cloud_flavor,
  21. osType='linux',
  22. region=config.ovh_public_cloud_region,
  23. )
  24. image_id = next(
  25. x['id']
  26. for x in result
  27. if x['name'] == config.ovh_public_cloud_image
  28. )
  29. # Get SSH key id
  30. result = client.get(
  31. '/cloud/project/' + config.ovh_public_cloud_project + '/sshkey',
  32. region=config.ovh_public_cloud_region,
  33. )
  34. ssh_key_id = next(
  35. x['id']
  36. for x in result
  37. if x['name'] == config.ovh_public_cloud_sshkey_name
  38. )
  39. # Get flavor id
  40. result = client.get(
  41. '/cloud/project/' + config.ovh_public_cloud_project + '/flavor',
  42. region=config.ovh_public_cloud_region,
  43. )
  44. flavor_id = next(
  45. x['id']
  46. for x in result
  47. if x['name'] == config.ovh_public_cloud_flavor
  48. )
  49. # Create instance
  50. name = str(uuid.uuid4())
  51. result = client.post(
  52. '/cloud/project/' + config.ovh_public_cloud_project + '/instance',
  53. flavorId=flavor_id,
  54. imageId=image_id,
  55. monthlyBilling=False,
  56. name=name,
  57. region=config.ovh_public_cloud_region,
  58. sshKeyId=ssh_key_id
  59. )
  60. if 'id' not in result:
  61. sys.exit(1)
  62. # Wait for IP address
  63. while True:
  64. result = client.get(
  65. '/cloud/project/' + config.ovh_public_cloud_project + '/instance',
  66. region=config.ovh_public_cloud_region,
  67. )
  68. ipAddresses = next(
  69. x['ipAddresses']
  70. for x in result
  71. if x['name'] == name
  72. )
  73. if ipAddresses:
  74. print(ipAddresses[0]['ip'])
  75. sys.exit(0)
  76. time.sleep(30)
  77. # Clear VM
  78. elif sys.argv[1] == 'purge':
  79. if len(sys.argv) < 3:
  80. sys.exit(1)
  81. # Get instance id from its IP address
  82. result = client.get(
  83. '/cloud/project/' + config.ovh_public_cloud_project + '/instance',
  84. region=config.ovh_public_cloud_region,
  85. )
  86. print(result)
  87. instance_id = next(
  88. x['id']
  89. for x in result
  90. if sys.argv[2] in [x['ip'] for x in x['ipAddresses']]
  91. )
  92. # Delete instance
  93. client.delete(
  94. '/cloud/project/' + config.ovh_public_cloud_project +
  95. '/instance/' + instance_id
  96. )
  97. else:
  98. sys.exit(1)