2
2
import sys
3
3
import json
4
4
import signal
5
- import shutil
6
5
import tempfile
7
6
import logging
8
7
import argparse
9
8
import subprocess
10
9
import warnings
10
+
11
+ import library .python .resource as rs
12
+
11
13
from urllib3 .exceptions import HTTPWarning
12
14
13
15
from ydb .tools .cfg .walle import NopHostsInformationProvider
@@ -499,7 +501,42 @@ def ssh_args():
499
501
metavar = "SSH_USER" ,
500
502
default = current_user ,
501
503
help = "user for ssh interaction with slice. Default value is $USER "
502
- "(which equals {user} now)" .format (user = current_user ),
504
+ "(which equals {user} now)" .format (user = current_user ),
505
+ )
506
+ return args
507
+
508
+
509
+ def databases_config_path_args ():
510
+ args = argparse .ArgumentParser (add_help = False )
511
+ args .add_argument (
512
+ "--databases-config" ,
513
+ metavar = "DATABASES_CONFIG" ,
514
+ default = "" ,
515
+ required = False ,
516
+ help = "Path to file with databases configuration" ,
517
+ )
518
+ return args
519
+
520
+
521
+ def cluster_type_args ():
522
+ args = argparse .ArgumentParser (add_help = False )
523
+ args .add_argument (
524
+ "--cluster-type" ,
525
+ metavar = "CLUSTER_TYPE" ,
526
+ required = True ,
527
+ help = "Erasure type for slice" ,
528
+ choices = ["block-4-2-8-nodes" , "mirror-3-dc-3-nodes-in-memory" , "mirror-3-dc-3-nodes" , "mirror-3-dc-9-nodes" ],
529
+ )
530
+ return args
531
+
532
+
533
+ def output_file ():
534
+ args = argparse .ArgumentParser (add_help = False )
535
+ args .add_argument (
536
+ "--output-file" ,
537
+ metavar = "OUTPUT_FILE" ,
538
+ required = False ,
539
+ help = "File to save cluster configuration" ,
503
540
)
504
541
return args
505
542
@@ -583,7 +620,7 @@ def dispatch_run(func, args, walle_provider):
583
620
584
621
if clear_tmp :
585
622
logger .debug ("remove temp dirs '%s'" , temp_dir )
586
- shutil .rmtree (temp_dir )
623
+ # shutil.rmtree(temp_dir)
587
624
588
625
589
626
def add_install_mode (modes , walle_provider ):
@@ -593,9 +630,17 @@ def _run(args):
593
630
mode = modes .add_parser (
594
631
"install" ,
595
632
conflict_handler = 'resolve' ,
596
- parents = [direct_nodes_args (), cluster_description_args (), binaries_args (), component_args (), log_args (), ssh_args ()],
633
+ parents = [
634
+ direct_nodes_args (),
635
+ cluster_description_args (),
636
+ binaries_args (),
637
+ component_args (),
638
+ log_args (),
639
+ ssh_args (),
640
+ # databases_config_path_args(),
641
+ ],
597
642
description = "Full installation of the cluster from scratch. "
598
- "You can use --hosts to specify particular hosts. But it is tricky."
643
+ "You can use --hosts to specify particular hosts. But it is tricky." ,
599
644
)
600
645
mode .set_defaults (handler = _run )
601
646
@@ -672,7 +717,7 @@ def _run(args):
672
717
"clear" ,
673
718
parents = [direct_nodes_args (), cluster_description_args (), binaries_args (), component_args (), ssh_args ()],
674
719
description = "Stop all kikimr instances at the nodes, format all kikimr drivers, shutdown dynamic slots. "
675
- "And don't start nodes afrer it. "
720
+ "And don't start nodes after it. "
676
721
"Use --hosts to specify particular hosts."
677
722
)
678
723
mode .set_defaults (handler = _run )
@@ -686,12 +731,42 @@ def _run(args):
686
731
"format" ,
687
732
parents = [direct_nodes_args (), cluster_description_args (), binaries_args (), component_args (), ssh_args ()],
688
733
description = "Stop all kikimr instances at the nodes, format all kikimr drivers at the nodes, start the instances. "
689
- "If you call format for all cluster, you will spoil it. "
690
- "Additional dynamic configuration will required after it. "
691
- "If you call format for few nodes, cluster will regenerate after it. "
692
- "Use --hosts to specify particular hosts."
734
+ "If you call format for all cluster, you will spoil it. "
735
+ "Additional dynamic configuration will required after it. "
736
+ "If you call format for few nodes, cluster will regenerate after it. "
737
+ "Use --hosts to specify particular hosts." ,
738
+ )
739
+ mode .set_defaults (handler = _run )
740
+
693
741
742
+ def add_sample_config_mode (modes ):
743
+ def _run (args ):
744
+ cluster_type = args .cluster_type
745
+ template_path = ""
746
+ if cluster_type == "block-4-2-8-nodes" :
747
+ template_path = "/ydbd_slice/baremetal/templates/block-4-2-8-nodes.yaml"
748
+ elif cluster_type == "mirror-3-dc-3-nodes-in-memory" :
749
+ pass
750
+ elif cluster_type == "mirror-3-dc-3-nodes" :
751
+ template_path = "/ydbd_slice/baremetal/templates/mirror-3-dc-3-nodes.yaml"
752
+ elif cluster_type == "mirror-3-dc-9-nodes" :
753
+ template_path = "/ydbd_slice/baremetal/templates/mirror-3-dc-9-nodes.yaml"
754
+ else :
755
+ raise "Unreachable code" # TODO(shmel1k@): improve error
756
+
757
+ f = rs .find (template_path ).decode ()
758
+ if args .output_file is not None and args .output_file != "" :
759
+ with open (args .output_file , "w+" ) as f1 :
760
+ f1 .write (f )
761
+ else :
762
+ print (f )
763
+
764
+ mode = modes .add_parser (
765
+ "sample-config" ,
766
+ parents = [cluster_type_args (), output_file ()],
767
+ description = "Generate default mock-configuration for provided cluster-type"
694
768
)
769
+
695
770
mode .set_defaults (handler = _run )
696
771
697
772
@@ -1205,6 +1280,8 @@ def main(walle_provider=None):
1205
1280
add_clear_mode (modes , walle_provider )
1206
1281
add_format_mode (modes , walle_provider )
1207
1282
add_explain_mode (modes , walle_provider )
1283
+ add_sample_config_mode (modes )
1284
+
1208
1285
add_docker_build_mode (modes )
1209
1286
add_kube_generate_mode (modes )
1210
1287
add_kube_install_mode (modes )
0 commit comments