Creating custom views

A view (or filter) determines what data is returned by a PyLXCA inventory command. The default views for each command are defined in the <python_install_dir>/site-packages/pylxca-1.0-py2.7.egg/pylxca/pylxca_cmd/lxca_filters.xml file. You can add your own custom views.

In the lxca_filters.xml file, all default and custom views are included under the <filters> tag. You can also add custom views under this tag for any command that returns inventory data. In the following example, there is a filter for the chassis command named default. This is the default view that is used if the --view parameter is not specified. The following example also has a filter for the cmm command named location_view To use this view, specify --view location_view when you run the command.
   <chassis name="default">...</chassis>
   <chassis name="health_view">...</chassis>
   <cmm name="location_view">...</cmm>
Under each command tag (such as <chassis>) are the fields that you want returned for that view. You can choose to return any response-body field that the inventory REST API supports for the device type. In the following example, Name and ChassisLocation are the labels that are returned by the chassis command, and name and location are the names of the response-body fields in the GET /chassis/{UUID_list} request. If the field is an object, you must specify type="object” in the tag and then list the fields in the object that you want to return under the tag.
   <chassis name="location_view">
      <ChassisLocation name="location" type="object">
  • If you do not specify type=”object” for objects and arrays of objects, the returned data is null.

  • The response-body field names are case-sensitive.

The following example is returned if you run the chassis command using the location_view filter that is defined previously:
Name: SN#Y031BG19H006
    Rack: []
    Room: []
Contact: None
Type: Chassis
IPAddresses: [u'', u'fe80::5ef3:fcff:fe25:e1dd', u'fd55:faaf:e1ab:2021:5ef3:fcff:fe25:e1dd']
HostName: SN#Y031BG19H006

Use the following table to find the supported response-body fields for each command: