py-pve-cloud 3.4.4__tar.gz → 3.4.6__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.
Files changed (37) hide show
  1. {py_pve_cloud-3.4.4/src/py_pve_cloud.egg-info → py_pve_cloud-3.4.6}/PKG-INFO +2 -2
  2. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/pyproject.toml +1 -1
  3. py_pve_cloud-3.4.6/src/pve_cloud/_version.py +1 -0
  4. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/cli/pxrpc.py +38 -33
  5. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6/src/py_pve_cloud.egg-info}/PKG-INFO +2 -2
  6. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/py_pve_cloud.egg-info/requires.txt +1 -1
  7. py_pve_cloud-3.4.4/src/pve_cloud/_version.py +0 -1
  8. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/LICENSE.md +0 -0
  9. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/README.md +0 -0
  10. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/setup.cfg +0 -0
  11. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/cli/pvcli.py +0 -0
  12. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/cli/pvclu.py +0 -0
  13. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/lib/backup_rpc.py +0 -0
  14. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/lib/inventory.py +0 -0
  15. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/lib/ssh.py +0 -0
  16. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/alchemy.py +0 -0
  17. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/alembic.ini +0 -0
  18. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/env.py +0 -0
  19. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/04398db10434_external_cp_extra_sans.py +0 -0
  20. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/0ad803c51325_machine_type_refactor.py +0 -0
  21. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/24a548bfce3e_len_rules_enforcements.py +0 -0
  22. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/27724e407e2b_proxy_fqdn.py +0 -0
  23. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/3c95509a5de9_fix.py +0 -0
  24. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/7496c3f3b2e8_fix_secrets_constraint.py +0 -0
  25. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/7868bcd05006_migrate_old.py +0 -0
  26. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/7dea8c4ee39f_init.py +0 -0
  27. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/944a8fd5d5bc_ext_ctrl_plns.py +0 -0
  28. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/9de11ef8ba39_vm_vars_and_cloud_secrets.py +0 -0
  29. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/d9b711555be8_ext_control_plane.py +0 -0
  30. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/e60b9cc63413_ingress_generic.py +0 -0
  31. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/e6ae1e138c1f_change_scope_cloud.py +0 -0
  32. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/ee4924ac4f60_secrets_plural_type.py +0 -0
  33. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/pve_cloud/orm/migrations/versions/fdcb5aa33b76_slop_firewall_seperation.py +0 -0
  34. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/py_pve_cloud.egg-info/SOURCES.txt +0 -0
  35. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/py_pve_cloud.egg-info/dependency_links.txt +0 -0
  36. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/py_pve_cloud.egg-info/entry_points.txt +0 -0
  37. {py_pve_cloud-3.4.4 → py_pve_cloud-3.4.6}/src/py_pve_cloud.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py-pve-cloud
3
- Version: 3.4.4
3
+ Version: 3.4.6
4
4
  Author-email: Tobias Huebner <tobias.huebner@vmzberlin.com>
5
5
  License-Expression: GPL-3.0-or-later
6
6
  License-File: LICENSE.md
@@ -13,5 +13,5 @@ Requires-Dist: dnspython==2.8.0
13
13
  Requires-Dist: rpyc==6.0.2
14
14
  Requires-Dist: fabric==3.2.3
15
15
  Requires-Dist: asyncssh==2.22.0
16
- Requires-Dist: pve-cloud-schemas<3.3.0,>=3.2.4
16
+ Requires-Dist: pve-cloud-schemas<3.3.0,>=3.2.5
17
17
  Dynamic: license-file
@@ -17,7 +17,7 @@ dependencies = [
17
17
  "rpyc==6.0.2",
18
18
  "fabric==3.2.3",
19
19
  "asyncssh==2.22.0",
20
- "pve-cloud-schemas>=3.2.4,<3.3.0"
20
+ "pve-cloud-schemas>=3.2.5,<3.3.0"
21
21
  ]
22
22
  dynamic = ["version"]
23
23
 
@@ -0,0 +1 @@
1
+ __version__ = "3.4.6"
@@ -3,7 +3,6 @@ import json
3
3
  import multiprocessing
4
4
  import os
5
5
  import re
6
- import signal
7
6
  import socket
8
7
  import subprocess
9
8
  import sys
@@ -23,6 +22,7 @@ import yaml
23
22
  from fabric import Connection
24
23
  from proxmoxer import ProxmoxAPI
25
24
  from pve_cloud_schemas.validate import validate_cluster_vars
25
+ from rpyc.utils.helpers import classpartial
26
26
  from sqlalchemy import create_engine, delete, select
27
27
  from sqlalchemy.exc import IntegrityError
28
28
  from sqlalchemy.orm import Session
@@ -30,6 +30,9 @@ from sqlalchemy.orm import Session
30
30
  from pve_cloud.orm.alchemy import (AcmeX509, ProxmoxCloudSecrets,
31
31
  VirtualMachineVars)
32
32
 
33
+ # when this service is run remotely you can debug / view its logs easily running
34
+ # `journalctl -u pxrpc-service.slice` (this lets you view the logs of all instances)
35
+
33
36
 
34
37
  # services need to implement the shutdown function
35
38
  class PxServiceEnum(StrEnum):
@@ -37,31 +40,12 @@ class PxServiceEnum(StrEnum):
37
40
  PROXMOXER = "PROXMOXER"
38
41
 
39
42
 
40
- # initialized / launched by pvcli connect_remote_cluster
41
- # it is launched on a proxmox host
42
-
43
- # todo: it would be nice to have some generic exception handeling / wrapping and passing down to the
44
- # rpyc clients for printing. like a wrapping RPycException class and general implcit try catch + handeling
45
- # on terraform-provider-pxc unpacking
46
-
47
- # we once get the master pid, this is needed for the forkingserver
48
- # todo: probably not the best way for ipc shutdown, maybe use pipes?
49
- MASTER_PID = os.getpid()
50
-
51
-
52
- def shutdown_handler(signum, frame):
53
- # wait a few seconds so clients can gracefully disconnect
54
- time.sleep(5)
55
-
56
- # kill the entire process and all forks
57
- os.killpg(os.getpgrp(), signal.SIGKILL)
58
-
59
-
60
43
  @rpyc.service
61
44
  class RemoteProxmoxApi(rpyc.Service):
62
45
 
63
- def __init__(self):
46
+ def __init__(self, port):
64
47
  super().__init__()
48
+ self.port = port # port as transient id for systemctl shutdown
65
49
 
66
50
  # init services required by most functions
67
51
  self.proxmox = ProxmoxAPI("127.0.0.1", user="root", backend="ssh_paramiko")
@@ -70,10 +54,18 @@ class RemoteProxmoxApi(rpyc.Service):
70
54
  # this is the cleanest i found without triggerin eof on the clients side
71
55
  @rpyc.exposed
72
56
  def shutdown(self):
73
- os.kill(MASTER_PID, signal.SIGTERM) # this triggers the shutdown handler
57
+ subprocess.Popen(
58
+ [
59
+ "sh",
60
+ "-c",
61
+ f"sleep 5; systemctl stop pxrpc-service-{self.port}.service",
62
+ ],
63
+ start_new_session=True,
64
+ )
74
65
 
75
66
  @rpyc.exposed
76
67
  def get_pve_cluster_name(self):
68
+
77
69
  # try get the cluster name
78
70
  cluster_name = None
79
71
  status_resp = self.proxmox.cluster.status.get()
@@ -136,11 +128,27 @@ class PxrpcService(rpyc.Service):
136
128
  # this is the cleanest i found without triggerin eof on the clients side
137
129
  @rpyc.exposed
138
130
  def shutdown(self):
139
- os.kill(MASTER_PID, signal.SIGTERM) # this triggers the shutdown handler
131
+ if not self.port:
132
+ raise RuntimeError(
133
+ "Remote shutdown function called on instane initialized without id port!"
134
+ )
135
+
136
+ subprocess.Popen(
137
+ [
138
+ "sh",
139
+ "-c",
140
+ f"sleep 5; systemctl stop pxrpc-service-{self.port}.service",
141
+ ],
142
+ start_new_session=True,
143
+ )
140
144
 
141
- def __init__(self, cluster_vars=None, patroni_cstr=None, internal_bind_key=None):
145
+ def __init__(
146
+ self, cluster_vars=None, patroni_cstr=None, internal_bind_key=None, port=None
147
+ ):
142
148
  super().__init__()
143
149
 
150
+ self.port = port # port serves as id for systemctl transient service shutdown
151
+
144
152
  if cluster_vars:
145
153
  self.cluster_vars = cluster_vars
146
154
  else:
@@ -239,7 +247,7 @@ class PxrpcService(rpyc.Service):
239
247
  session.commit()
240
248
  return True
241
249
 
242
- except IntegrityError as e:
250
+ except IntegrityError:
243
251
  session.rollback()
244
252
  return False
245
253
 
@@ -387,16 +395,13 @@ def main():
387
395
 
388
396
  print("launching on", sys.argv[1], sys.argv[2], sys.argv[3])
389
397
 
390
- # register handler in master thread / process
391
- signal.signal(signal.SIGTERM, shutdown_handler)
392
-
393
398
  service_to_launch = None
394
399
  match PxServiceEnum(sys.argv[3]):
395
400
  # here custom inits could take place (using classpartial / constructor)
396
401
  case PxServiceEnum.PXRPC:
397
- service_to_launch = PxrpcService
402
+ service_to_launch = classpartial(PxrpcService, port=int(sys.argv[1]))
398
403
  case PxServiceEnum.PROXMOXER:
399
- service_to_launch = RemoteProxmoxApi
404
+ service_to_launch = classpartial(RemoteProxmoxApi, port=int(sys.argv[1]))
400
405
 
401
406
  # launch it threaded for sync (easy tasks no paralellism)
402
407
  if sys.argv[2] == "THREADED":
@@ -460,8 +465,8 @@ def _launch_pxrpc_base(
460
465
  print("open port remote", open_port_remote)
461
466
 
462
467
  # run detached pxrpc server - we use this to execute python code remotely on the jump host
463
- # pkill -f pxrpc to cleanup
464
- pxrpc_cmd = f"export PYTHONUNBUFFERED=1; /root/.pxc-venv/bin/pxrpc {open_port_remote} {rpyc_server_type} {rpyc_service} >> /var/log/pxrpc-{open_port_remote}.log 2>&1"
468
+ # `pkill -f pxrpc` to cleanup, `journalctl -u pxrpc-service.slice` to view logs
469
+ pxrpc_cmd = f"systemd-run --unit=pxrpc-service-{open_port_remote} --slice=pxrpc-service.slice /root/.pxc-venv/bin/pxrpc {open_port_remote} {rpyc_server_type} {rpyc_service}"
465
470
  print("pxrpc cmd", pxrpc_cmd)
466
471
  pve_host_conn.run(
467
472
  pxrpc_cmd,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py-pve-cloud
3
- Version: 3.4.4
3
+ Version: 3.4.6
4
4
  Author-email: Tobias Huebner <tobias.huebner@vmzberlin.com>
5
5
  License-Expression: GPL-3.0-or-later
6
6
  License-File: LICENSE.md
@@ -13,5 +13,5 @@ Requires-Dist: dnspython==2.8.0
13
13
  Requires-Dist: rpyc==6.0.2
14
14
  Requires-Dist: fabric==3.2.3
15
15
  Requires-Dist: asyncssh==2.22.0
16
- Requires-Dist: pve-cloud-schemas<3.3.0,>=3.2.4
16
+ Requires-Dist: pve-cloud-schemas<3.3.0,>=3.2.5
17
17
  Dynamic: license-file
@@ -7,4 +7,4 @@ dnspython==2.8.0
7
7
  rpyc==6.0.2
8
8
  fabric==3.2.3
9
9
  asyncssh==2.22.0
10
- pve-cloud-schemas<3.3.0,>=3.2.4
10
+ pve-cloud-schemas<3.3.0,>=3.2.5
@@ -1 +0,0 @@
1
- __version__ = "3.4.4"
File without changes
File without changes
File without changes