fastcloudinit 0.0.2__tar.gz → 0.0.4__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.4
4
4
  Summary: Simplified opinionated cloud init for ubuntu
5
5
  Home-page: https://github.com/AnswerDotAI/fastcloudinit
6
6
  Author: Jeremy Howard
@@ -20,6 +20,8 @@ Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
21
  Requires-Dist: fastcore
22
22
  Requires-Dist: PyYAML
23
+ Requires-Dist: httpx
24
+ Requires-Dist: jsonschema
23
25
  Provides-Extra: dev
24
26
  Dynamic: author
25
27
  Dynamic: author-email
@@ -0,0 +1,2 @@
1
+ __version__ = "0.0.4"
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,21 +1,24 @@
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 *
9
- import fastcore.xtras, yaml
10
9
  from textwrap import dedent
10
+ from jsonschema import validate
11
+ from httpx import get as xget
12
+
13
+ import fastcore.xtras, yaml, json
11
14
 
12
15
  # %% ../nbs/00_core.ipynb
13
16
  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)
17
+ cmds = [ f"ufw default {def_incoming} incoming", f"ufw default {def_outgoing} outgoing", f"ufw logging {logging}" ]
18
+ for name, port in allows.items(): cmds.append("ufw allow {}/tcp".format(port))
19
+ if internal: cmds.append("ufw allow in on {}".format(internal))
20
+ cmds.append("ufw --force enable")
21
+ return cmds
19
22
 
20
23
  # %% ../nbs/00_core.ipynb
21
24
  def user(name, pub_keys, groups=None, shell="/bin/bash", sudo=True):
@@ -46,8 +49,11 @@ Unattended-Upgrade::Automatic-Reboot "{auto_reboot}";
46
49
 
47
50
  # %% ../nbs/00_core.ipynb
48
51
  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))
52
+ return [
53
+ {'path': f"/etc/systemd/system/{unit_name}.d/override.conf",
54
+ 'owner': 'root:root', 'permissions': '0644', 'content': content}
55
+ for unit_name, content in items.items()
56
+ ]
51
57
 
52
58
  # %% ../nbs/00_core.ipynb
53
59
  def log_rotate(freq="weekly", num_keep=7, fname="00-cloud-init-global"):
@@ -80,43 +86,31 @@ def mounts(devices):
80
86
  return dict(mounts=devices)
81
87
 
82
88
  # %% ../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)
89
+ def runcmd(cmds):
90
+ if not cmds: return {}
91
+ return dict(runcmd=cmds)
100
92
 
101
93
  # %% ../nbs/00_core.ipynb
102
- def cloud_init_base(hostname, packages=None, **kw):
94
+ def cloud_init_base(hostname, packages=None, check=True, **kw):
103
95
  cfg = dict(
104
96
  hostname=hostname, preserve_hostname=False,
105
97
  packages=listify(packages), package_update=True, package_upgrade=True,
106
98
  disable_root=True, ssh_pwauth=False, **kw
107
99
  )
100
+ if check: cc_validate(cfg)
108
101
  return "#cloud-config\n" + yaml.safe_dump(cfg, sort_keys=False, width=1_000_000)
109
102
 
110
103
  # %% ../nbs/00_core.ipynb
111
- def cloud_init_config(hostname, username, pub_keys, email='', groups=None, internal=None,
104
+ def cloud_init_config(hostname, username, pub_keys, email='', groups=None, internal=None, cmds=None,
112
105
  devices=None, ping_host=None, packages=None, dropins=None, **sources):
106
+ cmds = listify(cmds)
107
+ cmds += ufw(internal=internal, OpenSSH=22)
113
108
  return cloud_init_base(
114
109
  hostname, packages=packages,
115
110
  users=[user(username, pub_keys, groups=groups)],
116
- **ufw(internal=internal, OpenSSH=22),
111
+ **runcmd(cmds),
117
112
  **apt(**sources),
118
- **systemd(dropins or {}),
119
- write_files=[ log_rotate() ],
113
+ write_files=[ log_rotate(), *systemd(dropins or {}) ],
120
114
  **mounts(devices),
121
115
  **phone_home(ping_host),
122
116
  **reboot(),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fastcloudinit
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: Simplified opinionated cloud init for ubuntu
5
5
  Home-page: https://github.com/AnswerDotAI/fastcloudinit
6
6
  Author: Jeremy Howard
@@ -20,6 +20,8 @@ Description-Content-Type: text/markdown
20
20
  License-File: LICENSE
21
21
  Requires-Dist: fastcore
22
22
  Requires-Dist: PyYAML
23
+ Requires-Dist: httpx
24
+ Requires-Dist: jsonschema
23
25
  Provides-Extra: dev
24
26
  Dynamic: author
25
27
  Dynamic: author-email
@@ -1,4 +1,6 @@
1
1
  fastcore
2
2
  PyYAML
3
+ httpx
4
+ jsonschema
3
5
 
4
6
  [dev]
@@ -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.4
5
5
  min_python = 3.9
6
6
  license = apache2
7
7
  black_formatting = False
@@ -28,7 +28,7 @@ keywords = nbdev jupyter notebook python
28
28
  language = English
29
29
  status = 3
30
30
  user = AnswerDotAI
31
- requirements = fastcore PyYAML
31
+ requirements = fastcore PyYAML httpx jsonschema
32
32
  readme_nb = index.ipynb
33
33
  allowed_metadata_keys =
34
34
  allowed_cell_metadata_keys =
@@ -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