|
@@ -3,8 +3,6 @@
|
3
|
3
|
from __future__ import print_function
|
4
|
4
|
|
5
|
5
|
import argparse
|
6
|
|
-#import fs
|
7
|
|
-#from fs import tempfs, path
|
8
|
6
|
import fs.tempfs
|
9
|
7
|
import fs.path
|
10
|
8
|
import ipaddress
|
|
@@ -131,7 +129,6 @@ class ConfigDrive:
|
131
|
129
|
if dir_path and not self._tmpfs.exists(dir_path):
|
132
|
130
|
self._tmpfs.makedirs(dir_path)
|
133
|
131
|
|
134
|
|
-
|
135
|
132
|
self._tmpfs.settext(path, content)
|
136
|
133
|
if self._verbose:
|
137
|
134
|
print(" >>", path)
|
|
@@ -151,10 +148,10 @@ class ConfigDrive:
|
151
|
148
|
"files": [],
|
152
|
149
|
"hostname": self._hostname,
|
153
|
150
|
"name": self._hostname.split(".")[0],
|
154
|
|
- #"meta": {
|
155
|
|
- # "role": "webservers",
|
156
|
|
- # "essential": False,
|
157
|
|
- #}
|
|
151
|
+ # "meta": {
|
|
152
|
+ # "role": "webservers",
|
|
153
|
+ # "essential": False,
|
|
154
|
+ # }
|
158
|
155
|
"uuid": str(uuid.uuid4()),
|
159
|
156
|
}
|
160
|
157
|
|
|
@@ -169,12 +166,14 @@ class ConfigDrive:
|
169
|
166
|
meta_data["files"].append({"content_path": "/content/0000", "path": "/etc/network/interfaces"})
|
170
|
167
|
self.add_text("/openstack/content/0000", "\n".join(self._interfaces))
|
171
|
168
|
|
172
|
|
- meta_data["files"].append({"content_path": "/content/0001", "path": "/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg"})
|
|
169
|
+ meta_data["files"].append({"content_path": "/content/0001",
|
|
170
|
+ "path": "/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg"})
|
173
|
171
|
self.add_text("/openstack/content/0001", "network: {config: disabled}")
|
174
|
172
|
|
175
|
173
|
# do not look for datasource on every boot
|
176
|
174
|
if self._clean_metadata:
|
177
|
|
- meta_data["files"].append({"content_path": "/content/0002", "path": "/etc/cloud/cloud.cfg.d/99-manual-cache-clean.cfg"})
|
|
175
|
+ meta_data["files"].append({"content_path": "/content/0002",
|
|
176
|
+ "path": "/etc/cloud/cloud.cfg.d/99-manual-cache-clean.cfg"})
|
178
|
177
|
self.add_text("/openstack/content/0002", "manual_cache_clean: True")
|
179
|
178
|
|
180
|
179
|
if self._pubkeys:
|
|
@@ -202,9 +201,9 @@ class ConfigDrive:
|
202
|
201
|
if "chpasswd" not in self._user_data:
|
203
|
202
|
self._user_data["chpasswd"] = {}
|
204
|
203
|
self._user_data["chpasswd"]["list"] = ""
|
205
|
|
- #self._user_data["chpasswd"]["list"] = []
|
|
204
|
+ # self._user_data["chpasswd"]["list"] = []
|
206
|
205
|
|
207
|
|
- #self._user_data["chpasswd"]["list"].append("%s:%s" % (user, password))
|
|
206
|
+ # self._user_data["chpasswd"]["list"].append("%s:%s" % (user, password))
|
208
|
207
|
self._user_data["chpasswd"]["list"] += "%s:%s\n" % (user, password)
|
209
|
208
|
|
210
|
209
|
def _write_userdata(self):
|
|
@@ -250,7 +249,8 @@ class ConfigDrive:
|
250
|
249
|
# cfgdrv.add_command("rm -rf /home/debian/; userdel debian; groupdel debian", True)
|
251
|
250
|
# cfgdrv.add_command("cloud-init single --name cc_resolv_conf", True)
|
252
|
251
|
# cfgdrv.add_command("rm -f /etc/network/interfaces.d/eth*.cfg", True)
|
253
|
|
-# cfgdrv.add_command("sed -rni '/^([^#]|## template)/p' /etc/cloud/templates/sources.list.*.tmpl; rm /etc/apt/sources.list.d/*", True)
|
|
252
|
+# cfgdrv.add_command("sed -rni '/^([^#]|## template)/p' /etc/cloud/templates/sources.list.*.tmpl; "
|
|
253
|
+# "rm /etc/apt/sources.list.d/*", True)
|
254
|
254
|
# #cfgdrv.add_command("(whoami; date) > /root/bleep", False)
|
255
|
255
|
# cfgdrv.add_pubkey("ssh-rsa bleep foo")
|
256
|
256
|
# cfgdrv.set_password("root", "kitteh")
|
|
@@ -262,13 +262,17 @@ def main():
|
262
|
262
|
parser.add_argument("-H", "--hostname", required=True, help="Hostname")
|
263
|
263
|
parser.add_argument("-o", "--output", required=True, help="Path to write iso to")
|
264
|
264
|
parser.add_argument("-n", "--nameservers", "--ns", default=["1.1.1.1", "8.8.8.8"], nargs="+", help="Nameservers")
|
265
|
|
- parser.add_argument("-i", "--networks", "--net", default=[], nargs="+", help="Specify all networks, in format of interface[:address:[gateway]]. Both : and ; can be used as delimiter (but only one per net config). Address MUST be a network in CIDR notation")
|
|
265
|
+ parser.add_argument("-i", "--networks", "--net", default=[], nargs="+",
|
|
266
|
+ help="Specify all networks, in format of interface[:address:[gateway]]. "
|
|
267
|
+ "Both : and ; can be used as delimiter (but only one per net config). "
|
|
268
|
+ "Address MUST be a network in CIDR notation")
|
266
|
269
|
parser.add_argument("-u", "--disable-upgrades", action="store_true", default=False)
|
267
|
270
|
parser.add_argument("-v", "--verbose", action="store_true", default=False)
|
268
|
271
|
parser.add_argument("--no-debian-cleanup", "--ndc", action="store_true", default=False)
|
269
|
272
|
parser.add_argument("--set-root-password", "--srp", default=None)
|
270
|
|
- parser.add_argument("-a", "--add-user", default=[], nargs="+", help="Add users, format is username:key?:sudo?:gecos?:password?, sudo is a bool, key is either an ssh key or a path to an ssh key")
|
271
|
|
-
|
|
273
|
+ parser.add_argument("-a", "--add-user", default=[], nargs="+",
|
|
274
|
+ help="Add users, format is username:key?:sudo?:gecos?:password?, "
|
|
275
|
+ "sudo is a bool, key is either an ssh key or a path to an ssh key")
|
272
|
276
|
|
273
|
277
|
args = parser.parse_args()
|
274
|
278
|
|
|
@@ -298,9 +302,10 @@ def main():
|
298
|
302
|
|
299
|
303
|
if not args.no_debian_cleanup:
|
300
|
304
|
cfgdrv.add_command("rm -f /etc/network/interfaces.d/eth*", True)
|
301
|
|
- cfgdrv.add_command("sed -rni '/^([^#]|## template)/p' /etc/cloud/templates/sources.list.*.tmpl; rm /etc/apt/sources.list.d/*", True)
|
302
|
|
- cfgdrv.add_command("sed -rni '/^([^#]|## template)/p' /etc/resolv.conf /etc/cloud/templates/resolv.conf.tmpl", True)
|
303
|
|
-
|
|
305
|
+ cfgdrv.add_command("sed -rni '/^([^#]|## template)/p' /etc/cloud/templates/sources.list.*.tmpl; "
|
|
306
|
+ "rm /etc/apt/sources.list.d/*", True)
|
|
307
|
+ cfgdrv.add_command("sed -rni '/^([^#]|## template)/p' "
|
|
308
|
+ "/etc/resolv.conf /etc/cloud/templates/resolv.conf.tmpl", True)
|
304
|
309
|
|
305
|
310
|
if args.set_root_password:
|
306
|
311
|
cfgdrv.set_password("root", args.set_root_password)
|
|
@@ -339,5 +344,6 @@ def main():
|
339
|
344
|
if cfgdrv:
|
340
|
345
|
cfgdrv.close()
|
341
|
346
|
|
|
347
|
+
|
342
|
348
|
if __name__ == '__main__':
|
343
|
349
|
main()
|