Revision 99667854 snf-cyclades-app/synnefo/api/floating_ips.py
b/snf-cyclades-app/synnefo/api/floating_ips.py | ||
---|---|---|
62 | 62 |
'synnefo.api.floating_ips', |
63 | 63 |
(r'^(?:/|.json|.xml)?$', 'demux'), |
64 | 64 |
(r'^/detail(?:.json|.xml)?$', 'list_floating_ips', {'detail': True}), |
65 |
(r'^/(\w+)(?:/|.json|.xml)?$', 'floating_ip_demux')) |
|
65 |
(r'^/(\w+)(?:/|.json|.xml)?$', 'floating_ip_demux'), |
|
66 |
(r'^/(\w+)/action(?:.json|.xml)?$', 'floating_ip_action_demux'), |
|
67 |
) |
|
66 | 68 |
|
67 | 69 |
|
68 | 70 |
def demux(request): |
... | ... | |
87 | 89 |
allowed_methods=['GET', 'DELETE']) |
88 | 90 |
|
89 | 91 |
|
92 |
@api.api_method(http_method='POST', user_required=True, logger=log, |
|
93 |
serializations=["json"]) |
|
94 |
def floating_ip_action_demux(request, floating_ip_id): |
|
95 |
userid = request.user_uniq |
|
96 |
req = utils.get_request_dict(request) |
|
97 |
log.debug('floating_ip_action %s %s', floating_ip_id, req) |
|
98 |
if len(req) != 1: |
|
99 |
raise faults.BadRequest('Malformed request.') |
|
100 |
floating_ip = util.get_floating_ip_by_id(userid, |
|
101 |
floating_ip_id, |
|
102 |
for_update=True) |
|
103 |
action = req.keys()[0] |
|
104 |
try: |
|
105 |
f = FLOATING_IP_ACTIONS[action] |
|
106 |
except KeyError: |
|
107 |
raise faults.BadRequest("Action %s not supported." % action) |
|
108 |
action_args = req[action] |
|
109 |
if not isinstance(action_args, dict): |
|
110 |
raise faults.BadRequest("Invalid argument.") |
|
111 |
|
|
112 |
return f(request, floating_ip, action_args) |
|
113 |
|
|
114 |
|
|
90 | 115 |
def ip_to_dict(floating_ip): |
91 | 116 |
machine_id = None |
92 | 117 |
port_id = None |
... | ... | |
236 | 261 |
return HttpResponse(data, status=200) |
237 | 262 |
|
238 | 263 |
|
264 |
@transaction.commit_on_success |
|
265 |
def reassign(request, floating_ip, args): |
|
266 |
project = args.get("project") |
|
267 |
if project is None: |
|
268 |
raise faults.BadRequest("Missing 'project' attribute.") |
|
269 |
ips.reassign_floating_ip(floating_ip, project) |
|
270 |
return HttpResponse(status=200) |
|
271 |
|
|
272 |
|
|
273 |
FLOATING_IP_ACTIONS = { |
|
274 |
"reassign": reassign, |
|
275 |
} |
|
276 |
|
|
277 |
|
|
239 | 278 |
def network_to_floating_ip_pool(network): |
240 | 279 |
"""Convert a 'Network' object to a floating IP pool dict.""" |
241 | 280 |
total, free = network.ip_count() |
Also available in: Unified diff