def create(ctx, name, sensors, elements): """Create a label. Creates a label with a given NAME and an (optional) list of sensors and elements associated with that label. """ client = ctx.find_object(Client) sensors = sensors or [] if sensors: all_sensors = Sensor.all(client) sensors = [ Sensor.lookup(client, id, resources=all_sensors) for id in sensors ] elements = elements or [] if elements: all_elements = Element.all(client) elements = [ Element.lookup(client, id, resources=all_elements) for id in elements ] label = Label.create(client, attributes={'name': name}) if sensors: label.update_sensors(sensors) if elements: label.update_elements(elements) label = Label.find(client, label.id, include=label_includes) Label.display(client, [label], include=label_includes)
def list(client, sensor, mac, **kwargs): """List sensors. Lists information for a given SENSOR or all sensors in the organization. """ if sensor: sensors = [Sensor.lookup(client, sensor, mac=mac)] else: sensors = Sensor.all(client) Sensor.display(client, sensors, **kwargs)
def update(client, label, name, **kwargs): label = Label.lookup(client, label) if name: label.update(name=name) all_sensors = Sensor.all(client) add_sensors = kwargs.pop('add', None) or [] remove_sensors = kwargs.pop('remove', None) or [] sensors = [Sensor.lookup(client, s, resources=all_sensors) for s in add_sensors] if sensors: label.add_sensors(sensors) sensors = [Sensor.lookup(client, s, resources=all_sensors) for s in remove_sensors] if sensors: label.remove_sensors(sensors) include = [Sensor] label = Label.find(client, label.id, include=include) Label.display(client, [label], include=include)