fastcloudinit 0.0.2__tar.gz → 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcloudinit
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Simplified opinionated cloud init for ubuntu
5
5
  Home-page: https://github.com/AnswerDotAI/fastcloudinit
6
6
  Author: Jeremy Howard
@@ -0,0 +1,2 @@
1
+ __version__ = "0.0.3"
2
+ from .core import *
@@ -12,6 +12,7 @@ d = { 'settings': { 'branch': 'main',
12
12
  'fastcloudinit.core.mounts': ('core.html#mounts', 'fastcloudinit/core.py'),
13
13
  'fastcloudinit.core.phone_home': ('core.html#phone_home', 'fastcloudinit/core.py'),
14
14
  'fastcloudinit.core.reboot': ('core.html#reboot', 'fastcloudinit/core.py'),
15
+ 'fastcloudinit.core.runcmd': ('core.html#runcmd', 'fastcloudinit/core.py'),
15
16
  'fastcloudinit.core.source': ('core.html#source', 'fastcloudinit/core.py'),
16
17
  'fastcloudinit.core.systemd': ('core.html#systemd', 'fastcloudinit/core.py'),
17
18
  'fastcloudinit.core.ufw': ('core.html#ufw', 'fastcloudinit/core.py'),
@@ -1,8 +1,8 @@
1
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_core.ipynb.
2
2
 
3
3
  # %% auto 0
4
- __all__ = ['ufw', 'user', 'source', 'apt', 'systemd', 'log_rotate', 'phone_home', 'reboot', 'mounts', 'cloud_init_config',
5
- 'cloud_init_base']
4
+ __all__ = ['ufw', 'user', 'source', 'apt', 'systemd', 'log_rotate', 'phone_home', 'reboot', 'mounts', 'runcmd', 'cloud_init_base',
5
+ 'cloud_init_config']
6
6
 
7
7
  # %% ../nbs/00_core.ipynb
8
8
  from fastcore.utils import *
@@ -11,11 +11,11 @@ from textwrap import dedent
11
11
 
12
12
  # %% ../nbs/00_core.ipynb
13
13
  def ufw(logging="off", def_incoming="deny", def_outgoing="allow", internal=None, **allows):
14
- rules = [dict(name=k, rule="allow", port=v) for k,v in allows.items()]
15
- if internal: rules.append(dict(interface=internal, rule="allow", direction="in"))
16
- defaults=dict(incoming=def_incoming, outgoing=def_outgoing)
17
- res = dict(enabled=True, logging=logging, defaults=defaults, rules=rules)
18
- return dict(ufw=res)
14
+ cmds = [ f"ufw default {def_incoming} incoming", f"ufw default {def_outgoing} outgoing", f"ufw logging {logging}" ]
15
+ for name, port in allows.items(): cmds.append("ufw allow {}/tcp".format(port))
16
+ if internal: cmds.append("ufw allow in on {}".format(internal))
17
+ cmds.append("ufw --force enable")
18
+ return cmds
19
19
 
20
20
  # %% ../nbs/00_core.ipynb
21
21
  def user(name, pub_keys, groups=None, shell="/bin/bash", sudo=True):
@@ -46,8 +46,11 @@ Unattended-Upgrade::Automatic-Reboot "{auto_reboot}";
46
46
 
47
47
  # %% ../nbs/00_core.ipynb
48
48
  def systemd(items):
49
- units = [dict(name=k, dropin=True, content=v) for k,v in items.items()]
50
- return dict(systemd=dict(units=units))
49
+ return [
50
+ {'path': f"/etc/systemd/system/{unit_name}.d/override.conf",
51
+ 'owner': 'root:root', 'permissions': '0644', 'content': content}
52
+ for unit_name, content in items.items()
53
+ ]
51
54
 
52
55
  # %% ../nbs/00_core.ipynb
53
56
  def log_rotate(freq="weekly", num_keep=7, fname="00-cloud-init-global"):
@@ -80,23 +83,9 @@ def mounts(devices):
80
83
  return dict(mounts=devices)
81
84
 
82
85
  # %% ../nbs/00_core.ipynb
83
- def cloud_init_config(hostname, username, pub_keys, email='',
84
- devices=None, ping_host=None, packages=None, dropins=None, **sources):
85
- if not dropins: dropins={}
86
- cfg = dict(
87
- hostname=hostname, preserve_hostname=False,
88
- users=[user(username, pub_keys, groups="docker")],
89
- packages=listify(packages), package_update=True, package_upgrade=True,
90
- disable_root=True, ssh_pwauth=False,
91
- **ufw(internal="enp7s0", OpenSSH=22),
92
- **apt(**sources),
93
- **systemd(dropins),
94
- write_files=[ log_rotate() ],
95
- **mounts(devices),
96
- **phone_home(ping_host),
97
- **reboot(),
98
- )
99
- return "#cloud-config\n" + yaml.safe_dump(cfg, sort_keys=False, width=1_000_000)
86
+ def runcmd(cmds):
87
+ if not cmds: return {}
88
+ return dict(runcmd=cmds)
100
89
 
101
90
  # %% ../nbs/00_core.ipynb
102
91
  def cloud_init_base(hostname, packages=None, **kw):
@@ -108,15 +97,16 @@ def cloud_init_base(hostname, packages=None, **kw):
108
97
  return "#cloud-config\n" + yaml.safe_dump(cfg, sort_keys=False, width=1_000_000)
109
98
 
110
99
  # %% ../nbs/00_core.ipynb
111
- def cloud_init_config(hostname, username, pub_keys, email='', groups=None, internal=None,
100
+ def cloud_init_config(hostname, username, pub_keys, email='', groups=None, internal=None, cmds=None,
112
101
  devices=None, ping_host=None, packages=None, dropins=None, **sources):
102
+ cmds = listify(cmds)
103
+ cmds += ufw(internal=internal, OpenSSH=22)
113
104
  return cloud_init_base(
114
105
  hostname, packages=packages,
115
106
  users=[user(username, pub_keys, groups=groups)],
116
- **ufw(internal=internal, OpenSSH=22),
107
+ **runcmd(cmds),
117
108
  **apt(**sources),
118
- **systemd(dropins or {}),
119
- write_files=[ log_rotate() ],
109
+ write_files=[ log_rotate(), *systemd(dropins or {}) ],
120
110
  **mounts(devices),
121
111
  **phone_home(ping_host),
122
112
  **reboot(),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcloudinit
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Simplified opinionated cloud init for ubuntu
5
5
  Home-page: https://github.com/AnswerDotAI/fastcloudinit
6
6
  Author: Jeremy Howard
@@ -1,7 +1,7 @@
1
1
  [DEFAULT]
2
2
  repo = fastcloudinit
3
3
  lib_name = fastcloudinit
4
- version = 0.0.2
4
+ version = 0.0.3
5
5
  min_python = 3.9
6
6
  license = apache2
7
7
  black_formatting = False
@@ -1,2 +0,0 @@
1
- __version__ = "0.0.2"
2
- from .core import *
File without changes
File without changes
File without changes
File without changes
File without changes