py-pve-cloud 0.0.4__py3-none-any.whl → 0.1.1__py3-none-any.whl

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.

Potentially problematic release.


This version of py-pve-cloud might be problematic. Click here for more details.

pve_cloud/cli/pvcli.py CHANGED
@@ -2,7 +2,7 @@ import argparse
2
2
  import yaml
3
3
  from proxmoxer import ProxmoxAPI
4
4
  import os
5
- import paramiko
5
+
6
6
 
7
7
 
8
8
  def connect_cluster(args):
pve_cloud/cli/pvclu.py CHANGED
@@ -2,6 +2,9 @@ import argparse
2
2
  import yaml
3
3
  import os
4
4
  import socket
5
+ import paramiko
6
+ import dns.resolver
7
+ import base64
5
8
 
6
9
 
7
10
  def get_cloud_domain(target_pve):
@@ -41,9 +44,65 @@ def get_online_pve_host(target_pve):
41
44
  raise Exception(f"Could not find online pve host for {target_pve}")
42
45
 
43
46
 
47
+ def get_cloud_env(pve_host):
48
+ ssh = paramiko.SSHClient()
49
+ ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
50
+
51
+ ssh.connect(pve_host, username="root")
52
+
53
+ # since we need root we cant use sftp and root via ssh is disabled
54
+ _, stdout, _ = ssh.exec_command("cat /etc/pve/cloud/cluster_vars.yaml")
55
+
56
+ cluster_vars = yaml.safe_load(stdout.read().decode('utf-8'))
57
+
58
+ _, stdout, _ = ssh.exec_command("cat /etc/pve/cloud/secrets/patroni.pass")
59
+
60
+ patroni_pass = stdout.read().decode('utf-8')
61
+
62
+ return cluster_vars, patroni_pass
63
+
64
+
44
65
  def get_online_pve_host_prsr(args):
45
66
  print(f"export PVE_ANSIBLE_HOST='{get_online_pve_host(args.target_pve)}'")
46
67
 
68
+
69
+ def get_ssh_master_kubeconfig(cluster_vars, stack_name):
70
+ resolver = dns.resolver.Resolver()
71
+ resolver.nameservers = [cluster_vars['bind_master_ip'], cluster_vars['bind_slave_ip']]
72
+
73
+ ddns_answer = resolver.resolve(f"masters-{stack_name}.{cluster_vars['pve_cloud_domain']}")
74
+ ddns_ips = [rdata.to_text() for rdata in ddns_answer]
75
+
76
+ if not ddns_ips:
77
+ raise Exception("No master could be found via DNS!")
78
+
79
+ ssh = paramiko.SSHClient()
80
+ ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
81
+
82
+ ssh.connect(ddns_ips[0], username="admin")
83
+
84
+ # since we need root we cant use sftp and root via ssh is disabled
85
+ _, stdout, _ = ssh.exec_command("sudo cat /etc/kubernetes/admin.conf")
86
+
87
+ return base64.b64encode(stdout.read().decode('utf-8').replace("https://127.0.0.1:6443", f"https://{ddns_ips[0]}:6443").encode('utf-8')).decode('utf-8')
88
+
89
+
90
+ def export_envr(args):
91
+ ansible_host = get_online_pve_host(args.target_pve)
92
+ cloud_domain = get_cloud_domain(args.target_pve)
93
+ cluster_vars, patroni_pass = get_cloud_env(ansible_host)
94
+ print(f"export PVE_ANSIBLE_HOST='{ansible_host}'")
95
+ print(f"export PVE_CLOUD_DOMAIN='{cloud_domain}'")
96
+
97
+ # tf vars
98
+ print(f"export PG_CONN_STR=\"postgres://postgres:{patroni_pass}@{cluster_vars['pve_haproxy_floating_ip_internal']}:5000/tf_states?sslmode=disable\"")
99
+ print(f"export TF_VAR_pve_cloud_domain='{cloud_domain}'")
100
+ print(f"export TF_VAR_pve_host='{ansible_host}'")
101
+ print(f"export TF_VAR_cluster_proxy_ip='{cluster_vars['pve_haproxy_floating_ip_internal']}'")
102
+ print(f"export TF_VAR_pve_cloud_pg_cstr=\"postgresql+psycopg2://postgres:{patroni_pass}@{cluster_vars['pve_haproxy_floating_ip_internal']}:5000/pve_cloud?sslmode=disable\"")
103
+ print(f"export TF_VAR_master_b64_kubeconf='{get_ssh_master_kubeconfig(cluster_vars, args.stack_name)}'")
104
+
105
+
47
106
 
48
107
  def main():
49
108
  parser = argparse.ArgumentParser(description="PVE Cloud utility cli. Should be called with bash eval.")
@@ -56,6 +115,11 @@ def main():
56
115
  get_cld_domain_parser.add_argument("--target-pve", type=str, help="The target pve cluster to get the cloud domain of.", required=True)
57
116
  get_cld_domain_parser .set_defaults(func=get_cld_domain_prsr)
58
117
 
118
+ export_envr_parser = subparsers.add_parser("export-envrc", help="Export variables for k8s .envrc", parents=[base_parser])
119
+ export_envr_parser.add_argument("--target-pve", type=str, help="The target pve cluster.", required=True)
120
+ export_envr_parser.add_argument("--stack-name", type=str, help="Stack name of the deployment.", required=True)
121
+ export_envr_parser.set_defaults(func=export_envr)
122
+
59
123
  get_online_pve_host_parser = subparsers.add_parser("get-online-host", help="Gets the ip for the first online proxmox host in the cluster.", parents=[base_parser])
60
124
  get_online_pve_host_parser.add_argument("--target-pve", type=str, help="The target pve cluster to get the first online ip of.", required=True)
61
125
  get_online_pve_host_parser.set_defaults(func=get_online_pve_host_prsr)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: py-pve-cloud
3
- Version: 0.0.4
3
+ Version: 0.1.1
4
4
  Author-email: Tobias Huebner <tobias.huebner@vmzberlin.com>
5
5
  License-Expression: GPL-3.0-or-later
6
6
  License-File: LICENSE
@@ -8,5 +8,7 @@ Requires-Dist: PyYAML==6.0.2
8
8
  Requires-Dist: psycopg2-binary==2.9.10
9
9
  Requires-Dist: SQLAlchemy==2.0.43
10
10
  Requires-Dist: alembic==1.16.5
11
+ Requires-Dist: paramiko==4.0.0
11
12
  Requires-Dist: proxmoxer==2.2.0
13
+ Requires-Dist: dnspython==2.7.0
12
14
  Dynamic: license-file
@@ -1,5 +1,5 @@
1
- pve_cloud/cli/pvcli.py,sha256=inR4KMI63nWufPYoM9udxgh3CN10xyQlJw_kGzVw7DQ,3166
2
- pve_cloud/cli/pvclu.py,sha256=D5R5Gzo_iSImPTtEHVJWZoFr66uijeFbb-k6ODz_71o,2498
1
+ pve_cloud/cli/pvcli.py,sha256=sRMVhpUQzDF1sRP9d8u-aDUkCRp6KoneiqZX_mLCgGU,3151
2
+ pve_cloud/cli/pvclu.py,sha256=Hszd6kVvWcD_Z4aMyVyzsDvCmV9myJTiRate1ABISJg,5276
3
3
  pve_cloud/lib/inventory.py,sha256=0W31j34jtxUa-3Cxe0HmHJqc_8CpvvxyDqd0sAZ5oCI,31
4
4
  pve_cloud/orm/alchemy.py,sha256=1PABOo2d-ceIwlSZPYx19aXZFszDXMh8YIXgkLT-554,5000
5
5
  pve_cloud/orm/alembic.ini,sha256=7140n-YUj06aAIHOHACm8U0xhUFUoBZ4Jw23KlYB9EA,4865
@@ -11,9 +11,9 @@ pve_cloud/orm/migrations/versions/7868bcd05006_migrate_old.py,sha256=rU8Bw2tYDyn
11
11
  pve_cloud/orm/migrations/versions/7dea8c4ee39f_init.py,sha256=iMDyHhtyvpSywMnLhiSEL3W12YSm6sPa18XRgzQcwDg,954
12
12
  pve_cloud/orm/migrations/versions/944a8fd5d5bc_ext_ctrl_plns.py,sha256=LnVAShLaU1asz1L7TYs7oI9SnLxPp2IOA6K83kHNkN0,1674
13
13
  pve_cloud/orm/migrations/versions/d9b711555be8_ext_control_plane.py,sha256=uBqv1r5pLX-RjqciKYx0zvWyygJMa5u58DTnVfIEAF0,1073
14
- py_pve_cloud-0.0.4.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
15
- py_pve_cloud-0.0.4.dist-info/METADATA,sha256=EENqU0S2uq7SBI05ChHVDybFOBFEhcA55zEb4RWPJFo,362
16
- py_pve_cloud-0.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
- py_pve_cloud-0.0.4.dist-info/entry_points.txt,sha256=VvncsKmTJ46irz-9wQZ4Zo1FgNBjRltGDBKR9ht18mE,84
18
- py_pve_cloud-0.0.4.dist-info/top_level.txt,sha256=mpT7ttGRyZJVt_obhPLBHyIBcjKhUdJ-qVsMEVX5WJg,10
19
- py_pve_cloud-0.0.4.dist-info/RECORD,,
14
+ py_pve_cloud-0.1.1.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
15
+ py_pve_cloud-0.1.1.dist-info/METADATA,sha256=iOaf-gpm588QhGddRlPFmEgoXZa49o3sbtKWU5YG7nQ,425
16
+ py_pve_cloud-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
17
+ py_pve_cloud-0.1.1.dist-info/entry_points.txt,sha256=VvncsKmTJ46irz-9wQZ4Zo1FgNBjRltGDBKR9ht18mE,84
18
+ py_pve_cloud-0.1.1.dist-info/top_level.txt,sha256=mpT7ttGRyZJVt_obhPLBHyIBcjKhUdJ-qVsMEVX5WJg,10
19
+ py_pve_cloud-0.1.1.dist-info/RECORD,,