This commit adds a new command, 'craton device-list', to support the
endpoint /v1/devices. Currently the endpoint only supports GET requests.
The command supports filtering by cloud, cell, region, parent and active
status. In addition, where a parent is specified, it is also possible to
request descendants.
The API response body is of the form:
{
"devices: {
"hosts": [
],
"network-devices": [
],
},
"links": [
],
}
This object differs, from the other response bodies that return
collections, in that devices is not an array but is instead an object
whose values are arrays. This difference has necessitated modifying the
list and pagination functionality to support nested data.
Change-Id: I7cdec9935a360dae3910802f210ab9341ef7a696
Closes-bug: 1668705
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
"""Devices manager code."""
|
|
from cratonclient import crud
|
|
|
|
|
|
class Device(crud.Resource):
|
|
"""Representation of a Device."""
|
|
|
|
pass
|
|
|
|
|
|
class DeviceManager(crud.CRUDClient):
|
|
"""A manager for devices."""
|
|
|
|
key = 'device'
|
|
base_path = '/devices'
|
|
resource_class = Device
|
|
|
|
def list(self, **kwargs):
|
|
"""Generate the items from this endpoint."""
|
|
return super(DeviceManager, self).list(nested=True, **kwargs)
|
|
|
|
DEVICE_FIELDS = {
|
|
'id': 'ID',
|
|
'project_id': 'Project ID',
|
|
'cloud_id': 'Cloud ID',
|
|
'region_id': 'Region ID',
|
|
'cell_id': 'Cell ID',
|
|
'parent_id': 'Parent ID',
|
|
'name': 'Name',
|
|
'ip_address': 'IP Address',
|
|
'device_type': 'Device Type',
|
|
'note': 'Note',
|
|
'created_at': 'Created At',
|
|
'updated_at': 'Updated At'
|
|
}
|