(instance_name)
Get the websocket URL for the serial proxy for a given nova server (instance)
    :param instance_name: name of the instance
    :return: websocket url ws://x.x.x.x:xxxx/token=xxxxx
Get the websocket URL for the serial proxy for a given nova server (instance)
    :param instance_name: name of the instance
    :return: websocket url ws://x.x.x.x:xxxx/token=xxxxx
Get the websocket URL for the serial proxy for a given nova server ( instance ) : param instance_name : name of the instance : return : websocket url ws : // x . x . x . x : xxxx / token = xxxxx
def get_nova_serial_console(instance_name):
    """
    Get the websocket URL for the serial proxy for a given nova server (instance)
    :param instance_name: name of the instance
    :return: websocket url ws://x.x.x.x:xxxx/token=xxxxx
    """
    logger.debug("--- get_nova_serial_console ---")

    logger.debug("Looking for instance: %s" % instance_name)
    server_detail_url = create_nova_url('/%s/servers?name=%s' % (_tenant_id, instance_name))
    server_detail = do_nova_get(server_detail_url)

    # logger.debug("got details: %s" % server_detail)

    if server_detail is None:
        return None

    json_data = json.loads(server_detail)
    if len(json_data["servers"]) == 0:
        return None

    server_uuid = ""
    for s in json_data["servers"]:
        if s["name"] == instance_name:
            server_uuid = s["id"]
            break

    if server_uuid == "":
        logger.error("Console not found with server name %s" % instance_name)
        return None

    # logger.debug(server_uuid)
    data = '{"os-getSerialConsole": {"type": "serial"}}'
    url = create_nova_url('/%s/servers/%s/action' % (_tenant_id, server_uuid))

    try:
        project_auth_token = get_project_auth_token(configuration.openstack_project)
        request = urllib2.Request(url)
        request.add_header("Content-Type", "application/json")
        request.add_header("charset", "UTF-8")
        request.add_header("X-Auth-Token", project_auth_token)
        request.get_method = lambda: 'POST'
        result = urllib2.urlopen(request, data)
        console_json_data = json.loads(result.read())
        logger.debug(json.dumps(console_json_data, indent=2))
        return console_json_data["console"]["url"]
    except URLError as e:
        logger.error("Could not get serial console to instance: %s" % instance_name)
        logger.error("error was %s" % str(e))
        return None
def get_nova_serial_console ( instance_name ) : logger . debug ( "--- get_nova_serial_console ---" ) logger . debug ( "Looking for instance: %s" % instance_name ) server_detail_url = create_nova_url ( '/%s/servers?name=%s' % ( _tenant_id , instance_name ) ) server_detail = do_nova_get ( server_detail_url ) # logger.debug("got details: %s" % server_detail) if server_detail is None : return None json_data = json . loads ( server_detail ) if len ( json_data [ "servers" ] ) == 0 : return None server_uuid = "" for s in json_data [ "servers" ] : if s [ "name" ] == instance_name : server_uuid = s [ "id" ] break if server_uuid == "" : logger . error ( "Console not found with server name %s" % instance_name ) return None # logger.debug(server_uuid) data = '{"os-getSerialConsole": {"type": "serial"}}' url = create_nova_url ( '/%s/servers/%s/action' % ( _tenant_id , server_uuid ) ) try : project_auth_token = get_project_auth_token ( configuration . openstack_project ) request = urllib2 . Request ( url ) request . add_header ( "Content-Type" , "application/json" ) request . add_header ( "charset" , "UTF-8" ) request . add_header ( "X-Auth-Token" , project_auth_token ) request . get_method = lambda : 'POST' result = urllib2 . urlopen ( request , data ) console_json_data = json . loads ( result . read ( ) ) logger . debug ( json . dumps ( console_json_data , indent = 2 ) ) return console_json_data [ "console" ] [ "url" ] except URLError as e : logger . error ( "Could not get serial console to instance: %s" % instance_name ) logger . error ( "error was %s" % str ( e ) ) return None