-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdestroy_instance.py
executable file
·64 lines (49 loc) · 1.92 KB
/
destroy_instance.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
from __future__ import unicode_literals, print_function
from os import path
import sys
import time
from runabove import Runabove
from runabove.exception import APIError
from ConfigParser import SafeConfigParser
parser = SafeConfigParser()
parser.read('settings.conf')
#env.key_filename = parser.get('ra','ssh_key_filename')
application_key = parser.get('ra', 'application_key')
application_secret = parser.get('ra','application_secret')
# Get information about the account
while True:
try :
consumer_key = parser.get('ra','consumer_key')
# Create the Runabove SDK interface
ra = Runabove(application_key,
application_secret,
consumer_key=consumer_key)
acc = ra.account.get()
print('\nHi %s,' % acc.first_name)
break
except:
print('\nLogin failed.')
choice = raw_input('\nWould you like to get a new consumer key? (n/Y): ')
if choice.lower() == 'n':
print('Not requesting a Consumer Key, aborting')
sys.exit(0)
else:
print('\nYou need to login on this site %s' % ra.get_login_url())
raw_input('\nWhen you are logged, press Enter ')
#print('Your consumer key is: %s' % ra.get_consumer_key())
parser.set('ra', 'consumer_key', ra.get_consumer_key())
# Writing our configuration file
with open('settings.conf', 'wb') as configfile:
parser.write(configfile)
# Get the list of raning instances
choice = 'n'
instances = ra.instances.list()
print('\nYou have %d instance(s) runing' % len(instances))
choice = raw_input('\nWould you like to delete all your instances? (y/N): ')
if choice.lower() == 'y':
for i in instances:
print('\t- [%s] %s (%s, %s)' % (i.region.name, i.name, i.ip, i.image.name))
instance = ra.instances.get_by_id(i.id)
instance.delete()
print('Instance deleted')