8
8
from flask import Flask , request
9
9
import os
10
10
11
+
11
12
def create_app ():
12
13
app = Flask (__name__ )
13
14
@@ -47,6 +48,7 @@ def create_container():
47
48
container = Container (** request .get_json (force = True ))
48
49
container .status = "creating"
49
50
new_container (container )
51
+
50
52
def get_ip ():
51
53
public_ip = subprocess .getoutput (
52
54
f"pct exec { get_vmid ()} -- ip -6 addr show eth0 | grep -oP '(?<=inet6\s)[\da-f:]+' | head -n 1"
@@ -106,6 +108,7 @@ class Network(BaseModel):
106
108
bridge : Optional [str ] = "vmbr0"
107
109
ipv6 : Optional [str ] = "dhcp"
108
110
111
+
109
112
class Container (BaseModel ):
110
113
id : Optional [int ] = ""
111
114
hostname : str
@@ -115,15 +118,17 @@ class Container(BaseModel):
115
118
ssh_public_keys : Optional [str ] = ""
116
119
status : Optional [str ] = ""
117
120
121
+
118
122
# Get id of container
119
123
def get_vmid ():
120
- max = 0
121
- for root , dirs , files in os .walk ("/etc/pve/lxc/" ):
122
- for file in files :
123
- vmid = int (file .replace ('.conf' , '' ))
124
- if vmid > max :
125
- max = vmid
126
- return max
124
+ max = 0
125
+ for root , dirs , files in os .walk ("/etc/pve/lxc/" ):
126
+ for file in files :
127
+ vmid = int (file .replace (".conf" , "" ))
128
+ if vmid > max :
129
+ max = vmid
130
+ return max
131
+
127
132
128
133
def new_container (container : Container ):
129
134
# Container ssh keys (optional, but needed if you want to login)
@@ -141,5 +146,3 @@ def new_container(container: Container):
141
146
pct create 999 --start --hostname 999 --net0 name=eth0,bridge=vmbr0,ip6=dhcp,gw6=2a01:4f8:160:2333:0:1:0:2 --memory 10240 local:vztmpl/debian-10-standard_10.7-1_amd64.tar.gz
142
147
143
148
"""
144
-
145
-
0 commit comments