Skip to content

Commit 96376a5

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "nocloud: add configurable meta/user data paths"
2 parents 2c2bb5e + e5a97d7 commit 96376a5

5 files changed

Lines changed: 64 additions & 5 deletions

File tree

cloudbaseinit/conf/factory.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'cloudbaseinit.conf.packet.PacketOptions',
2727
'cloudbaseinit.conf.vmwareguestinfo.VMwareGuestInfoConfigOptions',
2828
'cloudbaseinit.conf.gce.GCEOptions',
29+
'cloudbaseinit.conf.nocloud.NoCloudOptions',
2930
)
3031

3132

cloudbaseinit/conf/nocloud.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright 2024 Cloudbase Solutions Srl
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
"""Config options available for the OpenStack metadata service."""
16+
17+
from oslo_config import cfg
18+
19+
from cloudbaseinit.conf import base as conf_base
20+
21+
22+
class NoCloudOptions(conf_base.Options):
23+
24+
"""Config options available for the OpenStack metadata service."""
25+
26+
def __init__(self, config):
27+
super(NoCloudOptions, self).__init__(config, group="nocloud")
28+
self._options = [
29+
cfg.StrOpt(
30+
"metadata_file", default="meta-data",
31+
help="The file name where the service looks for"
32+
"metadata"),
33+
cfg.StrOpt(
34+
"userdata_file", default="user-data",
35+
help="The file name where the service looks for"
36+
"userdata"),
37+
]
38+
39+
def register(self):
40+
"""Register the current options to the global ConfigOpts object."""
41+
group = cfg.OptGroup(self.group_name, title='NoCloud Options')
42+
self._config.register_group(group)
43+
self._config.register_opts(self._options, group=group)
44+
45+
def list(self):
46+
"""Return a list which contains all the available options."""
47+
return self._options

cloudbaseinit/metadata/services/baseconfigdrive.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232

3333
class BaseConfigDriveService(base.BaseMetadataService):
3434

35-
def __init__(self, drive_label, metadata_file):
35+
def __init__(self, drive_label, metadata_file,
36+
userdata_file='user-data'):
3637
super(BaseConfigDriveService, self).__init__()
3738
self._drive_label = drive_label
3839
self._metadata_file = metadata_file
40+
self._userdata_file = userdata_file
3941
self._metadata_path = None
4042
self._searched_types = set()
4143
self._searched_locations = set()

cloudbaseinit/metadata/services/nocloudservice.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,17 +541,19 @@ class NoCloudConfigDriveService(baseconfigdrive.BaseConfigDriveService):
541541

542542
def __init__(self):
543543
super(NoCloudConfigDriveService, self).__init__(
544-
'cidata', 'meta-data')
544+
'cidata', CONF.nocloud.metadata_file,
545+
CONF.nocloud.userdata_file)
545546
self._meta_data = {}
546547

547548
def get_user_data(self):
548-
return self._get_cache_data("user-data")
549+
return self._get_cache_data(self._userdata_file)
549550

550551
def _get_meta_data(self):
551552
if self._meta_data:
552553
return self._meta_data
553554

554-
raw_meta_data = self._get_cache_data("meta-data", decode=True)
555+
raw_meta_data = self._get_cache_data(
556+
self._metadata_file, decode=True)
555557
try:
556558
self._meta_data = (
557559
serialization.parse_json_yaml(raw_meta_data))

doc/source/services.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,15 @@ similar to the EC2 metadata in terms of how the metadata files are named and str
128128

129129
The metadata is provided on a config-drive (vfat or iso9660) with the label cidata or CIDATA.
130130

131-
The folder structure for NoCloud is:
131+
The default folder structure for NoCloud is:
132132

133133
* /user-data
134134
* /meta-data
135135

136136
The user-data and meta-data files respect the EC2 metadata service format.
137137

138+
The names of the meta-data and user-data files can be configured.
139+
138140
Capabilities:
139141

140142
* instance id
@@ -153,6 +155,11 @@ Config options for `config_drive` section:
153155
* types (list: ["vfat", "iso"])
154156
* locations (list: ["cdrom", "hdd", "partition"])
155157

158+
Config options for `nocloud` section:
159+
160+
* metadata_file (string: "meta-data")
161+
* userdata_file (string: "user-data")
162+
156163
Example metadata:
157164

158165
.. code-block:: yaml

0 commit comments

Comments
 (0)