def console(vm, console_type): """Arrange for an OOB console of the specified type This method arranges for an OOB console of the specified type. Only consoles of type "vnc" are supported for now. It uses a running instance of vncauthproxy to setup proper VNC forwarding with a random password, then returns the necessary VNC connection info to the caller. """ log.info("Get console VM %s, type %s", vm, console_type) # Use RAPI to get VNC console information for this instance if vm.operstate != "STARTED": raise faults.BadRequest('Server not in ACTIVE state.') if settings.TEST: console_data = {'kind': 'vnc', 'host': 'ganeti_node', 'port': 1000} else: console_data = backend.get_instance_console(vm) if console_data['kind'] != 'vnc': message = 'got console of kind %s, not "vnc"' % console_data['kind'] raise faults.ServiceUnavailable(message) # Let vncauthproxy decide on the source port. # The alternative: static allocation, e.g. # sport = console_data['port'] - 1000 sport = 0 daddr = console_data['host'] dport = console_data['port'] password = util.random_password() if settings.TEST: fwd = {'source_port': 1234, 'status': 'OK'} else: vnc_extra_opts = settings.CYCLADES_VNCAUTHPROXY_OPTS fwd = request_vnc_forwarding(sport, daddr, dport, password, **vnc_extra_opts) if fwd['status'] != "OK": raise faults.ServiceUnavailable('vncauthproxy returned error status') # Verify that the VNC server settings haven't changed if not settings.TEST: if console_data != backend.get_instance_console(vm): raise faults.ServiceUnavailable('VNC Server settings changed.') console = { 'type': 'vnc', 'host': getfqdn(), 'port': fwd['source_port'], 'password': password } return console
def console(vm, console_type): """Arrange for an OOB console of the specified type This method arranges for an OOB console of the specified type. Only consoles of type "vnc" are supported for now. It uses a running instance of vncauthproxy to setup proper VNC forwarding with a random password, then returns the necessary VNC connection info to the caller. """ log.info("Get console VM %s, type %s", vm, console_type) # Use RAPI to get VNC console information for this instance if vm.operstate != "STARTED": raise faults.BadRequest('Server not in ACTIVE state.') if settings.TEST: console_data = {'kind': 'vnc', 'host': 'ganeti_node', 'port': 1000} else: console_data = backend.get_instance_console(vm) if console_data['kind'] != 'vnc': message = 'got console of kind %s, not "vnc"' % console_data['kind'] raise faults.ServiceUnavailable(message) # Let vncauthproxy decide on the source port. # The alternative: static allocation, e.g. # sport = console_data['port'] - 1000 sport = 0 daddr = console_data['host'] dport = console_data['port'] password = util.random_password() if settings.TEST: fwd = {'source_port': 1234, 'status': 'OK'} else: vnc_extra_opts = settings.CYCLADES_VNCAUTHPROXY_OPTS fwd = request_vnc_forwarding(sport, daddr, dport, password, **vnc_extra_opts) if fwd['status'] != "OK": raise faults.ServiceUnavailable('vncauthproxy returned error status') # Verify that the VNC server settings haven't changed if not settings.TEST: if console_data != backend.get_instance_console(vm): raise faults.ServiceUnavailable('VNC Server settings changed.') console = { 'type': 'vnc', 'host': getfqdn(), 'port': fwd['source_port'], 'password': password} return console
def get_console(request, vm, args): """Arrange for an OOB console of the specified type This method arranges for an OOB console of the specified type. Only consoles of type "vnc" are supported for now. It uses a running instance of vncauthproxy to setup proper VNC forwarding with a random password, then returns the necessary VNC connection info to the caller. """ # Normal Response Code: 200 # Error Response Codes: computeFault (400, 500), # serviceUnavailable (503), # unauthorized (401), # badRequest (400), # badMediaType(415), # itemNotFound (404), # buildInProgress (409), # overLimit (413) log.info("Get console VM %s", vm) console_type = args.get('type', '') if (console_type != 'vnc' and console_type != 'wsvnc'): raise faults.BadRequest('Type can only be "vnc" or "wsvnc."') # Use RAPI to get VNC console information for this instance if get_rsapi_state(vm) != 'ACTIVE': raise faults.BadRequest('Server not in ACTIVE state.') if settings.TEST: console_data = {'kind': 'vnc', 'host': 'ganeti_node', 'port': 1000} else: console_data = backend.get_instance_console(vm) if console_data['kind'] != 'vnc': message = 'got console of kind %s, not "vnc"' % console_data['kind'] raise faults.ServiceUnavailable(message) # Let vncauthproxy decide on the source port. # The alternative: static allocation, e.g. # sport = console_data['port'] - 1000 sport = 27631 daddr = console_data['host'] dport = console_data['port'] password = random_password() if settings.TEST: fwd = {'source_port': 1234, 'status': 'OK'} else: fwd = request_vnc_forwarding(sport, daddr, dport, password,auth_user="******",auth_password="******",console_type=console_type) #fwd = request_vnc_forwarding(sport, daddr, dport, password) if fwd['status'] != "OK": raise faults.ServiceUnavailable('vncauthproxy returned error status') # Verify that the VNC server settings haven't changed if not settings.TEST: if console_data != backend.get_instance_console(vm): raise faults.ServiceUnavailable('VNC Server settings changed.') console = { 'type': console_type, 'host': getfqdn(), 'port': fwd['source_port'], 'password': password} if request.serialization == 'xml': mimetype = 'application/xml' data = render_to_string('console.xml', {'console': console}) else: mimetype = 'application/json' data = json.dumps({'console': console}) return HttpResponse(data, mimetype=mimetype, status=200)
def get_console(request, vm, args): """Arrange for an OOB console of the specified type This method arranges for an OOB console of the specified type. Only consoles of type "vnc" are supported for now. It uses a running instance of vncauthproxy to setup proper VNC forwarding with a random password, then returns the necessary VNC connection info to the caller. """ # Normal Response Code: 200 # Error Response Codes: computeFault (400, 500), # serviceUnavailable (503), # unauthorized (401), # badRequest (400), # badMediaType(415), # itemNotFound (404), # buildInProgress (409), # overLimit (413) log.info("Get console VM %s", vm) console_type = args.get('type', '') if (console_type != 'vnc' and console_type != 'wsvnc'): raise faults.BadRequest('Type can only be "vnc" or "wsvnc."') # Use RAPI to get VNC console information for this instance if get_rsapi_state(vm) != 'ACTIVE': raise faults.BadRequest('Server not in ACTIVE state.') if settings.TEST: console_data = {'kind': 'vnc', 'host': 'ganeti_node', 'port': 1000} else: console_data = backend.get_instance_console(vm) if console_data['kind'] != 'vnc': message = 'got console of kind %s, not "vnc"' % console_data['kind'] raise faults.ServiceUnavailable(message) # Let vncauthproxy decide on the source port. # The alternative: static allocation, e.g. # sport = console_data['port'] - 1000 sport = 27631 daddr = console_data['host'] dport = console_data['port'] password = random_password() if settings.TEST: fwd = {'source_port': 1234, 'status': 'OK'} else: fwd = request_vnc_forwarding(sport, daddr, dport, password, auth_user="******", auth_password="******", console_type=console_type) #fwd = request_vnc_forwarding(sport, daddr, dport, password) if fwd['status'] != "OK": raise faults.ServiceUnavailable('vncauthproxy returned error status') # Verify that the VNC server settings haven't changed if not settings.TEST: if console_data != backend.get_instance_console(vm): raise faults.ServiceUnavailable('VNC Server settings changed.') console = { 'type': console_type, 'host': getfqdn(), 'port': fwd['source_port'], 'password': password } if request.serialization == 'xml': mimetype = 'application/xml' data = render_to_string('console.xml', {'console': console}) else: mimetype = 'application/json' data = json.dumps({'console': console}) return HttpResponse(data, mimetype=mimetype, status=200)