Skip to content

Commit

Permalink
Refactor network configuration.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
oliverkurth committed Feb 16, 2023
1 parent 4aacf5a commit 63edd85
Show file tree
Hide file tree
Showing 3 changed files with 505 additions and 199 deletions.
39 changes: 20 additions & 19 deletions photon_installer/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def execute(self):
else:
self._install()


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


def _load_preinstall(self, install_config):
if 'preinstall' in install_config or 'preinstallscripts' in install_config:
self.install_config = install_config
self._execute_modules(modules.commons.PRE_INSTALL)
for fill_values in self._fill_dynamic_conf(install_config):
print(fill_values)
self.install_config = install_config
self._execute_modules(modules.commons.PRE_INSTALL)
for fill_values in self._fill_dynamic_conf(install_config):
print(fill_values)


def _add_defaults(self, install_config):
"""
Expand Down Expand Up @@ -231,10 +233,11 @@ def _add_defaults(self, install_config):
else:
install_config['packages'] = packages

# live means online system. When you create an image for
# target system, live should be set to false.
# live means online system, and it's True be default. When you create an image for
# target system, live should be set to False.
if 'live' not in install_config:
install_config['live'] = 'loop' not in install_config['disk']
if 'loop' in install_config['disk']:
install_config['live'] = False

# default partition
if 'partitions' not in install_config:
Expand Down Expand Up @@ -422,7 +425,7 @@ def _install(self, stdscreen=None):
if self.interactive:
self.window.content_window().getch()

if self.install_config['live']:
if self.install_config.get('live', True):
self._eject_cdrom()

def _unsafe_install(self):
Expand Down Expand Up @@ -471,25 +474,23 @@ def exit_gracefully(self, signal1=None, frame1=None):
self._unmount_all()
raise Exception("Installer failed")


def _setup_network(self):
if 'network' not in self.install_config:
return

# setup network config files in chroot
nm = NetworkManager(self.install_config, self.photon_root)
nm = NetworkManager(self.install_config['network'], self.photon_root)
if not nm.setup_network():
self.logger.error("Failed to setup network!")
self.exit_gracefully()
nm.set_perms()

# Configure network when in live mode (ISO) and when network is not
# already configured (typically in KS flow).
if ('live' in self.install_config and
'conf_files' not in self.install_config['network']):
nm = NetworkManager(self.install_config)
if not nm.setup_network():
self.logger.error("Failed to setup network in ISO system")
self.exit_gracefully()
# Configure network when in live mode (ISO)
if (self.install_config.get('live', True)):
nm.restart_networkd()


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

if self.install_config['live']:
if self.install_config.get('live', True):
arch = self.install_config['arch']
# 'x86_64' -> 'bootx64.efi', 'aarch64' -> 'bootaa64.efi'
exe_name = 'boot'+arch[:-5]+arch[-2:]+'.efi'
Expand Down
74 changes: 73 additions & 1 deletion photon_installer/ks_config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,79 @@ Kickstart config file is a json format with following possible parameters:
}

"network" (optional)
Used to configure network in live/installed system.
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" : boolean, set to true or false

"dhcp6" : boolean, set to true or false

"accept-ra" : boolean, set to true or false. Whether to accept
Router Advertisement for IPv6.

"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" : false,
"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"
]
}
}
}

Legacy network configuration:

"type" (required)
String; must be one of dhcp/static/vlan. Indicates how the network
is being configured.
Expand Down
Loading

0 comments on commit 63edd85

Please sign in to comment.