2020
2121import coloredlogs # type: ignore[import-untyped]
2222import distro
23- from semantic_version import ( SimpleSpec , # type: ignore[import-untyped]
24- Version )
23+ from semantic_version import SimpleSpec # type: ignore[import-untyped]
24+ from semantic_version import Version
2525
2626from .config import read_config
2727from .config .config import (ARCH_AARCH64 , ARCH_AMD , ARCH_ARM , ARCH_PPC ,
2828 ARCH_S390X , ARCH_X86_64 )
2929from .installer import (delete_cluster , download_installer , install_cluster ,
3030 storage )
31+ from .installer .downloader .image import download_rhcos_image , get_url
3132
3233
3334def _identity (in_attr : str ) -> str :
@@ -66,8 +67,6 @@ def _read_list(in_str: str) -> list[str]:
6667 'worker_flavor' : {'help' : 'flavor of worker node' },
6768 'worker_replicas' : {'help' : 'Number of replicas of worker nodes' , 'type' : int },
6869 'certificate_bundle_file' : {'help' : 'CA bundle file' },
69- 'images_dir' : {'help' : 'Directory where images should be stored' , 'type' : str ,
70- 'default' : 'images' },
7170 'skip_clean' : {'help' : 'Skip clean when installation fails' , 'action' : 'store_true' },
7271 'enable_fips' : {'help' : 'Enable fips mode to the cluster' , 'action' : 'store_true' },
7372 },
@@ -174,10 +173,22 @@ def _exec_delete_cluster(args):
174173
175174
176175def _exec_download_insaller (args ):
176+ args .cluster_name = ""
177+ args .installer = None
177178 conf = _merge_dictionaries (args )
178179 print (conf ['installer' ])
179180
180181
182+ def _exec_download_rhcos_image (args ):
183+ args .cluster_name = ""
184+ args .installer = None
185+ args .enable_fips = None
186+ conf = _merge_dictionaries (args )
187+
188+ url , version = get_url (conf ['installer' ])
189+ print (download_rhcos_image (args .images_dir , url , version ))
190+
191+
181192def _get_helper (parser : argparse .ArgumentParser ):
182193 def printer (unused_conf ):
183194 print ("Operation not set, please specify either install or clean!" )
@@ -186,12 +197,22 @@ def printer(unused_conf):
186197 return printer
187198
188199
189- def _create_commons () -> argparse .ArgumentParser :
190- commons = argparse .ArgumentParser (add_help = False )
200+ def _add_cluster_commons (commons : argparse .ArgumentParser ) -> argparse .ArgumentParser :
191201 common_arguments : list [tuple [list [str ], dict ]] = [
192202 (['--cluster-name' ], dict (required = True , help = 'Name of the cluster' )),
193203 (['--installer' ], dict (required = False ,
194204 help = 'Executable binary of openshift install cli' , default = None )),
205+ (['--skip-git' ], dict (help = 'When set, the persistance will be skipped' ,
206+ action = 'store_true' )),
207+ ]
208+ for args , kwargs in common_arguments :
209+ commons .add_argument (* args , ** kwargs )
210+ return commons
211+
212+
213+ def _create_commons () -> argparse .ArgumentParser :
214+ commons = argparse .ArgumentParser (add_help = False )
215+ common_arguments : list [tuple [list [str ], dict ]] = [
195216 (['--installer-version' ], dict (help = 'Version of downloader to be downloaded' ,
196217 default = 'latest' , type = str )),
197218 (['--installer-arch' ], dict (help = 'Architecture of downloader to be downloaded' ,
@@ -204,8 +225,8 @@ def _create_commons() -> argparse.ArgumentParser:
204225 default = 'prod' )),
205226 (['--installers-dir' ], dict (help = 'Folder where installers are stored' ,
206227 required = False , default = 'installers' )),
207- (['--skip-git ' ], dict (help = 'When set, the persistance will be skipped ' ,
208- action = 'store_true ' )),
228+ (['--images-dir ' ], dict (help = 'Directory where images should be stored ' ,
229+ required = False , default = 'images ' )),
209230 (['-v' , '--verbose' ], dict (help = 'Increase verbosity level' , action = 'store_true' )),
210231 ]
211232 for args , kwargs in common_arguments :
@@ -216,23 +237,29 @@ def _create_commons() -> argparse.ArgumentParser:
216237def _setup_parser () -> argparse .ArgumentParser :
217238 commons = _create_commons ()
218239
240+ cluster_commons = argparse .ArgumentParser (add_help = False , parents = [commons ])
241+ cluster_commons = _add_cluster_commons (cluster_commons )
242+
219243 parser = argparse .ArgumentParser ("osia" )
220244 parser .set_defaults (func = _get_helper (parser ))
221245 sub_parsers = parser .add_subparsers ()
222246
223- install = sub_parsers .add_parser ('install' , help = 'Install new cluster' , parents = [commons ])
247+ install = sub_parsers .add_parser ('install' , help = 'Install new cluster' , parents = [cluster_commons ])
224248
225249 for arg , value in sorted ({k : v for _ , x in ARGUMENTS .items () for k , v in x .items ()}.items ()):
226250 install .add_argument (f"--{ arg .replace ('_' , '-' )} " ,
227251 ** {k : v for k , v in value .items () if k != 'proc' })
228252 install .set_defaults (func = _exec_install_cluster )
229253
230- clean = sub_parsers .add_parser ('clean' , help = 'Remove cluster' , parents = [commons ])
254+ clean = sub_parsers .add_parser ('clean' , help = 'Remove cluster' , parents = [cluster_commons ])
231255 clean .set_defaults (func = _exec_delete_cluster )
232256
233- download = sub_parsers .add_parser ('download-installer' , help = 'Download installer' , parents = [commons ])
234- download .add_argument ("--enable-fips" , action = 'store_true' )
235- download .set_defaults (func = _exec_download_insaller )
257+ installer = sub_parsers .add_parser ('download-installer' , help = 'Download installer' , parents = [commons ])
258+ installer .add_argument ("--enable-fips" , help = 'Enable fips mode to the cluster' , action = 'store_true' )
259+ installer .set_defaults (func = _exec_download_insaller )
260+
261+ rhcos_image = sub_parsers .add_parser ('download-rhcos-image' , help = 'Download rhcos image' , parents = [commons ])
262+ rhcos_image .set_defaults (func = _exec_download_rhcos_image )
236263
237264 return parser
238265
0 commit comments