Skip to content

Commit 63edd85

Browse files
committed
Refactor network configuration.
This is based on a subset of Ubuntu's netplan and cloudinit. "network" (optional) Used to configure network in live/installed system. Set "version": "2" or the legacy config will be used, see below. The syntax roughly follows the cloud-init or netplan configuration, but not all options are supported. "hostname": set the host name. "ethernets": Settings for ethernet interfaces. Each interface has an 'id', which can be any name which may be refrenced for examplev for VLANs. Can be the interface name. Within any 'id': "match" : set a way to match this interface. Can be 'name' or 'macaddress'. "dhcp4" : set to "yes" or "no" "addresses" : a list of ip addresses (IPv4 or IPv6) with cidr netmask. "gateway" : the default gateway. "nameservers" : a dictionary with "addresses" containing a list of name servers, and "search" with a list of search domains. "vlans": Settings for VLAN interfaces. Similar to "ethernets" above, but with these additional required settings: "id" : the VLAN id (integer in the range 1..4094) "link" : the id of the ethernet interface to use, from the "ethernets" configured. Example: "network":{ "version": "2", "hostname" : "photon-machine", "ethernets": { "id0":{ "match":{ "name" : "eth0" }, "dhcp4" : "no", "addresses":[ "192.168.2.58/24" ], "gateway": "192.168.2.254", "nameservers":{ "addresses" : ["8.8.8.8", "8.8.4.4"], "search" : ["vmware.com", "eng.vmware.com"] } } }, "vlans": { "vlan0": { "id": 100, "link": "id0", "addresses":[ "192.168.100.58/24" ] } } } Change-Id: I544da79dba0c4285f1acf8d8315cdb1e9ec91783
1 parent 4aacf5a commit 63edd85

File tree

3 files changed

+505
-199
lines changed

3 files changed

+505
-199
lines changed

photon_installer/installer.py

+20-19
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def execute(self):
165165
else:
166166
self._install()
167167

168+
168169
def _fill_dynamic_conf(self, install_config):
169170
if isinstance(install_config, abc.Mapping) or isinstance(install_config, list):
170171
for key, value in install_config.items():
@@ -183,12 +184,13 @@ def _fill_dynamic_conf(self, install_config):
183184
\n Please export dynamic values in preinstall script in ks file as below: \
184185
\n export {}=\"<my-val>\"".format(value,key,value[1:]))
185186

187+
186188
def _load_preinstall(self, install_config):
187-
if 'preinstall' in install_config or 'preinstallscripts' in install_config:
188-
self.install_config = install_config
189-
self._execute_modules(modules.commons.PRE_INSTALL)
190-
for fill_values in self._fill_dynamic_conf(install_config):
191-
print(fill_values)
189+
self.install_config = install_config
190+
self._execute_modules(modules.commons.PRE_INSTALL)
191+
for fill_values in self._fill_dynamic_conf(install_config):
192+
print(fill_values)
193+
192194

193195
def _add_defaults(self, install_config):
194196
"""
@@ -231,10 +233,11 @@ def _add_defaults(self, install_config):
231233
else:
232234
install_config['packages'] = packages
233235

234-
# live means online system. When you create an image for
235-
# target system, live should be set to false.
236+
# live means online system, and it's True be default. When you create an image for
237+
# target system, live should be set to False.
236238
if 'live' not in install_config:
237-
install_config['live'] = 'loop' not in install_config['disk']
239+
if 'loop' in install_config['disk']:
240+
install_config['live'] = False
238241

239242
# default partition
240243
if 'partitions' not in install_config:
@@ -422,7 +425,7 @@ def _install(self, stdscreen=None):
422425
if self.interactive:
423426
self.window.content_window().getch()
424427

425-
if self.install_config['live']:
428+
if self.install_config.get('live', True):
426429
self._eject_cdrom()
427430

428431
def _unsafe_install(self):
@@ -471,25 +474,23 @@ def exit_gracefully(self, signal1=None, frame1=None):
471474
self._unmount_all()
472475
raise Exception("Installer failed")
473476

477+
474478
def _setup_network(self):
475479
if 'network' not in self.install_config:
476480
return
481+
477482
# setup network config files in chroot
478-
nm = NetworkManager(self.install_config, self.photon_root)
483+
nm = NetworkManager(self.install_config['network'], self.photon_root)
479484
if not nm.setup_network():
480485
self.logger.error("Failed to setup network!")
481486
self.exit_gracefully()
487+
nm.set_perms()
482488

483-
# Configure network when in live mode (ISO) and when network is not
484-
# already configured (typically in KS flow).
485-
if ('live' in self.install_config and
486-
'conf_files' not in self.install_config['network']):
487-
nm = NetworkManager(self.install_config)
488-
if not nm.setup_network():
489-
self.logger.error("Failed to setup network in ISO system")
490-
self.exit_gracefully()
489+
# Configure network when in live mode (ISO)
490+
if (self.install_config.get('live', True)):
491491
nm.restart_networkd()
492492

493+
493494
def _unmount_all(self):
494495
"""
495496
Unmount partitions and special folders
@@ -811,7 +812,7 @@ def _setup_grub(self):
811812
grub_cfg.write("set prefix=($root){}grub2\n".format(self.install_config['partitions_data']['bootdirectory']))
812813
grub_cfg.write("configfile {}grub2/grub.cfg\n".format(self.install_config['partitions_data']['bootdirectory']))
813814

814-
if self.install_config['live']:
815+
if self.install_config.get('live', True):
815816
arch = self.install_config['arch']
816817
# 'x86_64' -> 'bootx64.efi', 'aarch64' -> 'bootaa64.efi'
817818
exe_name = 'boot'+arch[:-5]+arch[-2:]+'.efi'

photon_installer/ks_config.txt

+73-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,79 @@ Kickstart config file is a json format with following possible parameters:
238238
}
239239

240240
"network" (optional)
241-
Used to configure network in live/installed system.
241+
Used to configure network in live/installed system.
242+
243+
Set "version": "2" or the legacy config will be used, see below.
244+
245+
The syntax roughly follows the cloud-init or netplan configuration,
246+
but not all options are supported.
247+
248+
"hostname": set the host name.
249+
250+
"ethernets": Settings for ethernet interfaces. Each interface has an 'id',
251+
which can be any name which may be refrenced for examplev for VLANs. Can
252+
be the interface name.
253+
254+
Within any 'id':
255+
256+
"match" : set a way to match this interface. Can be 'name' or 'macaddress'.
257+
258+
"dhcp4" : boolean, set to true or false
259+
260+
"dhcp6" : boolean, set to true or false
261+
262+
"accept-ra" : boolean, set to true or false. Whether to accept
263+
Router Advertisement for IPv6.
264+
265+
"addresses" : a list of ip addresses (IPv4 or IPv6) with cidr netmask.
266+
267+
"gateway" : the default gateway.
268+
269+
"nameservers" : a dictionary with "addresses" containing a list of name servers,
270+
and "search" with a list of search domains.
271+
272+
"vlans": Settings for VLAN interfaces. Similar to "ethernets" above,
273+
but with these additional required settings:
274+
275+
"id" : the VLAN id (integer in the range 1..4094)
276+
277+
"link" : the id of the ethernet interface to use, from the "ethernets"
278+
configured.
279+
280+
Example:
281+
282+
"network":{
283+
"version": "2",
284+
"hostname" : "photon-machine",
285+
"ethernets": {
286+
"id0":{
287+
"match":{
288+
"name" : "eth0"
289+
},
290+
"dhcp4" : false,
291+
"addresses":[
292+
"192.168.2.58/24"
293+
],
294+
"gateway": "192.168.2.254",
295+
"nameservers":{
296+
"addresses" : ["8.8.8.8", "8.8.4.4"],
297+
"search" : ["vmware.com", "eng.vmware.com"]
298+
}
299+
}
300+
},
301+
"vlans": {
302+
"vlan0": {
303+
"id": 100,
304+
"link": "id0",
305+
"addresses":[
306+
"192.168.100.58/24"
307+
]
308+
}
309+
}
310+
}
311+
312+
Legacy network configuration:
313+
242314
"type" (required)
243315
String; must be one of dhcp/static/vlan. Indicates how the network
244316
is being configured.

0 commit comments

Comments
 (0)