@raise_if_no_orchestrator([OrchFeature.HOST_LABEL_ADD, OrchFeature.HOST_LABEL_REMOVE])
@handle_orchestrator_error('host')
+ @EndpointDoc('',
+ parameters={
+ 'hostname': (str, 'Hostname'),
+ 'labels': ([str], 'Host Labels'),
+ },
+ responses={200: None, 204: None})
def set(self, hostname: str, labels: List[str]):
"""
Update the specified host.
"""
orch = OrchClient.instance()
host = get_host(hostname)
+ # only allow List[str] type for labels
+ if not isinstance(labels, list):
+ raise DashboardException(
+ msg='Expected list of labels. Please check API documentation.',
+ http_status_code=400,
+ component='orchestrator')
current_labels = set(host['labels'])
# Remove labels.
remove_labels = list(current_labels.difference(set(labels)))
\ name of the host to be processed.\n :param labels: List of labels.\n\
\ "
parameters:
- - in: path
+ - description: Hostname
+ in: path
name: hostname
required: true
schema:
schema:
properties:
labels:
- type: string
+ description: Host Labels
+ items:
+ type: string
+ type: array
required:
- labels
type: object
'200':
content:
application/vnd.ceph.api.v1.0+json:
- type: object
+ schema:
+ properties: {}
+ type: object
description: Resource updated.
'202':
content:
fake_client.hosts.remove_label.assert_called_once_with('node0', 'aaa')
fake_client.hosts.add_label.assert_called_once_with('node0', 'ccc')
+ # return 400 if type other than List[str]
+ self._put('{}/node0'.format(self.URL_HOST), {'labels': 'ddd'})
+ self.assertStatus(400)
+
@mock.patch('dashboard.controllers.host.time')
def test_identify_device(self, mock_time):
url = '{}/host-0/identify_device'.format(self.URL_HOST)