Skip to content

Commit 4fbeded

Browse files
committed
restore & save seed in dev mode
1 parent 8afbda3 commit 4fbeded

File tree

6 files changed

+147
-168
lines changed

6 files changed

+147
-168
lines changed

images/utils/launcher/check_wallets.py

Lines changed: 0 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,6 @@
1818
# from .table import ServiceTable
1919
#
2020
#
21-
# class CFHeaderState:
22-
# def __init__(self):
23-
# self.current = 0
24-
# self.total = 0
25-
# self.ready = False
26-
#
27-
#
28-
# class Action:
29-
# def __init__(self, node_manager: NodeManager):
30-
# self.logger = logging.getLogger("launcher.CheckWalletsAction")
31-
# self.node_manager = node_manager
32-
# self.lnd_cfheaders = {}
33-
#
34-
# @property
35-
# def shell(self):
36-
# return self.node_manager.shell
37-
#
38-
# @property
39-
# def config(self):
40-
# return self.node_manager.config
41-
#
42-
# @property
43-
# def network(self) -> XudNetwork:
44-
# return self.config.network
4521
#
4622
# def lnd_has_unlock_log_line(self, c):
4723
# pass
@@ -142,18 +118,6 @@
142118
# except Exception as e:
143119
# raise RuntimeError("Failed to restart xud") from e
144120
#
145-
# @staticmethod
146-
# def _get_percentage(current, total):
147-
# if total == 0:
148-
# return "0.00%% (%d/%d)" % (current, total)
149-
# if current >= total:
150-
# return "100.00%% (%d/%d)" % (current, total)
151-
# p = current / total * 100
152-
# if p > 0.005:
153-
# p = p - 0.005
154-
# else:
155-
# p = 0
156-
# return "%.2f%% (%d/%d)" % (p, current, total)
157121
#
158122
# def _print_lnd_cfheaders(self, erase_last_line=True):
159123
# services = {}
@@ -301,23 +265,6 @@
301265
# if self.node_manager.newly_installed:
302266
# print()
303267
#
304-
# def xucli_create_wrapper(self, xud):
305-
# counter = 0
306-
# ok = False
307-
# while counter < 3:
308-
# try:
309-
# xud.cli("create", self.shell)
310-
# while True:
311-
# confirmed = self.shell.confirm("YOU WILL NOT BE ABLE TO DISPLAY YOUR XUD SEED AGAIN. Press ENTER to continue...")
312-
# if confirmed:
313-
# break
314-
# ok = True
315-
# break
316-
# except (PasswordNotMatch, InvalidPassword):
317-
# counter += 1
318-
# continue
319-
# if not ok:
320-
# raise Exception("Failed to create wallets")
321268
#
322269
# def xucli_restore_wrapper(self, xud):
323270
# counter = 0
@@ -337,81 +284,6 @@
337284
# if not ok:
338285
# raise Exception("Failed to restore wallets")
339286
#
340-
# def check_backup_dir(self, backup_dir):
341-
# assert not backup_dir.startswith("/mnt/hostfs")
342-
#
343-
# hostfs_dir = get_hostfs_file(backup_dir)
344-
#
345-
# if not os.path.exists(hostfs_dir):
346-
# return False, "not existed"
347-
#
348-
# if not os.path.isdir(hostfs_dir):
349-
# return False, "not a directory"
350-
#
351-
# if not os.access(hostfs_dir, os.R_OK):
352-
# return False, "not readable"
353-
#
354-
# if not os.access(hostfs_dir, os.W_OK):
355-
# return False, "not writable"
356-
#
357-
# return True, None
358-
#
359-
# def check_restore_dir(self, restore_dir):
360-
# return self.check_backup_dir(restore_dir)
361-
#
362-
# def check_restore_dir_files(self, restore_dir):
363-
# files = os.listdir(get_hostfs_file(restore_dir))
364-
# contents = []
365-
# if "xud" in files:
366-
# contents.append("xud")
367-
# if "lnd-BTC" in files:
368-
# contents.append("lndbtc")
369-
# if "lnd-LTC" in files:
370-
# contents.append("lndltc")
371-
# return contents
372-
#
373-
# def setup_backup_dir(self):
374-
# if self.config.backup_dir:
375-
# return
376-
#
377-
# backup_dir = None
378-
#
379-
# while True:
380-
# reply = self.shell.input("Enter path to backup location: ")
381-
# reply = reply.strip()
382-
# if len(reply) == 0:
383-
# continue
384-
#
385-
# backup_dir = normalize_path(reply)
386-
#
387-
# print("Checking backup location... ", end="")
388-
# sys.stdout.flush()
389-
# ok, reason = self.check_backup_dir(backup_dir)
390-
# if ok:
391-
# print("OK.")
392-
# break
393-
# else:
394-
# print(f"Failed. ", end="")
395-
# self.logger.debug(f"Failed to check backup dir {backup_dir}: {reason}")
396-
# sys.stdout.flush()
397-
# r = self.shell.no_or_yes("Retry?")
398-
# if r == "no":
399-
# self.node_manager.down()
400-
# raise FatalError("Backup directory not available")
401-
#
402-
# self.config.backup_dir = backup_dir
403-
#
404-
# def is_backup_available(self):
405-
# if self.config.backup_dir is None:
406-
# return False
407-
#
408-
# ok, reason = self.check_backup_dir(self.config.backup_dir)
409-
#
410-
# if not ok:
411-
# return False
412-
#
413-
# return True
414-
#
415287
# def setup_restore_dir(self) -> None:
416288
# """This function will try to interactively setting up restore_dir. And
417289
# store it in self._config.restore_dir
@@ -463,15 +335,6 @@
463335
#
464336
# self.config.restore_dir = restore_dir
465337
#
466-
# def _get_service(self, name: str) -> Node:
467-
# return self.node_manager.get_node(name)
468-
#
469-
# def _create_wallets(self):
470-
# try:
471-
# self.xucli_create_wrapper(xud)
472-
# break
473-
# except:
474-
# pass
475338
#
476339
# def _restore_wallets(self):
477340
# self.setup_restore_dir()
@@ -493,8 +356,6 @@
493356
#
494357
# self.config.restore_dir = None
495358
#
496-
# def _has_wallets(self) -> bool:
497-
# pass
498359
#
499360
# def _setup_wallets(self) -> None:
500361
# xud = self._get_service("xud")

images/utils/launcher/config/config.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def __init__(self):
3636
self.network = os.environ["NETWORK"]
3737

3838
self.network_dir = os.path.join("/root", self.network)
39+
self.host_network_dir = os.environ["NETWORK_DIR"]
40+
self.host_home = os.environ["HOST_HOME"]
41+
self.host_pwd = os.environ["HOST_PWD"]
3942
self.backup_dir = None
4043
self.restore_dir = None
4144

@@ -1030,20 +1033,38 @@ def expand_vars(self, value):
10301033
def logs_dir(self) -> str:
10311034
return os.path.join(self.network_dir, "logs")
10321035

1036+
@property
1037+
def host_logs_dir(self) -> str:
1038+
return os.path.join(self.host_network_dir, "logs")
1039+
10331040
@property
10341041
def data_dir(self) -> str:
10351042
return os.path.join(self.network_dir, "data")
10361043

1044+
@property
1045+
def host_data_dir(self) -> str:
1046+
return os.path.join(self.host_network_dir, "data")
1047+
10371048
@property
10381049
def logfile(self) -> str:
10391050
filename = f"{self.network}.log"
10401051
return os.path.join(self.logs_dir, filename)
10411052

1053+
@property
1054+
def host_logfile(self) -> str:
1055+
filename = f"{self.network}.log"
1056+
return os.path.join(self.host_logs_dir, filename)
1057+
10421058
@property
10431059
def dumpfile(self) -> str:
10441060
filename = f"config.sh"
10451061
return os.path.join(self.logs_dir, filename)
10461062

1063+
@property
1064+
def host_dumpfile(self) -> str:
1065+
filename = f"config.sh"
1066+
return os.path.join(self.host_logs_dir, filename)
1067+
10471068
def dump(self) -> None:
10481069
"""Dump xud-docker configurations as bash key-value file in logs_dir"""
10491070
prefix = "XUD_DOCKER"
@@ -1134,5 +1155,6 @@ def dump_node_attr(node: str, attr: str) -> None:
11341155
# dump_node_attr(node, "cex_api_secret")
11351156
dump_node_attr(node, "margin")
11361157

1137-
def expand_path(self, value) -> str:
1138-
pass
1158+
@property
1159+
def dev_mode(self) -> bool:
1160+
return self.args.dev

images/utils/launcher/node/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def create_docker_network(self):
211211

212212
def get_service(self, name: str) -> Node:
213213
try:
214-
return self.valid_nodes[name]
214+
return self.nodes[name]
215215
except KeyError as e:
216216
raise ServiceNotFound(name) from e
217217

@@ -296,7 +296,8 @@ def update(self) -> None:
296296
reply = yes_or_no(
297297
"A new version is available. Would you like to upgrade (Warning: this may restart your environment and cancel all open orders)?")
298298
if reply == "yes":
299-
self.image_manager.update_images()
299+
for img in pulls:
300+
img.pull()
300301

301302
b1 = len(pulls) == 0
302303
b2 = functools.reduce(lambda r, item: r and item == "NONE", containers.values(), True)

images/utils/launcher/node/base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,22 +264,24 @@ def exec(self, command: str) -> Tuple[int, str]:
264264
exit_code, output = self.container.exec_run(command)
265265
return exit_code, output.decode()
266266

267-
def cli(self, command: str, exception=False) -> None:
267+
def cli(self, command: str, exception=False, parse_output=None) -> None:
268268
if self.mode != "native":
269269
return
270270

271271
try:
272272
full_cmd = "%s %s" % (self._cli, command)
273+
logger.debug("[Execute] %s (interactive)", full_cmd)
273274
# FIXME use blocking docker client here
274275
output = exec_command(self.client.api, self.container_name, full_cmd)
275-
logger.debug("[Execute] %s (interactive)\n%s", full_cmd, output)
276276
try:
277277
self.extract_exception(command, output)
278278
except KeyboardInterrupt:
279279
raise
280280
except:
281281
if exception:
282282
raise
283+
if parse_output:
284+
parse_output(output)
283285
except docker.errors.NotFound:
284286
# FIXME use self.container
285287
raise ContainerNotFound(self.name)

images/utils/launcher/node/image.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ def get_update_action(self) -> str:
280280
logger.info("Image %s: status=%s, action=%s", self.name, status, action)
281281
return action
282282

283+
def pull(self):
284+
print("Pulling %s..." % self.pull_image)
285+
repo, tag = self.pull_image.split(":")
286+
output = self.client.api.pull(repo, tag=tag, stream=True, decode=True)
287+
print_status(output)
288+
283289

284290
class ImageManager:
285291
config: Config
@@ -360,13 +366,3 @@ def check_for_updates(self) -> Dict[Image, str]:
360366
print("WARNING: %s" % e)
361367

362368
return result
363-
364-
def update_images(self) -> None:
365-
for image in self.images.values():
366-
status = image.status
367-
pull_image = image.pull_image
368-
if status in ["LOCAL_MISSING", "LOCAL_OUTDATED"]:
369-
print("Pulling %s..." % pull_image)
370-
repo, tag = pull_image.split(":")
371-
output = self.client.api.pull(repo, tag=tag, stream=True, decode=True)
372-
print_status(output)

0 commit comments

Comments
 (0)