Skip to content
Snippets Groups Projects
Commit ccc8604b authored by Finn's avatar Finn
Browse files

Add Device class.

parent 3f6cf1b7
No related branches found
No related tags found
Loading
# Copyright (C) 2018 Bloomberg LP
#
# 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.
class Device:
def __init__(self, properties=None):
""" Creates devices available to the worker
The first device is know as the Primary Device - the revice which
is running a bit and responsible to actually executing commands.
All other devices are known as Attatched Devices and must be controlled
by the Primary Device.
"""
self.__properties = {}
self.__name = str(uuid.uuid4())
if properties:
for k, v in properties.items():
if k == 'os':
self.__properties[k] = v
elif k == 'docker':
if v not in ('True', 'False'):
raise ValueError('Value not supported: [{}]'.format(v))
self.__properties[k] = v
else:
raise KeyError('Key not supported: [{}]'.format(k))
@property
def name(self):
return self.__name
@property
def properties(self):
return self.__properties
def get_pb2(self):
device = worker_pb2.Device(handle=self._name)
property_message = worker_pb2.Device.Property()
for k, v in self._properties.items():
property_message.key = k
property_message.value = v
device.properties.extend([property_message])
return device
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment