Skip to content

Commit e5a97d7

Browse files
committed
nocloud: add configurable meta/user data paths
In some cases, the NoCloud config drive is built using `_` instead of `-` characters for the metadata and userdata paths. This commit adds two configuration options to be able to set custom values to those paths: ```ini [nocloud] metadata_file = "meta-data" userdata_file = "user-data" ``` Fixes: #89 Change-Id: I312aa26ed9be6f22156ac238f456c3906d93760d Signed-off-by: Adrian Vladu <avladu@cloudbasesolutions.com>
1 parent 04c6424 commit e5a97d7

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
@@ -276,17 +276,19 @@ class NoCloudConfigDriveService(baseconfigdrive.BaseConfigDriveService):
276276

277277
def __init__(self):
278278
super(NoCloudConfigDriveService, self).__init__(
279-
'cidata', 'meta-data')
279+
'cidata', CONF.nocloud.metadata_file,
280+
CONF.nocloud.userdata_file)
280281
self._meta_data = {}
281282

282283
def get_user_data(self):
283-
return self._get_cache_data("user-data")
284+
return self._get_cache_data(self._userdata_file)
284285

285286
def _get_meta_data(self):
286287
if self._meta_data:
287288
return self._meta_data
288289

289-
raw_meta_data = self._get_cache_data("meta-data", decode=True)
290+
raw_meta_data = self._get_cache_data(
291+
self._metadata_file, decode=True)
290292
try:
291293
self._meta_data = (
292294
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)