def destroy_machine(request): """Destroys a machine on a certain backend. After destroying a machine it also deletes all key associations. However, it doesn't undeploy the keypair. There is no need to do it because the machine will be destroyed. """ try: conn = connect(request) except: return Response("Backend not found", 404) machine_id = request.matchdict["machine"] machine = Node(machine_id, name=machine_id, state=0, public_ips=[], private_ips=[], driver=conn) machine.destroy() backend_id = request.matchdict["backend"] pair = [backend_id, machine_id] try: keypairs = request.environ["beaker.session"]["keypairs"] except: keypairs = request.registry.settings.get("keypairs", {}) for key in keypairs: machines = keypairs[key].get("machines", None) if pair in machines: disassociate_key(request, key, backend_id, machine_id, undeploy=False) return Response("Success", 200)
def update_key(request): """Associate/disassociate a keypair with a machine, or get private key. """ params = request.json_body if params["action"] == "associate" or params["action"] == "disassociate": key_id = params["key_id"] backend_id = params["backend_id"] machine_id = params["machine_id"] if params["action"] == "associate": ret = associate_key(request, key_id, backend_id, machine_id) else: ret = disassociate_key(request, key_id, backend_id, machine_id) elif params["action"] == "get_private_key": ret = get_private_key(request) else: ret = Response("Key action not supported", 405) return ret
def update_key(request): """Associate/disassociate a keypair with a machine, or get private key. """ params = request.json_body if params['action'] == 'associate' or params['action'] == 'disassociate': key_id = params['key_id'] backend_id = params['backend_id'] machine_id = params['machine_id'] if params['action'] == 'associate': ret = associate_key(request, key_id, backend_id, machine_id) else: ret = disassociate_key(request, key_id, backend_id, machine_id) elif params['action'] == 'get_private_key': ret = get_private_key(request) else: ret = Response('Key action not supported', 405) return ret