# Retrieving instance metadata from within the instance

**URL:** <https://forum.opennebula.io/t/retrieving-instance-metadata-from-within-the-instance/2044>\
**Category:** Product Support\
**Created:** [April 3, 2016, 8:32pm UTC](https://forum.opennebula.io/t/retrieving-instance-metadata-from-within-the-instance/2044 "2016-04-03T20:32:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![carletes](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/carletes/32/4618_2.png) [@carletes](https://forum.opennebula.io/u/carletes)\
**Post date:** [April 3, 2016, 8:32pm UTC](https://forum.opennebula.io/t/retrieving-instance-metadata-from-within-the-instance/2044/1 "2016-04-03T20:32:26Z")

</div>

I’d like to read instance metadata from within the VM. In particular, I’d like to know which Elastic IPs may have been attached to a given VM instantiated through the EC2 OpenNebula API.

I was thinking on writing an HTTP server that listens on [http://169.254.169.254](http://169.254.169.254), like what Amazon offers in [http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html).

Is there a simpler way of doing it right now?

---

<div class="post-metadata">

**Author:** ![dmolina](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/dmolina/32/22_2.png) [@dmolina](https://forum.opennebula.io/u/dmolina)\
**Post date:** [April 4, 2016, 9:48am UTC](https://forum.opennebula.io/t/retrieving-instance-metadata-from-within-the-instance/2044/2 "2016-04-04T09:48:21Z")

</div>

You may want to take a look to OneGate:  
[http://docs.opennebula.org/4.14/advanced\_administration/application\_insight/onegate\_overview.html](http://docs.opennebula.org/4.14/advanced_administration/application_insight/onegate_overview.html)

---

<div class="post-metadata">

**Author:** ![carletes](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/carletes/32/4618_2.png) [@carletes](https://forum.opennebula.io/u/carletes)\
**Post date:** [April 4, 2016, 7:23pm UTC](https://forum.opennebula.io/t/retrieving-instance-metadata-from-within-the-instance/2044/3 "2016-04-04T19:23:44Z")

</div>

Thanks, @dmolina! I just set it up at home, and I can connect to OneGate from within my VM.

I cannot find the Elastic IP information I’m interested in, however. I have associated an Elastic IP (192.168.1.1) to my instance (`i-00000118`):

```
$ econe-describe-instances 
  instanceId ImageId State IP instanceType
  i-00000118 ami-00000043 running 172.16.0.1 t1.micro
$ econe-describe-addresses 
     publicIp instanceId
  192.168.1.1 i-00000118
$

```

When I query the OneGate endpoint, I do not see any Elastic IP information:

```
$ sh -x query.sh
+ curl -v http://192.168.1.64:5030/vm --header 'X-ONEGATE-VMID: 118' --header 'X-ONEGATE-TOKEN: pBSIH1Q33KmiMm7TYHW/2w=='
* Trying 192.168.1.64...
* Connected to 192.168.1.64 (192.168.1.64) port 5030 (#0)
> GET /vm HTTP/1.1
> Host: 192.168.1.64:5030
> User-Agent: curl/7.47.1
> Accept: */*
> X-ONEGATE-VMID: 118
> X-ONEGATE-TOKEN: pBSIH1Q33KmiMm7TYHW/2w==
> 
< HTTP/1.1 200 OK
< Content-Type: text/html;charset=utf-8
< Content-Length: 254
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< Connection: keep-alive
< Server: thin 1.3.1 codename Triple Espresso
< 
* Connection #0 to host 192.168.1.64 left intact
{"VM":{"NAME":"t1.micro-118","ID":"118","STATE":"3","LCM_STATE":"3","USER_TEMPLATE":{"EC2_INSTANCE_TYPE":"t1.micro","HYPERVISOR":"kvm","IMAGE_ID":"ami-00000043"},"TEMPLATE":{"NIC":[{"IP":"172.16.0.1","MAC":"02:00:ac:10:00:01","NETWORK":"private-net"}]}}}

```

Should I perhaps be using a different URL, instead of [http://XXX.XXX.XXX.XXX:5030/vm](http://XXX.XXX.XXX.XXX:5030/vm)?

---

<div class="post-metadata">

**Author:** ![dmolina](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/dmolina/32/22_2.png) [@dmolina](https://forum.opennebula.io/u/dmolina)\
**Post date:** [April 5, 2016, 8:56am UTC](https://forum.opennebula.io/t/retrieving-instance-metadata-from-within-the-instance/2044/4 "2016-04-05T08:56:30Z")

</div>

You are right. That information is stored in the VNET template and not in the VM template. If you want to retrieve this information you should extend the OneGate server to retrieve this information from the attached NICs.

---

<div class="post-metadata">

**Author:** ![carletes](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/carletes/32/4618_2.png) [@carletes](https://forum.opennebula.io/u/carletes)\
**Post date:** [April 5, 2016, 5:26pm UTC](https://forum.opennebula.io/t/retrieving-instance-metadata-from-within-the-instance/2044/5 "2016-04-05T17:26:43Z")

</div>

> […] you should extend the OneGate server to retrieve this information from the attached NICs.

Yep! What about adding to `TEMPLATE` a new field called `EC2_ADDRESSES`, for instance:

```
"TEMPLATE": {
    "NIC": [
        [..]
    },
    "EC2_ADDRESSES": [
        "192.168.1.42",
        [..]
    }
    [..]
}

```

I can start working on extending the OneGate server on a pull request on GitHub.

---

<div class="post-metadata">

**Author:** ![carletes](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/carletes/32/4618_2.png) [@carletes](https://forum.opennebula.io/u/carletes)\
**Post date:** [April 10, 2016, 3:25pm UTC](https://forum.opennebula.io/t/retrieving-instance-metadata-from-within-the-instance/2044/6 "2016-04-10T15:25:58Z")

</div>

> you should extend the OneGate server to retrieve this information from the attached NICs.

Here’s a first draft, @dmolina: [onegate-server: Return associated EC2 ElasticIPs by carletes · Pull Request #90 · OpenNebula/one · GitHub](https://github.com/OpenNebula/one/pull/90)

---

<div class="post-metadata">

**Author:** ![dmolina](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/dmolina/32/22_2.png) [@dmolina](https://forum.opennebula.io/u/dmolina)\
**Post date:** [April 11, 2016, 10:18am UTC](https://forum.opennebula.io/t/retrieving-instance-metadata-from-within-the-instance/2044/7 "2016-04-11T10:18:11Z")

</div>

Hi Carlos,

The pull request looks great, but since this is too EC2-specific, we think it would be better to integrate this functionality into the OpenNebula core and being able to use it from any of the interfaces. We will try to think about it and let you know if we find a solution for this.

Cheers

---

<div class="post-metadata">

**Author:** ![carletes](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/carletes/32/4618_2.png) [@carletes](https://forum.opennebula.io/u/carletes)\
**Post date:** [April 11, 2016, 12:35pm UTC](https://forum.opennebula.io/t/retrieving-instance-metadata-from-within-the-instance/2044/8 "2016-04-11T12:35:36Z")

</div>

Thanks, @dmolina! Looking forward to that, let me know whether I can be of any help.
