def Prints(self, data, output='table', kind=None): if kind is None and len(data) > 0: kind = data[0]["cm"]["kind"] if output in ["flat", "table"]: order = self.p.output[kind]['order'] # not pretty header = self.p.output[kind]['header'] # not pretty if 'humanize' in self.p.output[kind]: humanize = self.p.output[kind]['humanize'] else: humanize = None _output = Printer.flatwrite(data, sort_keys=["name"], order=order, header=header, output=output, humanize=humanize) else: _output = Printer.write(data, output=output) return _output
def test_001_print(self): HEADING() pprint(self.data) table = Printer.flatwrite( self.data, sort_keys=["name"], order=["name", "address.street", "address.city"], header=["Name", "Street", "City"], ) print(table) assert "Name" in str(table)
def create(self, **kwargs): arguments = dotdict(kwargs) name = arguments.name cloud = arguments.cloud if name is None: name_generator = Name() vms = [str(name_generator)] else: vms = self.expand(name) # # Step 0, find the cloud # variables = Variables() if cloud is None: arguments.cloud = cloud = variables['cloud'] # Step 1. iterate through the names to see if they already exist in # the DB and fail if one of them already exists database = CmDatabase() defaults = Config()[f"cloudmesh.cloud.{cloud}.default"] duplicates = [] for vm in vms: query = {"name": vm} duplicates += database.find(collection=f'{cloud}-node', query=query) database.close_client() if len(duplicates) > 0: print( Printer.flatwrite(duplicates, order=['cm.name', 'cm.cloud'], header=['Name', 'Cloud'], output='table')) raise Exception("these vms already exists") # Step 2. identify the image and flavor from kwargs and if they do # not exist read them for that cloud from the yaml file if arguments.image is None: arguments.image = self.find_attribute('image', [variables, defaults]) if arguments.image is None: raise ValueError("image not specified") if arguments.group is None: arguments.group = self.find_attribute('group', [variables, defaults]) if arguments.group is None: arguments.group = "default" if arguments.size is None: arguments.size = self.find_attribute('size', [variables, defaults]) if arguments.size is None: raise ValueError("size not specified") # Step 3: use the create command to create the vms # created = self.loop(vms, self.p.create, **arguments) arguments['name'] = vms created = self.loop(self._create, **arguments) VERBOSE(created) self.list() return created