skip to Main Content

I have multiple User Managed Vertex AI Workbench instances running in my GCP Project.
Each can run one or more Jupyter Workspaces by clicking OPEN JUPYTERLAB. Each Jupyter lab opens in a new browser tab.
From one of the Jupyter lab tabs, how can I tell which workbench instance or VM is hosting it?

EDIT: The first answer by @kiran mathew is not working for me because I have a custom docker container and that solution returns the hostname of the container which is not set to the Workench instance name. I changed the title of the question to be specific to custom containers.

2

Answers


  1. Chosen as BEST ANSWER

    Using the URL solution in the comment by @KiranMathew, here is a function to return the workbook name that works with custom docker containers.

        def get_workbook_name():
            url = "http://metadata.google.internal/computeMetadata/v1/instance/name"
            req = urllib.request.Request(url)
            req.add_header("Metadata-Flavor", "Google")
            workbook_name = urllib.request.urlopen(req).read().decode()
            return workbook_name
    

    Still anticipating a simpler approach will be available as foreshadowed by @gogasca

    You can also get the project id with: http://metadata.google.internal/computeMetadata/v1/project/project-id


  2. Python code:

    import socket 
    instance_name = socket.gethostname() 
    print(instance_name)
    

    I have two notebooks stacckkk and stackoverflow2 . When I ran the above code in these two notebook individually I got the below results.

    enter image description here

    Result:

    1st Notebook

    enter image description here

    2nd Notebook

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search