diff --git a/easycloud/core/metamanager.py b/easycloud/core/metamanager.py index 257ccaaee428d50e86f36f69080c4327a4b6c746..45120cd96464cccb78894cb48998a2163b3a20cc 100755 --- a/easycloud/core/metamanager.py +++ b/easycloud/core/metamanager.py @@ -155,14 +155,20 @@ class MetaManager(ABC): def print_all_images(self): """ - Print all available images + Print all available images dynamically based on the data available. """ - table_header = ["ID", "Name", "Image ID", "Status"] table_body = self._platform_list_all_images() - SimpleTUI.print_table(table_header, table_body) - if len(self.images) == 0: + + # Dinamicly building the header table with extracted params + if table_body: + table_header = ["Index", "Name", "ID", "Status"] + SimpleTUI.print_table(table_header, table_body) + if len(table_body) == 0: + SimpleTUI.info("There are no images available") + return len(table_body) + else: SimpleTUI.info("There are no images available") - return len(self.images) + return 0 @abstractmethod def _platform_list_all_images(self): @@ -187,12 +193,16 @@ class MetaManager(ABC): """ Print all instance types """ - table_header = ["ID", "Instance Type ID", "vCPUs", "Ram (GB)", "Disk (GB)"] table_body = self._platform_list_all_instance_types() - SimpleTUI.print_table(table_header, table_body) - if len(self.instance_types) == 0: + + if len(table_body) == 0: SimpleTUI.info("There are no instance types available") - return len(self.instance_types) + + # Sets the table header dynamically based on the number of columns in the table body + table_header = ["ID", "Instance Type Name", "vCPUs", "Ram (GB)", "Disk (GB)"] + SimpleTUI.print_table(table_header, table_body) + + return len(table_body) @abstractmethod def _platform_list_all_instance_types(self): @@ -380,6 +390,7 @@ class MetaManager(ABC): regex="^[a-zA-Z0-9_-]+$") if instance_name is None: return + # 2. Image image_index = SimpleTUI.list_dialog("Images available", self.print_all_images, @@ -387,6 +398,7 @@ class MetaManager(ABC): if image_index is None: return image = self.images[image_index - 1] + # 3. Instance Type instance_type_index = SimpleTUI.list_dialog("Instance types available", self.print_all_instance_types, @@ -394,9 +406,11 @@ class MetaManager(ABC): if instance_type_index is None: return instance_type = self.instance_types[instance_type_index - 1] + # 4. Optional steps (depending on the manager) and creation try: - if self._platform_create_new_instance(instance_name, image, instance_type, monitor_cmd_queue=self.monitor_cmd_queue): + if self._platform_create_new_instance(instance_name, image, instance_type, + monitor_cmd_queue=self.monitor_cmd_queue): SimpleTUI.msg_dialog("Instance creation", "Instance created!", SimpleTUI.DIALOG_SUCCESS) else: SimpleTUI.msg_dialog("Instance creation", "There was an error while creating this instance!\n",