Skip to content
Snippets Groups Projects
Commit 8e898979 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Device component:

- Added logic to auto-enable devices when Automation component is not deployed
- Updated retrieval of device controller
parent 089e08f7
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!107Service RecomputeConnections RPC method, Device Controller node pointer and Exclude Constraint
...@@ -12,9 +12,11 @@ ...@@ -12,9 +12,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import grpc, logging, time import grpc, logging, os, time
from typing import Dict from typing import Dict
from prometheus_client import Histogram from prometheus_client import Histogram
from common.Constants import ServiceNameEnum
from common.Settings import ENVVAR_SUFIX_SERVICE_HOST, get_env_var_name
from common.method_wrappers.Decorator import MetricTypeEnum, MetricsPool, safe_and_metered_rpc_method from common.method_wrappers.Decorator import MetricTypeEnum, MetricsPool, safe_and_metered_rpc_method
from common.method_wrappers.ServiceExceptions import NotFoundException, OperationFailedException from common.method_wrappers.ServiceExceptions import NotFoundException, OperationFailedException
from common.proto.context_pb2 import ( from common.proto.context_pb2 import (
...@@ -121,7 +123,15 @@ class DeviceServiceServicerImpl(DeviceServiceServicer): ...@@ -121,7 +123,15 @@ class DeviceServiceServicerImpl(DeviceServiceServicer):
t9 = time.time() t9 = time.time()
device.device_operational_status = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED automation_service_host = get_env_var_name(ServiceNameEnum.AUTOMATION, ENVVAR_SUFIX_SERVICE_HOST)
environment_variables = set(os.environ.keys())
if automation_service_host in environment_variables:
# Automation component is deployed; leave devices disabled. Automation will enable them.
device.device_operational_status = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_DISABLED
else:
# Automation is not deployed; assume the device is ready while onboarding and set them as enabled.
device.device_operational_status = DeviceOperationalStatusEnum.DEVICEOPERATIONALSTATUS_ENABLED
device_id = context_client.SetDevice(device) device_id = context_client.SetDevice(device)
t10 = time.time() t10 = time.time()
......
...@@ -79,11 +79,13 @@ def check_no_endpoints(device_endpoints) -> None: ...@@ -79,11 +79,13 @@ def check_no_endpoints(device_endpoints) -> None:
'interrogation of the physical device.') 'interrogation of the physical device.')
def get_device_controller_uuid(device : Device) -> Optional[str]: def get_device_controller_uuid(device : Device) -> Optional[str]:
for config_rule in device.device_config.config_rules: controller_uuid = device.controller_id.device_uuid.uuid
if config_rule.WhichOneof('config_rule') != 'custom': continue if len(controller_uuid) > 0: return controller_uuid
if config_rule.custom.resource_key != '_controller': continue #for config_rule in device.device_config.config_rules:
device_controller_id = json.loads(config_rule.custom.resource_value) # if config_rule.WhichOneof('config_rule') != 'custom': continue
return device_controller_id['uuid'] # if config_rule.custom.resource_key != '_controller': continue
# device_controller_id = json.loads(config_rule.custom.resource_value)
# return device_controller_id['uuid']
return None return None
def populate_endpoints( def populate_endpoints(
...@@ -142,11 +144,12 @@ def populate_endpoints( ...@@ -142,11 +144,12 @@ def populate_endpoints(
# Sub-devices should not have a driver assigned. Instead, they should have # Sub-devices should not have a driver assigned. Instead, they should have
# a config rule specifying their controller. # a config rule specifying their controller.
#_sub_device.device_drivers.extend(resource_value['drivers']) # pylint: disable=no-member #_sub_device.device_drivers.extend(resource_value['drivers']) # pylint: disable=no-member
controller_config_rule = _sub_device.device_config.config_rules.add() #controller_config_rule = _sub_device.device_config.config_rules.add()
controller_config_rule.action = ConfigActionEnum.CONFIGACTION_SET #controller_config_rule.action = ConfigActionEnum.CONFIGACTION_SET
controller_config_rule.custom.resource_key = '_controller' #controller_config_rule.custom.resource_key = '_controller'
controller = {'uuid': device_uuid, 'name': device_name} #controller = {'uuid': device_uuid, 'name': device_name}
controller_config_rule.custom.resource_value = json.dumps(controller, indent=0, sort_keys=True) #controller_config_rule.custom.resource_value = json.dumps(controller, indent=0, sort_keys=True)
_sub_device.controller_id.device_uuid.uuid = device_uuid
new_sub_devices[_sub_device_uuid] = _sub_device new_sub_devices[_sub_device_uuid] = _sub_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