Revision a442c81d
b/snf-astakos-app/astakos/im/management/commands/user-modify.py | ||
---|---|---|
198 | 198 |
reject_reason=reject_reason) |
199 | 199 |
activation_backend.send_result_notifications(res, user) |
200 | 200 |
if res.is_error(): |
201 |
print "Failed to reject.", res.message
|
|
201 |
self.stderr.write("Failed to reject: %s" % res.message)
|
|
202 | 202 |
else: |
203 |
print "Account rejected"
|
|
203 |
self.stderr.write("Account rejected")
|
|
204 | 204 |
|
205 | 205 |
if options.get('verify'): |
206 | 206 |
res = activation_backend.handle_verification( |
... | ... | |
208 | 208 |
user.verification_code) |
209 | 209 |
#activation_backend.send_result_notifications(res, user) |
210 | 210 |
if res.is_error(): |
211 |
print "Failed to verify.", res.message
|
|
211 |
self.stderr.write("Failed to verify: %s" % res.message)
|
|
212 | 212 |
else: |
213 |
print "Account verified (%s)" % res.status_display() |
|
213 |
self.stderr.write("Account verified (%s)" |
|
214 |
% res.status_display()) |
|
214 | 215 |
|
215 | 216 |
if options.get('accept'): |
216 | 217 |
res = activation_backend.handle_moderation(user, accept=True) |
217 | 218 |
activation_backend.send_result_notifications(res, user) |
218 | 219 |
if res.is_error(): |
219 |
print "Failed to accept.", res.message
|
|
220 |
self.stderr.write("Failed to accept: %s" % res.message)
|
|
220 | 221 |
else: |
221 |
print "Account accepted and activated"
|
|
222 |
self.stderr.write("Account accepted and activated")
|
|
222 | 223 |
|
223 | 224 |
if options.get('active'): |
224 | 225 |
res = activation_backend.activate_user(user) |
225 | 226 |
if res.is_error(): |
226 |
print "Failed to activate.", res.message
|
|
227 |
self.stderr.write("Failed to activate: %s" % res.message)
|
|
227 | 228 |
else: |
228 |
print "Account %s activated" % user.username
|
|
229 |
self.stderr.write("Account %s activated" % user.username)
|
|
229 | 230 |
|
230 | 231 |
elif options.get('inactive'): |
231 | 232 |
res = activation_backend.deactivate_user( |
232 | 233 |
user, |
233 | 234 |
reason=options.get('inactive_reason', None)) |
234 | 235 |
if res.is_error(): |
235 |
print "Failed to deactivate,", res.message
|
|
236 |
self.stderr.write("Failed to deactivate: %s" % res.message)
|
|
236 | 237 |
else: |
237 |
print "Account %s deactivated" % user.username
|
|
238 |
self.stderr.write("Account %s deactivated" % user.username)
|
|
238 | 239 |
|
239 | 240 |
invitations = options.get('invitations') |
240 | 241 |
if invitations is not None: |
b/snf-cyclades-app/synnefo/logic/management/commands/backend-add.py | ||
---|---|---|
27 | 27 |
# those of the authors and should not be interpreted as representing official |
28 | 28 |
# policies, either expressed or implied, of GRNET S.A. |
29 | 29 |
# |
30 |
import sys |
|
31 | 30 |
from optparse import make_option |
32 | 31 |
from django.core.management.base import BaseCommand, CommandError |
33 | 32 |
|
... | ... | |
85 | 84 |
if options['check']: |
86 | 85 |
check_backend_credentials(clustername, port, username, password) |
87 | 86 |
|
88 |
create_backend(clustername, port, username, password, |
|
89 |
hypervisor=options["hypervisor"], |
|
90 |
initialize=options["init"]) |
|
91 |
|
|
92 |
|
|
93 |
def create_backend(clustername, port, username, password, hypervisor=None, |
|
94 |
initialize=True, stream=sys.stdout): |
|
95 |
kw = {"clustername": clustername, |
|
96 |
"port": port, |
|
97 |
"username": username, |
|
98 |
"password": password, |
|
99 |
"drained": True} |
|
100 |
|
|
101 |
if hypervisor: |
|
102 |
kw["hypervisor"] = hypervisor |
|
103 |
|
|
104 |
# Create the new backend in database |
|
105 |
try: |
|
106 |
backend = Backend.objects.create(**kw) |
|
107 |
except IntegrityError as e: |
|
108 |
raise CommandError("Cannot create backend: %s\n" % e) |
|
109 |
|
|
110 |
stream.write("Successfully created backend with id %d\n" % backend.id) |
|
111 |
|
|
112 |
if not initialize: |
|
113 |
return |
|
114 |
|
|
115 |
stream.write("Retrieving backend resources:\n") |
|
116 |
resources = backend_mod.get_physical_resources(backend) |
|
117 |
attr = ['mfree', 'mtotal', 'dfree', 'dtotal', 'pinst_cnt', 'ctotal'] |
|
118 |
|
|
119 |
table = [[str(resources[x]) for x in attr]] |
|
120 |
pprint_table(stream, table, attr) |
|
121 |
|
|
122 |
backend_mod.update_backend_resources(backend, resources) |
|
123 |
backend_mod.update_backend_disk_templates(backend) |
|
124 |
|
|
125 |
networks = Network.objects.filter(deleted=False, public=True) |
|
126 |
if not networks: |
|
127 |
return |
|
128 |
|
|
129 |
stream.write("Creating the following public:\n") |
|
130 |
headers = ("ID", "Name", 'IPv4 Subnet', "IPv6 Subnet", 'Mac Prefix') |
|
131 |
table = [] |
|
132 |
|
|
133 |
for net in networks: |
|
134 |
subnet4 = net.subnet4.cidr if net.subnet4 else None |
|
135 |
subnet6 = net.subnet6.cidr if net.subnet6 else None |
|
136 |
table.append((net.id, net.backend_id, subnet4, |
|
137 |
subnet6, str(net.mac_prefix))) |
|
138 |
pprint_table(stream, table, headers) |
|
139 |
|
|
140 |
for net in networks: |
|
141 |
net.create_backend_network(backend) |
|
142 |
result = backend_mod.create_network_synced(net, backend) |
|
143 |
if result[0] != "success": |
|
144 |
stream.write('\nError Creating Network %s: %s\n' % |
|
145 |
(net.backend_id, result[1])) |
|
146 |
else: |
|
147 |
stream.write('Successfully created Network: %s\n' % |
|
148 |
net.backend_id) |
|
149 |
result = backend_mod.connect_network_synced(network=net, |
|
150 |
backend=backend) |
|
151 |
if result[0] != "success": |
|
152 |
stream.write('\nError Connecting Network %s: %s\n' % |
|
153 |
(net.backend_id, result[1])) |
|
154 |
else: |
|
155 |
stream.write('Successfully connected Network: %s\n' % |
|
156 |
net.backend_id) |
|
87 |
self.create_backend(clustername, port, username, password, |
|
88 |
hypervisor=options["hypervisor"], |
|
89 |
initialize=options["init"]) |
|
90 |
|
|
91 |
def create_backend(self, clustername, port, username, password, |
|
92 |
hypervisor=None, initialize=True): |
|
93 |
kw = {"clustername": clustername, |
|
94 |
"port": port, |
|
95 |
"username": username, |
|
96 |
"password": password, |
|
97 |
"drained": True} |
|
98 |
|
|
99 |
if hypervisor: |
|
100 |
kw["hypervisor"] = hypervisor |
|
101 |
|
|
102 |
# Create the new backend in database |
|
103 |
try: |
|
104 |
backend = Backend.objects.create(**kw) |
|
105 |
except IntegrityError as e: |
|
106 |
raise CommandError("Cannot create backend: %s\n" % e) |
|
107 |
|
|
108 |
self.stderr.write("Successfully created backend with id %d\n" |
|
109 |
% backend.id) |
|
110 |
|
|
111 |
if not initialize: |
|
112 |
return |
|
113 |
|
|
114 |
self.stderr.write("Retrieving backend resources:\n") |
|
115 |
resources = backend_mod.get_physical_resources(backend) |
|
116 |
attr = ['mfree', 'mtotal', 'dfree', |
|
117 |
'dtotal', 'pinst_cnt', 'ctotal'] |
|
118 |
|
|
119 |
table = [[str(resources[x]) for x in attr]] |
|
120 |
pprint_table(self.stdout, table, attr) |
|
121 |
|
|
122 |
backend_mod.update_backend_resources(backend, resources) |
|
123 |
backend_mod.update_backend_disk_templates(backend) |
|
124 |
|
|
125 |
networks = Network.objects.filter(deleted=False, public=True) |
|
126 |
if not networks: |
|
127 |
return |
|
128 |
|
|
129 |
self.stderr.write("Creating the following public:\n") |
|
130 |
headers = ("ID", "Name", 'IPv4 Subnet', |
|
131 |
"IPv6 Subnet", 'Mac Prefix') |
|
132 |
table = [] |
|
133 |
|
|
134 |
for net in networks: |
|
135 |
subnet4 = net.subnet4.cidr if net.subnet4 else None |
|
136 |
subnet6 = net.subnet6.cidr if net.subnet6 else None |
|
137 |
table.append((net.id, net.backend_id, subnet4, |
|
138 |
subnet6, str(net.mac_prefix))) |
|
139 |
pprint_table(self.stdout, table, headers) |
|
140 |
|
|
141 |
for net in networks: |
|
142 |
net.create_backend_network(backend) |
|
143 |
result = backend_mod.create_network_synced(net, backend) |
|
144 |
if result[0] != "success": |
|
145 |
self.stderr.write('\nError Creating Network %s: %s\n' |
|
146 |
% (net.backend_id, result[1])) |
|
147 |
else: |
|
148 |
self.stderr.write('Successfully created Network: %s\n' |
|
149 |
% net.backend_id) |
|
150 |
result = backend_mod.connect_network_synced(network=net, |
|
151 |
backend=backend) |
|
152 |
if result[0] != "success": |
|
153 |
self.stderr.write('\nError Connecting Network %s: %s\n' |
|
154 |
% (net.backend_id, result[1])) |
|
155 |
else: |
|
156 |
self.stderr.write('Successfully connected Network: %s\n' |
|
157 |
% net.backend_id) |
b/snf-cyclades-app/synnefo/logic/management/commands/cyclades-astakos-migrate-013.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
import itertools |
35 |
import warnings |
|
36 | 35 |
import functools |
37 | 36 |
|
38 | 37 |
from optparse import make_option |
39 | 38 |
|
40 |
from django.core.management.base import NoArgsCommand, CommandError, BaseCommand
|
|
39 |
from django.core.management.base import CommandError, BaseCommand |
|
41 | 40 |
from django.db import transaction |
42 | 41 |
from django.conf import settings |
43 | 42 |
|
... | ... | |
48 | 47 |
|
49 | 48 |
from snf_django.lib import astakos |
50 | 49 |
|
51 |
def warn(*msgs): |
|
52 |
print "WARNING: %s" % ' '.join(msgs) |
|
53 | 50 |
|
54 |
get_displayname = functools.partial(astakos.get_displayname, |
|
55 |
settings.CYCLADES_SERVICE_TOKEN, |
|
56 |
url=settings.ASTAKOS_URL.replace('im/authenticate', |
|
57 |
'service/api/user_catalogs')) |
|
58 |
get_user_uuid = functools.partial(astakos.get_user_uuid, |
|
59 |
settings.CYCLADES_SERVICE_TOKEN, |
|
60 |
url=settings.ASTAKOS_URL.replace('im/authenticate', |
|
61 |
'service/api/user_catalogs')) |
|
62 |
|
|
63 |
def _validate_db_state(usernames): |
|
64 |
|
|
65 |
usernames = filter(bool, usernames) |
|
66 |
invalid_case_users = case_unique(usernames) |
|
67 |
if invalid_case_users: |
|
68 |
invalid_case_users.append(invalid_case_users[0].lower()) |
|
69 |
raise CommandError("Duplicate case insensitive user identifiers exist %r" % invalid_case_users) |
|
70 |
|
|
71 |
uuidusers = filter(lambda uid:'@' in uid or uid == None, usernames) |
|
72 |
if len(uuidusers) != len(usernames): |
|
73 |
warn('It seems that mixed uuid/email user identifiers exist in database.') |
|
74 |
return False |
|
75 |
|
|
76 |
return True |
|
77 |
|
|
78 |
|
|
79 |
@transaction.commit_manually |
|
80 |
def delete_user(username, only_stats=True, dry=True): |
|
81 |
vms = VirtualMachine.objects.filter(userid__exact=username) |
|
82 |
networks = Network.objects.filter(userid__exact=username) |
|
83 |
keys = PublicKeyPair.objects.filter(user__exact=username) |
|
84 |
|
|
85 |
if not len(list(itertools.ifilter(bool, map(lambda q: q.count(), [vms, |
|
86 |
networks, |
|
87 |
keys])))): |
|
88 |
print "No entries exist for '%s'" % username |
|
89 |
return -1 |
|
90 |
|
|
91 |
if only_stats: |
|
92 |
print "The following entries will be deleted if you decide to remove this user" |
|
93 |
print "%d Virtual Machines" % vms.exclude(operstate='DESTROYED').count() |
|
94 |
print "%d Destroyed Virtual Machines" % vms.filter(operstate='DESTROYED').count() |
|
95 |
print "%d Networks" % networks.count() |
|
96 |
print "%d PublicKeyPairs" % keys.count() |
|
97 |
return |
|
98 |
|
|
99 |
for o in itertools.chain(vms, networks): |
|
100 |
o.delete() |
|
101 |
|
|
102 |
for key in keys: |
|
103 |
key.delete() |
|
104 |
|
|
105 |
if dry: |
|
106 |
print "Skipping database commit." |
|
107 |
transaction.rollback() |
|
108 |
else: |
|
109 |
transaction.commit() |
|
110 |
print "User entries removed." |
|
51 |
get_displayname = functools.partial( |
|
52 |
astakos.get_displayname, settings.CYCLADES_SERVICE_TOKEN, |
|
53 |
url=settings.ASTAKOS_URL.replace('im/authenticate', |
|
54 |
'service/api/user_catalogs')) |
|
55 |
get_user_uuid = functools.partial( |
|
56 |
astakos.get_user_uuid, settings.CYCLADES_SERVICE_TOKEN, |
|
57 |
url=settings.ASTAKOS_URL.replace('im/authenticate', |
|
58 |
'service/api/user_catalogs')) |
|
111 | 59 |
|
112 | 60 |
|
113 | 61 |
@transaction.commit_on_success |
... | ... | |
142 | 90 |
key.save() |
143 | 91 |
|
144 | 92 |
|
145 |
@transaction.commit_manually |
|
146 |
def migrate_users(usernames, dry=True): |
|
147 |
usernames = filter(bool, usernames) |
|
148 |
count = 0 |
|
149 |
for u in usernames: |
|
150 |
if not '@' in u: |
|
151 |
warn('Skipping %s. It doesn\'t seem to be an email' % u) |
|
152 |
continue |
|
153 |
|
|
154 |
try: |
|
155 |
uuid = get_user_uuid(u) |
|
156 |
print "%s -> %s" % (u, uuid) |
|
157 |
if not uuid: |
|
158 |
raise Exception("No uuid for %s" % u) |
|
159 |
migrate_user(u, uuid) |
|
160 |
count += 1 |
|
161 |
except Exception, e: |
|
162 |
print "ERROR: User id migration failed (%s)" % e |
|
163 |
|
|
164 |
if dry: |
|
165 |
print "Skipping database commit." |
|
166 |
transaction.rollback() |
|
167 |
else: |
|
168 |
transaction.commit() |
|
169 |
print "Migrated %d users" % count |
|
170 |
|
|
171 |
|
|
172 |
class Command(NoArgsCommand): |
|
93 |
class Command(BaseCommand): |
|
173 | 94 |
help = "Quotas migration helper" |
174 | 95 |
|
175 | 96 |
option_list = BaseCommand.option_list + ( |
... | ... | |
231 | 152 |
if options.get('validate') and not options.get('merge_user') and not \ |
232 | 153 |
options.get('delete_user') and not options.get('user_entries'): |
233 | 154 |
usernames = get_existing_users() |
234 |
_validate_db_state(usernames) |
|
155 |
self._validate_db_state(usernames)
|
|
235 | 156 |
|
236 | 157 |
if options.get('migrate_users'): |
237 |
migrate_users(usernames, dry=self.dry) |
|
158 |
self.migrate_users(usernames, dry=self.dry)
|
|
238 | 159 |
|
239 | 160 |
if options.get('merge_user'): |
240 | 161 |
merge_user(options.get('merge_user')) |
241 |
print "Merge finished."
|
|
162 |
self.stderr.write("Merge finished.")
|
|
242 | 163 |
|
243 | 164 |
if options.get('delete_user'): |
244 |
entries = delete_user(options.get('delete_user'), only_stats=True) |
|
165 |
entries = self.delete_user(options.get('delete_user'), |
|
166 |
only_stats=True) |
|
245 | 167 |
if entries == -1: |
246 | 168 |
return |
247 | 169 |
|
... | ... | |
250 | 172 |
if not confirm == 'yes of course': |
251 | 173 |
return |
252 | 174 |
else: |
253 |
delete_user(options.get('delete_user'), only_stats=False, |
|
254 |
dry=self.dry) |
|
175 |
self.delete_user(options.get('delete_user'), only_stats=False,
|
|
176 |
dry=self.dry)
|
|
255 | 177 |
|
256 | 178 |
if options.get('user_entries'): |
257 |
delete_user(options.get('user_entries')) |
|
179 |
self.delete_user(options.get('user_entries')) |
|
180 |
|
|
181 |
@transaction.commit_manually |
|
182 |
def delete_user(self, username, only_stats=True, dry=True): |
|
183 |
vms = VirtualMachine.objects.filter(userid__exact=username) |
|
184 |
networks = Network.objects.filter(userid__exact=username) |
|
185 |
keys = PublicKeyPair.objects.filter(user__exact=username) |
|
186 |
|
|
187 |
if not len(list(itertools.ifilter(bool, |
|
188 |
map(lambda q: q.count(), |
|
189 |
[vms, networks, keys])))): |
|
190 |
self.stderr.write("No entries exist for '%s'" % username) |
|
191 |
return -1 |
|
192 |
|
|
193 |
if only_stats: |
|
194 |
self.stderr.write("The following entries will be deleted if " |
|
195 |
"you decide to remove this user") |
|
196 |
self.stderr.write("%d Virtual Machines" |
|
197 |
% vms.exclude(operstate='DESTROYED').count()) |
|
198 |
self.stderr.write("%d Destroyed Virtual Machines" |
|
199 |
% vms.filter(operstate='DESTROYED').count()) |
|
200 |
self.stderr.write("%d Networks" % networks.count()) |
|
201 |
self.stderr.write("%d PublicKeyPairs" % keys.count()) |
|
202 |
return |
|
203 |
|
|
204 |
for o in itertools.chain(vms, networks): |
|
205 |
o.delete() |
|
206 |
|
|
207 |
for key in keys: |
|
208 |
key.delete() |
|
209 |
|
|
210 |
if dry: |
|
211 |
self.stderr.write("Skipping database commit.") |
|
212 |
transaction.rollback() |
|
213 |
else: |
|
214 |
transaction.commit() |
|
215 |
self.stderr.write("User entries removed.") |
|
216 |
|
|
217 |
def warn(self, *msgs): |
|
218 |
self.stderr.write("WARNING: %s" % ' '.join(msgs)) |
|
219 |
|
|
220 |
def _validate_db_state(self, usernames): |
|
221 |
|
|
222 |
usernames = filter(bool, usernames) |
|
223 |
invalid_case_users = case_unique(usernames) |
|
224 |
if invalid_case_users: |
|
225 |
invalid_case_users.append(invalid_case_users[0].lower()) |
|
226 |
raise CommandError( |
|
227 |
"Duplicate case insensitive user identifiers exist %r" |
|
228 |
% invalid_case_users) |
|
229 |
|
|
230 |
uuidusers = filter(lambda uid: '@' in uid or uid is None, usernames) |
|
231 |
if len(uuidusers) != len(usernames): |
|
232 |
self.warn("It seems that mixed uuid/email user " |
|
233 |
"identifiers exist in database.") |
|
234 |
return False |
|
235 |
|
|
236 |
return True |
|
237 |
|
|
238 |
@transaction.commit_manually |
|
239 |
def migrate_users(self, usernames, dry=True): |
|
240 |
usernames = filter(bool, usernames) |
|
241 |
count = 0 |
|
242 |
for u in usernames: |
|
243 |
if not '@' in u: |
|
244 |
self.warn('Skipping %s. It doesn\'t seem to be an email' % u) |
|
245 |
continue |
|
246 |
|
|
247 |
try: |
|
248 |
uuid = get_user_uuid(u) |
|
249 |
self.stderr.write("%s -> %s" % (u, uuid)) |
|
250 |
if not uuid: |
|
251 |
raise Exception("No uuid for %s" % u) |
|
252 |
migrate_user(u, uuid) |
|
253 |
count += 1 |
|
254 |
except Exception, e: |
|
255 |
self.stderr.write("ERROR: User id migration failed (%s)" % e) |
|
256 |
|
|
257 |
if dry: |
|
258 |
self.stderr.write("Skipping database commit.") |
|
259 |
transaction.rollback() |
|
260 |
else: |
|
261 |
transaction.commit() |
|
262 |
self.stderr.write("Migrated %d users" % count) |
b/snf-cyclades-app/synnefo/logic/management/commands/queue-inspect.py | ||
---|---|---|
59 | 59 |
client = AMQPClient() |
60 | 60 |
client.connect() |
61 | 61 |
|
62 |
pp = pprint.PrettyPrinter(indent=4, width=4) |
|
62 |
pp = pprint.PrettyPrinter(indent=4, width=4, stream=self.stdout)
|
|
63 | 63 |
|
64 | 64 |
more_msgs = True |
65 | 65 |
counter = 0 |
... | ... | |
68 | 68 |
msg = client.basic_get(queue=queue) |
69 | 69 |
if msg: |
70 | 70 |
counter += 1 |
71 |
print sep
|
|
72 |
print 'Message %d:' % counter
|
|
73 |
print sep
|
|
71 |
self.stderr.write(sep)
|
|
72 |
self.stderr.write('Message %d:' % counter)
|
|
73 |
self.stderr.write(sep)
|
|
74 | 74 |
pp.pprint(msg) |
75 | 75 |
if not requeue or interactive: |
76 | 76 |
if interactive and not get_user_confirmation(): |
b/snf-cyclades-app/synnefo/logic/management/commands/server-import.py | ||
---|---|---|
43 | 43 |
from synnefo.logic import servers |
44 | 44 |
from synnefo import quotas |
45 | 45 |
|
46 |
import sys |
|
47 |
|
|
48 | 46 |
|
49 | 47 |
HELP_MSG = """ |
50 | 48 |
|
... | ... | |
124 | 122 |
raise CommandError(field + " is mandatory") |
125 | 123 |
|
126 | 124 |
import_server(instance_name, backend_id, flavor_id, image_id, user_id, |
127 |
new_public_nic, self.stdout)
|
|
125 |
new_public_nic, self.stderr)
|
|
128 | 126 |
|
129 | 127 |
|
130 | 128 |
def import_server(instance_name, backend_id, flavor_id, image_id, user_id, |
131 |
new_public_nic, stream=sys.stdout):
|
|
129 |
new_public_nic, stream): |
|
132 | 130 |
flavor = common.get_resource("flavor", flavor_id) |
133 | 131 |
backend = common.get_resource("backend", backend_id) |
134 | 132 |
|
... | ... | |
144 | 142 |
raise CommandError("Unexpected error" + str(e)) |
145 | 143 |
|
146 | 144 |
if not new_public_nic: |
147 |
check_instance_nics(instance) |
|
145 |
check_instance_nics(instance, stream)
|
|
148 | 146 |
|
149 | 147 |
shutdown_instance(instance, backend_client, stream=stream) |
150 | 148 |
|
... | ... | |
180 | 178 |
return |
181 | 179 |
|
182 | 180 |
|
183 |
def flavor_from_instance(instance, flavor, stream=sys.stdout):
|
|
181 |
def flavor_from_instance(instance, flavor, stream): |
|
184 | 182 |
beparams = instance['beparams'] |
185 | 183 |
disk_sizes = instance['disk.sizes'] |
186 | 184 |
if len(disk_sizes) != 1: |
... | ... | |
195 | 193 |
cpu=cpu, ram=ram) |
196 | 194 |
|
197 | 195 |
|
198 |
def check_instance_nics(instance): |
|
196 |
def check_instance_nics(instance, stream):
|
|
199 | 197 |
instance_name = instance['name'] |
200 | 198 |
networks = instance['nic.networks.names'] |
201 |
print networks
|
|
199 |
stream.write(str(networks))
|
|
202 | 200 |
try: |
203 | 201 |
networks = map(id_from_network_name, networks) |
204 | 202 |
except Network.InvalidBackendIdError: |
... | ... | |
209 | 207 |
" a public network of synnefo." % instance_name) |
210 | 208 |
|
211 | 209 |
|
212 |
def remove_instance_nics(instance, backend_client, stream=sys.stdout):
|
|
210 |
def remove_instance_nics(instance, backend_client, stream): |
|
213 | 211 |
instance_name = instance['name'] |
214 | 212 |
ips = instance['nic.ips'] |
215 | 213 |
nic_indexes = xrange(0, len(ips)) |
... | ... | |
222 | 220 |
raise CommandError("Cannot remove instance NICs: %s" % error) |
223 | 221 |
|
224 | 222 |
|
225 |
def add_public_nic(instance_name, nic, backend_client, stream=sys.stdout):
|
|
223 |
def add_public_nic(instance_name, nic, backend_client, stream): |
|
226 | 224 |
stream.write("Adding public NIC %s\n" % nic) |
227 | 225 |
jobid = backend_client.ModifyInstance(instance_name, nics=[('add', nic)]) |
228 | 226 |
(status, error) = wait_for_job(backend_client, jobid) |
... | ... | |
230 | 228 |
raise CommandError("Cannot rename instance: %s" % error) |
231 | 229 |
|
232 | 230 |
|
233 |
def shutdown_instance(instance, backend_client, stream=sys.stdout):
|
|
231 |
def shutdown_instance(instance, backend_client, stream): |
|
234 | 232 |
instance_name = instance['name'] |
235 | 233 |
if instance['status'] != 'ADMIN_down': |
236 | 234 |
stream.write("Instance is not down. Shutting down instance...\n") |
... | ... | |
240 | 238 |
raise CommandError("Cannot shutdown instance: %s" % error) |
241 | 239 |
|
242 | 240 |
|
243 |
def rename_instance(old_name, new_name, backend_client, stream=sys.stdout):
|
|
241 |
def rename_instance(old_name, new_name, backend_client, stream): |
|
244 | 242 |
stream.write("Renaming instance to %s\n" % new_name) |
245 | 243 |
|
246 | 244 |
jobid = backend_client.RenameInstance(old_name, new_name, |
... | ... | |
250 | 248 |
raise CommandError("Cannot rename instance: %s" % error) |
251 | 249 |
|
252 | 250 |
|
253 |
def startup_instance(name, backend_client, stream=sys.stdout):
|
|
251 |
def startup_instance(name, backend_client, stream): |
|
254 | 252 |
stream.write("Starting instance %s\n" % name) |
255 | 253 |
jobid = backend_client.StartupInstance(name) |
256 | 254 |
(status, error) = wait_for_job(backend_client, jobid) |
b/snf-webproject/synnefo/webproject/management/commands/link_static.py | ||
---|---|---|
29 | 29 |
""" |
30 | 30 |
Collect static files required by synnefo to a specific location |
31 | 31 |
""" |
32 |
import os, shutil
|
|
32 |
import os |
|
33 | 33 |
|
34 | 34 |
from django.utils.importlib import import_module |
35 | 35 |
from optparse import make_option |
36 | 36 |
|
37 |
from django.core.management.base import BaseCommand, CommandError
|
|
37 |
from django.core.management.base import BaseCommand |
|
38 | 38 |
from django.conf import settings |
39 | 39 |
|
40 | 40 |
STATIC_FILES = getattr(settings, "STATIC_FILES", {}) |
41 | 41 |
|
42 |
|
|
42 | 43 |
class Command(BaseCommand): |
43 | 44 |
|
44 | 45 |
help = 'Symlink static files to directory specified' |
45 | 46 |
|
46 | 47 |
option_list = BaseCommand.option_list + ( |
47 |
make_option('--static-root', |
|
48 |
make_option( |
|
49 |
'--static-root', |
|
48 | 50 |
action='store', |
49 | 51 |
dest='static_root', |
50 | 52 |
default=settings.MEDIA_ROOT, |
51 |
help='Path to place symlinks (default: `%s`)' % settings.MEDIA_ROOT), |
|
52 |
make_option('--dry-run', |
|
53 |
help='Path to place symlinks (default: `%s`)' |
|
54 |
% settings.MEDIA_ROOT), |
|
55 |
make_option( |
|
56 |
'--dry-run', |
|
53 | 57 |
action='store_true', |
54 | 58 |
dest='dry', |
55 | 59 |
default=False, |
... | ... | |
58 | 62 |
|
59 | 63 |
def collect_files(self, target): |
60 | 64 |
symlinks = [] |
61 |
dirs_to_create = set() |
|
62 | 65 |
for module, ns in STATIC_FILES.iteritems(): |
63 | 66 |
module = import_module(module) |
64 |
static_root = os.path.join(os.path.dirname(module.__file__), 'static') |
|
67 |
static_root = os.path.join(os.path.dirname(module.__file__), |
|
68 |
'static') |
|
65 | 69 |
|
66 | 70 |
# no nested dir exists for the app |
67 | 71 |
if ns == '': |
68 | 72 |
for f in os.listdir(static_root): |
69 |
symlinks.append((os.path.join(static_root, f), os.path.join(target, ns, f))) |
|
73 |
symlinks.append((os.path.join(static_root, f), |
|
74 |
os.path.join(target, ns, f))) |
|
70 | 75 |
|
71 | 76 |
# symlink whole app directory |
72 | 77 |
else: |
73 |
symlinks.append((os.path.join(static_root), os.path.join(target, ns))) |
|
78 |
symlinks.append((os.path.join(static_root), |
|
79 |
os.path.join(target, ns))) |
|
74 | 80 |
|
75 | 81 |
return symlinks |
76 | 82 |
|
77 | 83 |
def handle(self, *args, **options): |
78 | 84 |
|
79 |
print "The following synlinks will get created"
|
|
85 |
self.stderr.write("The following synlinks will get created")
|
|
80 | 86 |
|
81 | 87 |
symlinks = self.collect_files(options['static_root']) |
82 | 88 |
for linkfrom, linkto in symlinks: |
83 |
print "Symlink '%s' to '%s' will get created." % (linkfrom, linkto) |
|
89 |
self.stderr.write("Symlink '%s' to '%s' will get created." |
|
90 |
% (linkfrom, linkto)) |
|
84 | 91 |
|
85 | 92 |
if not options['dry']: |
86 | 93 |
confirm = raw_input(""" |
... | ... | |
89 | 96 |
|
90 | 97 |
if confirm == "yes": |
91 | 98 |
for linkfrom, linkto in symlinks: |
92 |
print "Creating link from %s to %s" % (linkfrom, linkto) |
|
99 |
self.stderr.write("Creating link from %s to %s" |
|
100 |
% (linkfrom, linkto)) |
|
93 | 101 |
if os.path.exists(linkto): |
94 |
print "Skippig %s" % linkto
|
|
102 |
self.stderr.write("Skippig %s" % linkto)
|
|
95 | 103 |
continue |
96 | 104 |
|
97 | 105 |
os.symlink(linkfrom, linkto) |
98 |
|
b/snf-webproject/synnefo/webproject/management/commands/show_urls.py | ||
---|---|---|
18 | 18 |
|
19 | 19 |
try: |
20 | 20 |
# 2008-05-30 admindocs found in newforms-admin brand |
21 |
from django.contrib.admindocs.views import extract_views_from_urlpatterns, simplify_regex |
|
21 |
from django.contrib.admindocs.views import \ |
|
22 |
extract_views_from_urlpatterns, simplify_regex |
|
22 | 23 |
except ImportError: |
23 | 24 |
# fall back to trunk, pre-NFA merge |
24 |
from django.contrib.admin.views.doc import extract_views_from_urlpatterns, simplify_regex |
|
25 |
from django.contrib.admin.views.doc import \ |
|
26 |
extract_views_from_urlpatterns, simplify_regex |
|
27 |
|
|
25 | 28 |
|
26 | 29 |
class Command(BaseCommand): |
27 | 30 |
help = "Displays all of the url matching routes for the project." |
... | ... | |
35 | 38 |
style = color_style() |
36 | 39 |
|
37 | 40 |
if settings.ADMIN_FOR: |
38 |
settings_modules = [__import__(m, {}, {}, ['']) for m in settings.ADMIN_FOR] |
|
41 |
settings_modules = [__import__(m, {}, {}, ['']) |
|
42 |
for m in settings.ADMIN_FOR] |
|
39 | 43 |
else: |
40 | 44 |
settings_modules = [settings] |
41 | 45 |
|
... | ... | |
46 | 50 |
except Exception, e: |
47 | 51 |
if options.get('traceback', None): |
48 | 52 |
import traceback |
49 |
traceback.print_exc() |
|
50 |
print style.ERROR("Error occurred while trying to load %s: %s" % (settings_mod.ROOT_URLCONF, str(e))) |
|
53 |
self.stderr.write(traceback.format_exc()) |
|
54 |
self.stderr.write( |
|
55 |
style.ERROR("Error occurred while trying to load %s: %s" |
|
56 |
% (settings_mod.ROOT_URLCONF, str(e)))) |
|
51 | 57 |
continue |
52 |
view_functions = extract_views_from_urlpatterns(urlconf.urlpatterns) |
|
58 |
view_functions = \ |
|
59 |
extract_views_from_urlpatterns(urlconf.urlpatterns) |
|
53 | 60 |
for (func, regex) in view_functions: |
54 |
func_name = hasattr(func, '__name__') and func.__name__ or repr(func) |
|
55 |
views.append("%(url)s\t%(module)s.%(name)s" % {'name': style.MODULE_NAME(func_name), |
|
56 |
'module': style.MODULE(getattr(func, '__module__', '<no module>')), |
|
57 |
'url': style.URL(simplify_regex(regex))}) |
|
61 |
func_name = hasattr(func, '__name__') and \ |
|
62 |
func.__name__ or repr(func) |
|
63 |
views.append("%(url)s\t%(module)s.%(name)s" |
|
64 |
% {'name': style.MODULE_NAME(func_name), |
|
65 |
'module': style.MODULE( |
|
66 |
getattr(func, '__module__', |
|
67 |
'<no module>')), |
|
68 |
'url': style.URL(simplify_regex(regex))}) |
|
58 | 69 |
|
59 | 70 |
return "\n".join([v for v in views]) |
Also available in: Unified diff