def find_elements(self, session): try: for a in self.args: obj_spec = ObjectSpec.parse(a, expected=(ElementName, ElementQuery)) for inst in obj_spec.resolve(session): yield inst except UnknownEntityError, e: raise CommandExecutionError(self, str(e))
def execute(self, session): obj_query = ObjectSpec.parse(self.args[0], expected=ElementQuery) if self.option.print_sql: print obj_query.create_query(session) return for inst in session.query_instances(obj_query): print inst
def validate(self): if len(self.args) < 1: raise CommandArgumentError(self, "Must specifiy a Subnet") self.oname = ObjectSpec.parse(self.args[0], expected=ElementName) if len(self.args) == 2: self.count = int(self.args[1]) else: self.count = 1
def execute(self, session): specs = [ ObjectSpec.parse(arg) for arg in self.args ] spec_types = set([ type(spec) for spec in specs ]) # make sure all the ObjectSpecs are of the same type. if len(spec_types) > 1: self.log.error("Cannot mix ObjectSpec types in single command: %s" % spec_types) raise CommandArgumentError(self, "More than two types specified: " ) object_spec_type = spec_types.pop() # Use the specific ObjectSpec class to properly # find the results of the each ObjectSpec result = list(self.resolve_all_specs(session, specs)) # EntityName if object_spec_type is EntityName: display_proc = result[0].entity_display_processor() result = display_proc.show(result[0]) # ElementQuery, EntityQuery - Optionally dump as a set of forms if object_spec_type in (EntityQuery, ElementQuery) and self.option.form_output: processor = ElementFormProcessor.create(session, show_headers=False) result = processor.to_form(result) # ElementName - display using Element Specific method if object_spec_type is ElementName: assert len(result) == 1 and isinstance(result[0], Element), "ElementName type failure" display_proc = result[0].display_processor() result = display_proc.show(result[0]) if object_spec_type in (AttributeName,): result = list(self._format_attribute(result)) if not self.cli: return result if isinstance(result, basestring): print result elif isinstance(result, (list, tuple, types.GeneratorType)): for x in result: print str(x) else: raise RuntimeError("spec types returned invalid result: %s" % type(result))
def execute(self, session): oname = ObjectSpec.parse(self.args[0], expected=ElementName) assert oname.entity_name == 'Rack', 'Object spec must have an EntityName of Rack' rack = session.find_element(oname) display_proc = rack.display_processor() string_list = list( display_proc.show(rack) ) if not self.cli: return string_list for line in string_list: print line
def execute(self, session): (interface_name, ip_value) = self.args oname = ObjectSpec.parse(interface_name, expected=ElementName) if oname.entity_name != "Interface": raise CommandArgumentError(self, "Element must be of type Interface. Supplied: %s" % oname.entity_name) iface = session.resolve_element_spec(oname) if iface.address is not None and iface.address.value == ip_value: self.log.info("Ip is already set") return try: session.open_changeset() iface.address = IpAddress.create_resource(session, ip_value, iface) cs = session.submit_changeset() except ResourceCreationError, e: raise CommandExecutionError(self, str(e))