HTTP metadata service support
This commit is contained in:
@@ -15,12 +15,14 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from cloudbaseinit.openstack.common import cfg
|
from cloudbaseinit.openstack.common import cfg
|
||||||
|
from cloudbaseinit.openstack.common import log as logging
|
||||||
from cloudbaseinit.utils import *
|
from cloudbaseinit.utils import *
|
||||||
|
|
||||||
opts = [
|
opts = [
|
||||||
cfg.ListOpt('metadata_services', default=[
|
cfg.ListOpt('metadata_services', default=[
|
||||||
'cloudbaseinit.metadata.services.configdrive.configdrive.'
|
'cloudbaseinit.metadata.services.configdrive.configdrive.'
|
||||||
'ConfigDriveService'
|
'ConfigDriveService',
|
||||||
|
'cloudbaseinit.metadata.services.httpservice.HttpService',
|
||||||
],
|
],
|
||||||
help='List of enabled metadata service classes, '
|
help='List of enabled metadata service classes, '
|
||||||
'to be tested fro availability in the provided order. '
|
'to be tested fro availability in the provided order. '
|
||||||
@@ -29,6 +31,7 @@ opts = [
|
|||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
CONF.register_opts(opts)
|
CONF.register_opts(opts)
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class MetadataServiceFactory(object):
|
class MetadataServiceFactory(object):
|
||||||
@@ -37,6 +40,11 @@ class MetadataServiceFactory(object):
|
|||||||
utils = Utils()
|
utils = Utils()
|
||||||
for class_path in CONF.metadata_services:
|
for class_path in CONF.metadata_services:
|
||||||
service = utils.load_class(class_path)()
|
service = utils.load_class(class_path)()
|
||||||
if service.load():
|
try:
|
||||||
return service
|
if service.load():
|
||||||
|
return service
|
||||||
|
except Exception, ex:
|
||||||
|
LOG.error('Failed to load metadata service \'%(class_path)s\' '
|
||||||
|
'with error: %(ex)s'%
|
||||||
|
locals())
|
||||||
raise Exception("No available service found")
|
raise Exception("No available service found")
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class ConfigDriveManager(object):
|
|||||||
q1 = conn.query('SELECT Label FROM Win32_Volume WHERE Name = \'%(drive)s\'' % locals())
|
q1 = conn.query('SELECT Label FROM Win32_Volume WHERE Name = \'%(drive)s\'' % locals())
|
||||||
for r1 in q1:
|
for r1 in q1:
|
||||||
if r1.Label == "config-2" and \
|
if r1.Label == "config-2" and \
|
||||||
os.path.exists(os.path.join(drive, 'openstack\\latest\meta_data.json')):
|
os.path.exists(os.path.join(drive, 'openstack\\latest\\meta_data.json')):
|
||||||
return drive
|
return drive
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
50
cloudbaseinit/metadata/services/httpservice.py
Normal file
50
cloudbaseinit/metadata/services/httpservice.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
|
# Copyright 2012 Cloudbase Solutions Srl
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import posixpath
|
||||||
|
import urllib2
|
||||||
|
|
||||||
|
from cloudbaseinit.metadata.services.base import *
|
||||||
|
from cloudbaseinit.openstack.common import cfg
|
||||||
|
|
||||||
|
opts = [
|
||||||
|
cfg.StrOpt('metadata_base_url', default='http://169.254.169.254/',
|
||||||
|
help='The base URL where the service looks for metadata'),
|
||||||
|
]
|
||||||
|
|
||||||
|
CONF = cfg.CONF
|
||||||
|
CONF.register_opts(opts)
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class HttpService(BaseMetadataService):
|
||||||
|
def load(self):
|
||||||
|
super(HttpService, self).load()
|
||||||
|
try:
|
||||||
|
self.get_meta_data('openstack')
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
LOG.debug('Metadata not found at URL \'%s\'' %
|
||||||
|
CONF.metadata_base_url)
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _get_data(self, path):
|
||||||
|
norm_path = posixpath.join(CONF.metadata_base_url, path)
|
||||||
|
LOG.debug('Getting metadata from: %(norm_path)s' % locals())
|
||||||
|
req = urllib2.Request(norm_path)
|
||||||
|
response = urllib2.urlopen(req)
|
||||||
|
return response.read()
|
||||||
Reference in New Issue
Block a user