def shutdown_instance(instance, backend_client, stream): instance_name = instance['name'] if instance['status'] != 'ADMIN_down': stream.write("Instance is not down. Shutting down instance...\n") jobid = backend_client.ShutdownInstance(instance_name) (status, error) = wait_for_job(backend_client, jobid) if status != 'success': raise CommandError("Cannot shutdown instance: %s" % error)
def rename_instance(old_name, new_name, backend_client, stream=sys.stdout): stream.write("Renaming instance to %s\n" % new_name) jobid = backend_client.RenameInstance(old_name, new_name, ip_check=False, name_check=False) (status, error) = wait_for_job(backend_client, jobid) if status != 'success': raise CommandError("Cannot rename instance: %s" % error)
def shutdown_instance(instance, backend_client, stream=sys.stdout): instance_name = instance['name'] if instance['status'] != 'ADMIN_down': stream.write("Instance is not down. Shutting down instance...\n") jobid = backend_client.ShutdownInstance(instance_name) (status, error) = wait_for_job(backend_client, jobid) if status != 'success': raise CommandError("Cannot shutdown instance: %s" % error)
def rename_instance(old_name, new_name, backend_client, stream): stream.write("Renaming instance to %s\n" % new_name) jobid = backend_client.RenameInstance(old_name, new_name, ip_check=False, name_check=False) (status, error) = wait_for_job(backend_client, jobid) if status != 'success': raise CommandError("Cannot rename instance: %s" % error)
def remove_instance_nics(instance, backend_client, stream): instance_name = instance['name'] ips = instance['nic.ips'] nic_indexes = xrange(0, len(ips)) op = map(lambda x: ('remove', x, {}), nic_indexes) stream.write("Removing instance nics\n") op.reverse() jobid = backend_client.ModifyInstance(instance_name, nics=op) (status, error) = wait_for_job(backend_client, jobid) if status != 'success': raise CommandError("Cannot remove instance NICs: %s" % error)
def remove_instance_nics(instance, backend_client, stream=sys.stdout): instance_name = instance['name'] ips = instance['nic.ips'] nic_indexes = xrange(0, len(ips)) op = map(lambda x: ('remove', x, {}), nic_indexes) stream.write("Removing instance nics\n") op.reverse() jobid = backend_client.ModifyInstance(instance_name, nics=op) (status, error) = wait_for_job(backend_client, jobid) if status != 'success': raise CommandError("Cannot remove instance NICs: %s" % error)
def wait_server_job(server): jobID = server.task_job_id client = server.get_client() status, error = backend.wait_for_job(client, jobID) if status != "success": raise ValueError(error)
def startup_instance(name, backend_client, stream): stream.write("Starting instance %s\n" % name) jobid = backend_client.StartupInstance(name) (status, error) = wait_for_job(backend_client, jobid) if status != 'success': raise CommandError("Cannot rename instance: %s" % error)
def add_public_nic(instance_name, nic, backend_client, stream): stream.write("Adding public NIC %s\n" % nic) jobid = backend_client.ModifyInstance(instance_name, nics=[('add', nic)]) (status, error) = wait_for_job(backend_client, jobid) if status != 'success': raise CommandError("Cannot rename instance: %s" % error)
def wait_ganeti_job(client, jobID, stdout): status, error = backend_mod.wait_for_job(client, jobID) if status == "success": stdout.write("Job finished successfully.\n") else: raise CommandError("Job failed! Error: %s\n" % error)
def startup_instance(name, backend_client, stream=sys.stdout): stream.write("Starting instance %s\n" % name) jobid = backend_client.StartupInstance(name) (status, error) = wait_for_job(backend_client, jobid) if status != 'success': raise CommandError("Cannot rename instance: %s" % error)
def add_public_nic(instance_name, nic, backend_client, stream=sys.stdout): stream.write("Adding public NIC %s\n" % nic) jobid = backend_client.ModifyInstance(instance_name, nics=[('add', nic)]) (status, error) = wait_for_job(backend_client, jobid) if status != 'success': raise CommandError("Cannot rename instance: %s" % error)