biome: 1.9.2 -> 1.9.3
[NixPkgs.git] / pkgs / tools / virtualization / cloud-init / 0001-add-nixos-support.patch
blob9389a045e38c9fce8e878a4c109f4a3bbbb01006
1 diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py
2 index 79e26235..bdc32c52 100644
3 --- a/cloudinit/distros/__init__.py
4 +++ b/cloudinit/distros/__init__.py
5 @@ -91,6 +91,7 @@ OSFAMILIES = {
6 ],
7 "openeuler": ["openeuler"],
8 "OpenCloudOS": ["OpenCloudOS", "TencentOS"],
9 + "nixos": ["nixos"],
12 LOG = logging.getLogger(__name__)
13 diff --git a/cloudinit/distros/nixos.py b/cloudinit/distros/nixos.py
14 new file mode 100644
15 index 00000000..67c049b8
16 --- /dev/null
17 +++ b/cloudinit/distros/nixos.py
18 @@ -0,0 +1,109 @@
19 +# vi: ts=4 expandtab
21 +# Copyright (C) 2012 Canonical Ltd.
22 +# Copyright (C) 2012 Hewlett-Packard Development Company, L.P.
23 +# Copyright (C) 2012 Yahoo! Inc.
25 +# Author: Scott Moser <scott.moser@canonical.com>
26 +# Author: Juerg Haefliger <juerg.haefliger@hp.com>
27 +# Author: Joshua Harlow <harlowja@yahoo-inc.com>
29 +# This program is free software: you can redistribute it and/or modify
30 +# it under the terms of the GNU General Public License version 3, as
31 +# published by the Free Software Foundation.
33 +# This program is distributed in the hope that it will be useful,
34 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
35 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 +# GNU General Public License for more details.
38 +# You should have received a copy of the GNU General Public License
39 +# along with this program. If not, see <http://www.gnu.org/licenses/>.
41 +import logging
42 +import os
44 +from cloudinit import distros
45 +from cloudinit import helpers
46 +from cloudinit import util
47 +from cloudinit import atomic_helper
49 +from cloudinit.distros.parsers.hostname import HostnameConf
50 +from cloudinit.net import dhcp
52 +LOG = logging.getLogger(__name__)
54 +class Distro(distros.Distro):
56 + def __init__(self, name, cfg, paths):
57 + distros.Distro.__init__(self, name, cfg, paths)
58 + # This will be used to restrict certain
59 + # calls from repeatly happening (when they
60 + # should only happen say once per instance...)
61 + self._runner = helpers.Runners(paths)
62 + self.usr_lib_exec = os.path.join(os.path.dirname(__file__),
63 + "../../../../../libexec")
64 + self.osfamily = 'nixos'
65 + self.dhcp_client_priority = [
66 + dhcp.Udhcpc,
67 + dhcp.IscDhclient,
68 + dhcp.Dhcpcd,
69 + ]
71 + def _select_hostname(self, hostname, fqdn):
72 + # Prefer the short hostname over the long
73 + # fully qualified domain name
74 + if not hostname:
75 + return fqdn
76 + return hostname
78 + def _write_hostname(self, your_hostname, out_fn):
79 + conf = None
80 + try:
81 + # Try to update the previous one
82 + # so lets see if we can read it first.
83 + conf = self._read_hostname_conf(out_fn)
84 + except IOError:
85 + pass
86 + if not conf:
87 + conf = HostnameConf('')
88 + conf.set_hostname(your_hostname)
89 + atomic_helper.write_file(out_fn, str(conf).encode("utf-8"))
91 + def _read_system_hostname(self):
92 + sys_hostname = self._read_hostname(self.hostname_conf_fn)
93 + return (self.hostname_conf_fn, sys_hostname)
95 + def _read_hostname_conf(self, filename):
96 + conf = HostnameConf(util.load_text_file(filename))
97 + conf.parse()
98 + return conf
100 + def _read_hostname(self, filename, default=None):
101 + hostname = None
102 + try:
103 + conf = self._read_hostname_conf(filename)
104 + hostname = conf.hostname
105 + except IOError:
106 + pass
107 + if not hostname:
108 + return default
109 + return hostname
111 + def _write_network(self, settings):
112 + raise NotImplementedError()
114 + def apply_locale(self, locale, out_fn=None):
115 + raise NotImplementedError()
117 + def install_packages(self, pkglist):
118 + raise NotImplementedError()
120 + def package_command(self, command, args=None, pkgs=None):
121 + pass
123 + def set_timezone(self, tz):
124 + pass
126 + def update_package_sources(self):
127 + pass