Skip to content

Commit d3c4653

Browse files
xmonaderOmarElawadyRafyAmgadBenjaminm-motaweaashraffouda
authored
Development 3botdeployer (#1441)
* Add location choice * Block the chatflow until the farms are ready * Add location policy * Fetch farm name early * Fix pool selection when forcing specific node * Use drop down menu instead of single choice * Create wallet on entry * working on adding 3bot status * Create a new wallet on 3bot creation * Rename the wallet to mainnet_wallet * Move wallet creation to threebot start * Log wallet creation errors and continue starting * Don't discriminate between self hosted and chatflow hosted 3Bots * update backup path related to restic server * Deploy on the new identity * add flavors for deployer * override the flavors * Create 3bot on new pool and new managed network * add destroy, delete and restart actions * add /root/.ssh to restic backup paths * add the deployer actions depending on the status * update methods with identity_name wip * separate 3bot deployers in separate component * refactor models dir * fix saved subdomain id * fix instance name * working on the frontend for listin the 3bots * use mainnet default * fixing and issue related to back /.ssh path * threebot listing wip * check for workload container type in building info * remove debugging prints * expired pools have empty_at at max int64 * add stop and delete threebot solutions * check if metadata exists before trying to decrypt it * fix typos * set owner key in networks metadata updated by the admin dashboard * move threebot config validation to a separate method * remove unused statement * address comments * deploy on mainnet * Development 3botdeployer escalation emails (#1478) * Add escalation emails button in developer options in fron-end and update the back-end * Add escalation email front-end and back-end * Handle the None stat in config manager related to escalating emails * fix invalid import * use management as name for networks 3bot deployment * pass identity to dry_run context * use new listing util in threebot chatflow * fix network name * return expiration * Update front-end and back end to use the new methods in listing the threebot states * add start method in utils * Restart 3Bot wip * Adds correct actions for stop / destroy threebot for threebot deployer Signed-off-by: Ashraf Fouda <[email protected]> * Fix steps missing comma * Add final step * Add some hardening for threebot deletion and stopping * clean up threebot identity * updated frontend view * delete only deployed workloads * add change size and location chatflows * receive 3bot name from params * clean up unused identity * fix log config * fix log config * fix message * remove extend * clear workloads in deployment_context before deleting threebot identity * show the correct empty at in blocked nodes * one table for all workloads * Add state filter in deployed 3bots UI * show bell icon and extend message and remove expiration column * update quick start guide * update quick start guide * change expiration icon * show href in info if the threebot is running * remove not needed inof when threebot is not running * fix error message * Create wallets when deploying new threebot * remove unused actor methods * override the flist with latest flist on redeployments * override the flist with latest flist on redeployments * fix api url and remove deprecated apis * return status 400 instead of raising exception * fix cancel solution for other identities * update branch in redeployments * open url in another tab * pass identity name to metadata encryption & decryption in delete_access * use root instead of homedir * change variable name * change ssh dir path based on the current user running 3bot server * fix message * revert ssh dir * respect over provisioning in farm capacity check * remove extend test * use identity name when decrypting metadata * Development 3botdeployer autoextend pool (#1526) auto-extend pools * Use std instead of default identity for the main wallet * update threebot tests * remove conflicts * remove recover and extend tests * Update email server config in admin dashboard vue to include tooltips * add threebot start & change size gedis patches * add threebot change location patch * add threebot change location patch * init test cases for threebot deployer * Make development as the default branch for threebot deployer Co-authored-by: Omar Elawady <[email protected]> Co-authored-by: Rafy Benjamin <[email protected]> Co-authored-by: m-motawea <[email protected]> Co-authored-by: RafyAmgadBenjamin <[email protected]> Co-authored-by: Ashraf Fouda <[email protected]> Co-authored-by: ranatrk <[email protected]> Co-authored-by: Waleed <[email protected]>
1 parent fa0082e commit d3c4653

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2810
-687
lines changed

jumpscale/entry_points/threebot.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from jumpscale.loader import j
1212
from jumpscale.threesdk.identitymanager import IdentityManager
1313
from jumpscale.sals.nginx.nginx import PORTS
14+
from jumpscale.packages.admin.actors.wallet import Wallet
1415

1516
SERVICES_PORTS = {"nginx": 8999, "nginx_http": 80, "nginx_https": 443, "gedis": 16000}
1617

@@ -80,6 +81,9 @@ def start(identity=None, background=False, local=False, development=False, domai
8081
identity (str, optional): threebot name. Defaults to None.
8182
explorer (str, optional): which explorer network to use: mainnet, testnet, devnet. Defaults to None.
8283
"""
84+
if j.config.get("ANNOUNCED") is None:
85+
j.config.set("ANNOUNCED", False)
86+
create_wallets_if_not_exists()
8387
check_for_bins()
8488
PORTS.init_default_ports(local)
8589
SERVICES_PORTS["nginx_http"] = PORTS.HTTP
@@ -227,7 +231,7 @@ def clean(all=False):
227231
print(f"exception was {e} for debugging")
228232

229233
answer = j.tools.console.ask_yes_no(f"Do you want to remove {config_root} ? ")
230-
if answer=="y":
234+
if answer == "y":
231235
j.sals.fs.rmtree(config_root)
232236
print("Previous configuration is deleted.")
233237

@@ -236,12 +240,44 @@ def clean(all=False):
236240
print(f"exception for debugging {e}")
237241

238242

239-
240243
@click.group()
241244
def cli():
242245
pass
243246

244247

248+
def have_wallets():
249+
wallets = j.clients.stellar.list_all()
250+
test, main = False, False
251+
for wallet_name in wallets:
252+
wallet = j.clients.stellar.get(wallet_name)
253+
if wallet.network.value == "TEST":
254+
test = True
255+
elif wallet.network.value == "STD":
256+
main = True
257+
return test, main
258+
259+
260+
def create_test_wallet(wallet_name):
261+
try:
262+
j.clients.stellar.create_testnet_funded_wallet(wallet_name)
263+
except Exception as e:
264+
j.logger.error(str(e))
265+
266+
267+
def create_main_wallet(wallet_name):
268+
wallet_actor = Wallet()
269+
try:
270+
wallet_actor.create_wallet(wallet_name, "STD")
271+
except Exception as e:
272+
j.logger.error(str(e))
273+
274+
275+
def create_wallets_if_not_exists():
276+
test, main = have_wallets()
277+
if not test:
278+
create_test_wallet("test")
279+
if not main:
280+
create_main_wallet("main")
245281

246282

247283
cli.add_command(start)

jumpscale/packages/admin/actors/admin.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,32 +185,46 @@ def get_developer_options(self) -> str:
185185
test_cert = j.core.config.set_default("TEST_CERT", False)
186186
over_provision = j.core.config.set_default("OVER_PROVISIONING", False)
187187
explorer_logs = j.core.config.set_default("EXPLORER_LOGS", False)
188+
escalation_emails = j.core.config.set_default("ESCALATION_EMAILS_ENABLED", False)
189+
auto_extend_pools = j.core.config.set_default("AUTO_EXTEND_POOLS_ENABLED", False)
188190
sort_nodes_by_sru = j.core.config.set_default("SORT_NODES_BY_SRU", False)
189191
return j.data.serializers.json.dumps(
190192
{
191193
"data": {
192194
"test_cert": test_cert,
193195
"over_provision": over_provision,
194196
"explorer_logs": explorer_logs,
197+
"escalation_emails": escalation_emails,
198+
"auto_extend_pools": auto_extend_pools,
195199
"sort_nodes_by_sru": sort_nodes_by_sru,
196200
}
197201
}
198202
)
199203

200204
@actor_method
201205
def set_developer_options(
202-
self, test_cert: bool, over_provision: bool, explorer_logs: bool, sort_nodes_by_sru: bool
206+
self,
207+
test_cert: bool,
208+
over_provision: bool,
209+
explorer_logs: bool,
210+
sort_nodes_by_sru: bool,
211+
escalation_emails: bool,
212+
auto_extend_pools: bool,
203213
) -> str:
204214
j.core.config.set("TEST_CERT", test_cert)
205215
j.core.config.set("OVER_PROVISIONING", over_provision)
206216
j.core.config.set("EXPLORER_LOGS", explorer_logs)
217+
j.core.config.set("ESCALATION_EMAILS_ENABLED", escalation_emails)
218+
j.core.config.set("AUTO_EXTEND_POOLS_ENABLED", auto_extend_pools)
207219
j.core.config.set("SORT_NODES_BY_SRU", sort_nodes_by_sru)
208220
return j.data.serializers.json.dumps(
209221
{
210222
"data": {
211223
"test_cert": test_cert,
212224
"over_provision": over_provision,
213225
"explorer_logs": explorer_logs,
226+
"escalation_emails": escalation_emails,
227+
"auto_extend_pools": auto_extend_pools,
214228
"sort_nodes_by_sru": sort_nodes_by_sru,
215229
}
216230
}
@@ -222,6 +236,42 @@ def clear_blocked_nodes(self) -> str:
222236
return j.data.serializers.json.dumps({"data": "blocked nodes got cleared successfully."})
223237

224238
@actor_method
239+
def get_email_server_config(self) -> str:
240+
email_server_config = j.core.config.get("EMAIL_SERVER_CONFIG", {})
241+
email_server_config.setdefault("host", "")
242+
email_server_config.setdefault("port", "")
243+
email_server_config.setdefault("username", "")
244+
email_server_config.setdefault("password", "")
245+
return j.data.serializers.json.dumps({"data": email_server_config})
246+
247+
@actor_method
248+
def set_email_server_config(self, host="", port="", username="", password="") -> str:
249+
email_server_config = j.core.config.get("EMAIL_SERVER_CONFIG", {})
250+
email_server_config = {"host": host, "port": port, "username": username, "password": password}
251+
j.core.config.set("EMAIL_SERVER_CONFIG", email_server_config)
252+
return j.data.serializers.json.dumps({"data": email_server_config})
253+
254+
@actor_method
255+
def list_escalation_emails(self) -> str:
256+
escalation_emails = j.core.config.get("ESCALATION_EMAILS", [])
257+
return j.data.serializers.json.dumps({"data": escalation_emails})
258+
259+
@actor_method
260+
def add_escalation_email(self, email) -> str:
261+
escalation_emails = j.core.config.get("ESCALATION_EMAILS", [])
262+
if email not in escalation_emails:
263+
escalation_emails.append(email)
264+
j.core.config.set("ESCALATION_EMAILS", escalation_emails)
265+
return j.data.serializers.json.dumps({"data": escalation_emails})
266+
267+
@actor_method
268+
def delete_escalation_email(self, email) -> str:
269+
escalation_emails = j.core.config.get("ESCALATION_EMAILS", [])
270+
if email in escalation_emails:
271+
escalation_emails.remove(email)
272+
j.core.config.set("ESCALATION_EMAILS", escalation_emails)
273+
return j.data.serializers.json.dumps({"data": escalation_emails})
274+
225275
def get_notifications(self) -> str:
226276
notifications = []
227277
if j.tools.notificationsqueue.count() >= 10:

jumpscale/packages/admin/actors/wallet.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55

66
class Wallet(BaseActor):
77
@actor_method
8-
def create_wallet(self, name: str) -> str:
8+
def create_wallet(self, name: str, wallettype: str = None) -> str:
99
explorer = j.core.identity.me.explorer
10-
wallettype = "STD"
11-
if "testnet" in explorer.url or "devnet" in explorer.url:
12-
wallettype = "TEST"
10+
if wallettype is None:
11+
if "testnet" in explorer.url or "devnet" in explorer.url:
12+
wallettype = "TEST"
13+
else:
14+
wallettype = "STD"
1315

1416
if j.clients.stellar.find(name):
1517
raise j.exceptions.Value(f"Wallet {name} already exists")

jumpscale/packages/admin/bottle/admin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
app = Bottle()
1010

11+
1112
@app.route("/api/allowed", method="GET")
1213
@login_required
1314
def allowed():
@@ -44,4 +45,23 @@ def accept():
4445
)
4546

4647

48+
@app.route("/api/announced", method="GET")
49+
@login_required
50+
def announced():
51+
result = bool(j.config.get("ANNOUNCED"))
52+
53+
return HTTPResponse(
54+
j.data.serializers.json.dumps({"announced": result}), status=200, headers={"Content-Type": "application/json"}
55+
)
56+
57+
58+
@app.route("/api/announce", method="GET")
59+
@login_required
60+
def announce():
61+
j.config.set("ANNOUNCED", True)
62+
return HTTPResponse(
63+
j.data.serializers.json.dumps({"announced": True}), status=200, headers={"Content-Type": "application/json"}
64+
)
65+
66+
4767
app = SessionMiddleware(app, SESSION_OPTS)

jumpscale/packages/admin/frontend/App.vue

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,33 @@
136136
<identities v-model="dialogs.identity"></identities>
137137
<popup></popup>
138138
</v-main>
139+
<v-dialog
140+
v-model="announcement_dialog"
141+
persistent
142+
max-width="500"
143+
>
144+
145+
<v-card>
146+
<v-card-title class="headline">
147+
Quick start guide
148+
</v-card-title>
149+
<v-card-text>
150+
We've created two wallets for you; main and test. These are to be used for mainnet and testnet respectively. Make sure your wallets are funded to extend your 3Bots before they expire.
151+
<br />
152+
Please visit the <a href="https://manual.threefold.io">manual</a> for more information.
153+
</v-card-text>
154+
<v-card-actions>
155+
<v-spacer></v-spacer>
156+
<v-btn
157+
color="green darken-1"
158+
text
159+
@click="announced = true"
160+
>
161+
Ok
162+
</v-btn>
163+
</v-card-actions>
164+
</v-card>
165+
</v-dialog>
139166
</v-app>
140167
</template>
141168

@@ -171,14 +198,17 @@ module.exports = {
171198
dialogs: {
172199
identity: false,
173200
},
201+
announced: true
174202
};
175203
},
176204
components: {
177205
identities: httpVueLoader("./Identity.vue"),
178206
},
179-
computed: {},
180207
methods: {},
181208
computed: {
209+
announcement_dialog() {
210+
return !this.announced
211+
},
182212
pages() {
183213
return this.$router.options.routes.filter((page) => {
184214
return page.meta.listed;
@@ -197,6 +227,13 @@ module.exports = {
197227
this.user = response.data;
198228
});
199229
},
230+
getAnnouncementStatus() {
231+
this.$api.announcement.announced().then((response) => {
232+
console.log(response.data)
233+
this.announced = response.data["announced"];
234+
this.$api.announcement.announce();
235+
});
236+
},
200237
getIdentity() {
201238
this.$api.identity.get().then((response) => {
202239
this.identity = JSON.parse(response.data);
@@ -237,6 +274,7 @@ module.exports = {
237274
this.checkDarkMode();
238275
this.getIdentity();
239276
this.getCurrentUser();
277+
this.getAnnouncementStatus();
240278
this.setTimeLocal();
241279
this.clockInterval = setInterval(() => {
242280
this.setTimeLocal();

jumpscale/packages/admin/frontend/api.js

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ const apiClient = {
181181
url: `${baseURL}/admin/get_developer_options`
182182
})
183183
},
184-
setDeveloperOptions: (testCert, overProvision, explorerLogs, sortNodesBySRU) => {
184+
setDeveloperOptions: (testCert, overProvision, explorerLogs, escalationEmails, autoExtendPools, sortNodesBySRU) => {
185185
return axios({
186186
url: `${baseURL}/admin/set_developer_options`,
187187
method: "post",
188188
headers: { 'Content-Type': 'application/json' },
189-
data: { test_cert: testCert, over_provision: overProvision, explorer_logs: explorerLogs, sort_nodes_by_sru: sortNodesBySRU }
189+
data: { test_cert: testCert, over_provision: overProvision, explorer_logs: explorerLogs, sort_nodes_by_sru: sortNodesBySRU, escalation_emails: escalationEmails, auto_extend_pools: autoExtendPools }
190190
})
191191
},
192192
clearBlockedNodes: () => {
@@ -205,6 +205,50 @@ const apiClient = {
205205
})
206206
}
207207
},
208+
emailServerConfig: {
209+
get: () => {
210+
return axios({
211+
url: `${baseURL}/admin/get_email_server_config`
212+
})
213+
},
214+
set: (host, port, username, password) => {
215+
return axios({
216+
url: `${baseURL}/admin/set_email_server_config`,
217+
method: "post",
218+
headers: { "Content-Type": "application/json" },
219+
data: {
220+
host: host,
221+
port: port,
222+
username: username,
223+
password: password
224+
}
225+
})
226+
},
227+
},
228+
escalationEmails: {
229+
list: () => {
230+
return axios({
231+
url: `${baseURL}/admin/list_escalation_emails`
232+
})
233+
},
234+
add: (email) => {
235+
return axios({
236+
url: `${baseURL}/admin/add_escalation_email`,
237+
method: "post",
238+
headers: { 'Content-Type': 'application/json' },
239+
data: { email: email }
240+
})
241+
},
242+
delete: (email) => {
243+
return axios({
244+
url: `${baseURL}/admin/delete_escalation_email`,
245+
method: "post",
246+
headers: { 'Content-Type': 'application/json' },
247+
data: { email: email }
248+
})
249+
}
250+
251+
},
208252
explorers: {
209253
get: () => {
210254
return axios({
@@ -534,5 +578,19 @@ const apiClient = {
534578
method: "get"
535579
})
536580
},
581+
},
582+
announcement: {
583+
announced: () => {
584+
return axios({
585+
url: `/admin/api/announced`,
586+
method: "get"
587+
})
588+
},
589+
announce: () => {
590+
return axios({
591+
url: `/admin/api/announce`,
592+
method: "get"
593+
})
594+
},
537595
}
538596
}

0 commit comments

Comments
 (0)