
The Oslo libraries have moved all of their code out of the 'oslo' namespace package into per-library packages. The namespace package was retained during kilo for backwards compatibility, but will be removed by the liberty-2 milestone. This change removes the use of the namespace package, replacing it with the new package names. The patches in the libraries will be put on hold until application patches have landed, or L2, whichever comes first. At that point, new versions of the libraries without namespace packages will be released as a major version update. Please merge this patch, or an equivalent, before L2 to avoid problems with those library releases. Blueprint: remove-namespace-packages https://blueprints.launchpad.net/oslo-incubator/+spec/remove-namespace-packages Change-Id: If51059c31c82d5235e2ae21143911b5561783ca6
61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
from oslo_config import cfg
|
|
|
|
from os_collect_config import common
|
|
from os_collect_config import exc
|
|
from os_collect_config.openstack.common import log
|
|
|
|
EC2_METADATA_URL = 'http://169.254.169.254/latest/meta-data'
|
|
CONF = cfg.CONF
|
|
|
|
opts = [
|
|
cfg.StrOpt('metadata-url',
|
|
default=EC2_METADATA_URL,
|
|
help='URL to query for EC2 Metadata')
|
|
]
|
|
name = 'ec2'
|
|
|
|
|
|
class Collector(object):
|
|
def __init__(self, requests_impl=common.requests):
|
|
self._requests_impl = requests_impl
|
|
self.session = requests_impl.Session()
|
|
|
|
def _fetch_metadata(self, fetch_url):
|
|
try:
|
|
r = self.session.get(fetch_url)
|
|
r.raise_for_status()
|
|
except self._requests_impl.exceptions.RequestException as e:
|
|
log.getLogger(__name__).warn(e)
|
|
raise exc.Ec2MetadataNotAvailable
|
|
content = r.text
|
|
if fetch_url[-1] == '/':
|
|
new_content = {}
|
|
for subkey in content.split("\n"):
|
|
if '=' in subkey:
|
|
subkey = subkey[:subkey.index('=')] + '/'
|
|
sub_fetch_url = fetch_url + subkey
|
|
if subkey[-1] == '/':
|
|
subkey = subkey[:-1]
|
|
new_content[subkey] = self._fetch_metadata(sub_fetch_url)
|
|
content = new_content
|
|
return content
|
|
|
|
def collect(self):
|
|
root_url = '%s/' % (CONF.ec2.metadata_url)
|
|
return [('ec2', self._fetch_metadata(root_url))]
|