def get_floating_ip(request, floating_ip_id): """Return information for a floating IP.""" userid = request.user_uniq floating_ip = util.get_floating_ip_by_id(userid, floating_ip_id) request.serialization = "json" data = json.dumps({"floatingip": ip_to_dict(floating_ip)}) return HttpResponse(data, status=200)
def reassign_floating_ip( floating_ip_id, project, shared_to_project, credentials, atomic_context=None): floating_ip = util.get_floating_ip_by_id(credentials, floating_ip_id, for_update=True) if not credentials.is_admin and credentials.userid != floating_ip.userid: raise faults.Forbidden("Action 'reassign' is allowed only to the owner" " of the floating IP.") validate_ip_action(floating_ip, "REASSIGN", silent=False) if floating_ip.project == project: if floating_ip.shared_to_project != shared_to_project: log.info("%s floating_ip %s to project %s", "Sharing" if shared_to_project else "Unsharing", floating_ip, project) floating_ip.shared_to_project = shared_to_project floating_ip.save() else: action_fields = {"to_project": project, "from_project": floating_ip.project} log.info("Reassigning floating_ip %s from project %s to %s, shared: %s", floating_ip, floating_ip.project, project, shared_to_project) floating_ip.project = project floating_ip.shared_to_project = shared_to_project floating_ip.save() quotas.issue_and_accept_commission(floating_ip, action="REASSIGN", action_fields=action_fields, atomic_context=atomic_context) return floating_ip
def release_floating_ip(request, floating_ip_id): """Release a floating IP.""" userid = request.user_uniq log.info("release_floating_ip '%s'. User '%s'.", floating_ip_id, userid) floating_ip = util.get_floating_ip_by_id(userid, floating_ip_id, for_update=True) ips.delete_floating_ip(floating_ip) log.info("User '%s' released IP '%s", userid, floating_ip) return HttpResponse(status=204)
def release_floating_ip(request, floating_ip_id): """Release a floating IP.""" userid = request.user_uniq log.debug("User: %s, Floating IP: %s, Action: delete", request.user_uniq, floating_ip_id) floating_ip = util.get_floating_ip_by_id(userid, request.user_projects, floating_ip_id, for_update=True) ips.delete_floating_ip(floating_ip) log.info("User %s deleted floating IP %s", request.user_uniq, floating_ip.id) return HttpResponse(status=204)
def _delete_floating_ip(floating_ip_id, credentials, atomic_context=None): floating_ip = util.get_floating_ip_by_id(credentials, floating_ip_id, for_update=True) validate_ip_action(floating_ip, "DELETE", silent=False) # Lock network to prevent deadlock Network.objects.select_for_update().get(id=floating_ip.network_id) # Return the address of the floating IP back to pool floating_ip.release_address() # And mark the floating IP as deleted floating_ip.deleted = True floating_ip.save() # Release quota for floating IP quotas.issue_and_accept_commission(floating_ip, action="DESTROY", atomic_context=atomic_context) return floating_ip
def floating_ip_action_demux(request, floating_ip_id): userid = request.user_uniq req = utils.get_json_body(request) log.debug('floating_ip_action %s %s', floating_ip_id, req) if len(req) != 1: raise faults.BadRequest('Malformed request.') floating_ip = util.get_floating_ip_by_id(userid, floating_ip_id, for_update=True) action = req.keys()[0] try: f = FLOATING_IP_ACTIONS[action] except KeyError: raise faults.BadRequest("Action %s not supported." % action) action_args = req[action] if not isinstance(action_args, dict): raise faults.BadRequest("Invalid argument.") return f(request, floating_ip, action_args)
def reassign_floating_ip(floating_ip_id, project, shared_to_project, credentials, atomic_context=None): floating_ip = util.get_floating_ip_by_id(credentials, floating_ip_id, for_update=True) if not credentials.is_admin and credentials.userid != floating_ip.userid: raise faults.Forbidden("Action 'reassign' is allowed only to the owner" " of the floating IP.") validate_ip_action(floating_ip, "REASSIGN", silent=False) if floating_ip.project == project: if floating_ip.shared_to_project != shared_to_project: log.info("%s floating_ip %s to project %s", "Sharing" if shared_to_project else "Unsharing", floating_ip, project) floating_ip.shared_to_project = shared_to_project floating_ip.save() else: action_fields = { "to_project": project, "from_project": floating_ip.project } log.info( "Reassigning floating_ip %s from project %s to %s, shared: %s", floating_ip, floating_ip.project, project, shared_to_project) floating_ip.project = project floating_ip.shared_to_project = shared_to_project floating_ip.save() quotas.issue_and_accept_commission(floating_ip, action="REASSIGN", action_fields=action_fields, atomic_context=atomic_context) return floating_ip
def get_floating_ip(request, floating_ip_id, view=_floatingip_details_view): """Return information for a floating IP.""" floating_ip = util.get_floating_ip_by_id(request.credentials, floating_ip_id) return HttpResponse(view(floating_ip), status=200)