def _get_all_properties(self, prop_name): request = DescribeProperties.from_other(self, Property=[prop_name]) properties = [] for prop_dict in request.main().get('properties') or []: properties.append(_build_property(prop_dict['name'], prop_dict.get('value'))) return properties
def _get_all_properties(self, prop_name): request = DescribeProperties.from_other(self, Property=[prop_name]) properties = [] for prop_dict in request.main().get('properties') or []: properties.append( _build_property(prop_dict['name'], prop_dict.get('value'))) return properties
def main(self): # FIXME: This doesn't handle empty property values. if self.args.get('dump'): prop_name = self.args.get('prop_pairs')[0][0] self.log.info('dumping property value %s', prop_name) prop = self._get_unique_property(prop_name) formatter = self._get_formatter() print formatter.dumps(prop.value).strip() elif self.args.get('edit'): prop_name = self.args.get('prop_pairs')[0][0] self.log.info('editing property value %s', prop_name) prop = self._get_unique_property(prop_name) has_changed = self.edit_interactively(prop) if has_changed: self.log.info('setting property value %s', prop_name) self._set_property(prop_name, value=prop.dumps()) else: print >> sys.stderr, prop_name, 'is unchanged' else: for key, val in self.args.get('prop_pairs') or [(None, None)]: if key == 'euca': # DescribeProperties doesn't work on the magical, # groovy code-injecting "euca" property, so we have # to handle input and output in one shot. # # We don't do this all the time is case the value # we chose doesn't actually get set for some reason. self.log.info('handling one-shot property "euca"') req = ModifyPropertyValue.from_other(self, Name=key, Value=val) response = req.main() print response.get('value') continue if val is not None: self.log.info('setting property value %s: %s', key, val) self._set_property(key, value=val) if val is None and self.args.get('reset'): self.log.info('resetting property value %s', key) self._set_property(key, reset=True) self.log.info('showing property value %s', key) req = DescribeProperties.from_other(self, Property=[key]) response = req.main() for prop_dict in response.get('properties') or []: if self.args.get('show_defaults'): prop = _build_property(prop_dict.get('name'), prop_dict.get('defaultValue')) elif self.args.get('show_descriptions'): # Descriptions are plain text, so force plain # text handling. prop = _build_property(prop_dict.get('name'), prop_dict.get('description'), prop_type=_Property) else: prop = _build_property(prop_dict.get('name'), prop_dict.get('value')) if not self.args.get('suppress_all'): prop.print_( suppress_name=self.args.get('suppress_name'), force=self.args.get('all_types'))
def _get_all_properties(self, prop_name, prop_type=None): # Note that prop_type must currently be able to parse *everything*, # so it's probably only safe with the generic _Property class. request = DescribeProperties.from_other(self, Property=[prop_name]) properties = [] for prop_dict in request.main().get('properties') or []: properties.append(_build_property(prop_dict['name'], prop_dict.get('value'), prop_type=prop_type, log=self.log)) return properties
def main(self): # FIXME: This doesn't handle empty property values. if self.args.get('dump'): prop_name = self.args.get('prop_pairs')[0][0] self.log.info('dumping property value %s', prop_name) prop = self._get_unique_property(prop_name) formatter = self._get_formatter() print formatter.dumps(prop.value).strip() elif self.args.get('edit'): prop_name = self.args.get('prop_pairs')[0][0] self.log.info('editing property value %s', prop_name) prop = self._get_unique_property(prop_name) has_changed = self.edit_interactively(prop) if has_changed: self.log.info('setting property value %s', prop_name) self._set_property(prop_name, value=prop.dumps()) else: print >> sys.stderr, prop_name, 'is unchanged' else: for key, val in self.args.get('prop_pairs') or [(None, None)]: if val is not None: self.log.info('setting property value %s: %s', key, val) self._set_property(key, value=val) if val is None and self.args.get('reset'): self.log.info('resetting property value %s', key) self._set_property(key, reset=True) self.log.info('showing property value %s', key) req = DescribeProperties.from_other(self, Property=[key]) response = req.main() for prop_dict in response.get('properties') or []: prop = _build_property(prop_dict.get('name'), prop_dict.get('value')) if not self.args.get('suppress_all'): prop.print_( suppress_name=self.args.get('suppress_name'), force=self.args.get('all_types'))