from o2common.helper import o2logging
from o2dms.domain import commands
from o2ims.domain import commands as imscmd
-from o2ims.domain.subscription_obj import Message2SMO, RegistrationMessage
+from o2ims.domain.subscription_obj import Message2SMO, RegistrationMessage, \
+ NotificationEventEnum
from o2ims.domain.alarm_obj import AlarmEvent2SMO
logger = o2logging.get_logger(__name__)
datastr = m['data']
data = json.loads(datastr)
logger.info('OcloudChanged with cmd:{}'.format(data))
- cmd = imscmd.Register2SMO(data=RegistrationMessage(
- id=data['id'], eventtype=data['notificationEventType'],
- updatetime=data['updatetime']))
+ if data['notificationEventType'] == NotificationEventEnum.CREATE:
+ cmd = imscmd.Register2SMO(data=RegistrationMessage(
+ id=data['id'], eventtype=data['notificationEventType'],
+ updatetime=data['updatetime']))
+ elif data['notificationEventType'] == NotificationEventEnum.MODIFY:
+ ref = apibase + inventory_api_version
+ cmd = imscmd.PubMessage2SMO(data=Message2SMO(
+ id=data['id'], ref=ref,
+ eventtype=data['notificationEventType'],
+ updatetime=data['updatetime']),
+ type='OCloud')
bus.handle(cmd)
elif channel == 'AlarmEventChanged':
datastr = m['data']
data = json.loads(datastr)
logger.info('AlarmEventPurged with cmd:{}'.format(data))
cmd = imscmd.PurgeAlarmEvent(data=AlarmEvent2SMO(
- id=data['id'], eventtype=data['notificationEventType'],
+ id=data['id'], ref="", eventtype=data['notificationEventType'],
updatetime=data['updatetime']))
bus.handle(cmd)
else:
self._suppression_converter(event)))
return suppression_list
- @ staticmethod
+ @staticmethod
def _alarmconverter(alarm):
selected_keys = [
'alarm_id', 'alarm_state', 'entity_type_id', 'entity_instance_id',
uuid.NAMESPACE_URL, alarm.probable_cause)))
return alarm
- @ staticmethod
+ @staticmethod
def _eventconverter(event, clear=False):
selected_keys = [
'event_log_id', 'state', 'entity_type_id',
uuid.NAMESPACE_URL, event.probable_cause)))
return event
- @ staticmethod
+ @staticmethod
def _suppression_converter(event, clear=False):
selected_keys = [
'alarm_id', 'description', 'suppression_status',
setattr(event, 'timestamp', None)
return event
- @ staticmethod
+ @staticmethod
def _alarmeventhasher(event, state=''):
# The event model and the alarm model have different parameter name
# of the state. alarm model is alarm_state, event model is state.
'more than one system exists in the account.')
return isystems[0]
- @ staticmethod
+ @staticmethod
def _respoolconverter(res_pool):
setattr(res_pool, 'name', res_pool.region_name)
return res_pool
- @ staticmethod
+ @staticmethod
def _hostconverter(host):
selected_keys = [
"hostname", "personality", "id", "mgmt_ip", "mgmt_mac",
setattr(host, 'name', host.hostname)
return host
- @ staticmethod
+ @staticmethod
def _labelconverter(label):
selected_keys = [
"uuid", "label_key", "label_value", "host_uuid"
setattr(label, 'created_at', None)
return label
- @ staticmethod
+ @staticmethod
def _cpuconverter(cpu):
selected_keys = [
"cpu", "core", "thread", "allocated_function", "numa_node",
'-', 1)[0] + '-cpu-'+str(cpu.cpu))
return cpu
- @ staticmethod
+ @staticmethod
def _memconverter(mem):
selected_keys = [
"memtotal_mib", "memavail_mib", "vm_hugepages_use_1G",
'-mem-node-'+str(mem.numa_node))
return mem
- @ staticmethod
+ @staticmethod
def _ethconverter(eth):
selected_keys = [
"name", "namedisplay", "dev_id", "pdevice", "capabilities",
setattr(eth, 'created_at', None)
return eth
- @ staticmethod
+ @staticmethod
def _ifconverter(ifs):
selected_keys = [
"ifname", "iftype", "imac", "vlan_id", "imtu",
setattr(ifs, 'created_at', None)
return ifs
- @ staticmethod
+ @staticmethod
def _devconverter(dev):
selected_keys = [
"name", "pdevice", "pciaddr", "pvendor_id", "pvendor",
setattr(dev, 'name', dev.host_uuid.split('-', 1)[0] + '-'+dev.name)
return dev
- @ staticmethod
+ @staticmethod
def _k8sconverter(cluster):
setattr(cluster, 'name', cluster.cloud_name +
'.' + cluster.cluster_name)
cluster.name + '/' + str(cluster.uuid))
return cluster
- @ staticmethod
+ @staticmethod
def _k8shasher(cluster):
return str(hash((cluster.cluster_name, cluster.cloud_name,
cluster.cluster_api_endpoint, cluster.admin_user,
'more than one system exists in the account.')
return isystems[0]
- @ staticmethod
+ @staticmethod
def _hostconverter(host):
setattr(host, 'name', host.hostname)
return host
- @ staticmethod
+ @staticmethod
def _cpuconverter(cpu):
setattr(cpu, 'name', cpu.ihost_uuid.split(
'-', 1)[0] + '-cpu-'+str(cpu.cpu))
return cpu
- @ staticmethod
+ @staticmethod
def _memconverter(mem):
setattr(mem, 'name', mem.ihost_uuid.split('-', 1)[0] +
'-mem-node-'+str(mem.numa_node))
return mem
- @ staticmethod
+ @staticmethod
def _ethconverter(eth):
setattr(eth, 'name', eth.host_uuid.split('-', 1)[0] + '-'+eth.name)
setattr(eth, 'updated_at', None)
setattr(eth, 'created_at', None)
return eth
- @ staticmethod
+ @staticmethod
def _ifconverter(ifs):
setattr(ifs, 'name', ifs.ihost_uuid.split('-', 1)[0] + '-'+ifs.ifname)
setattr(ifs, 'updated_at', None)
setattr(ifs, 'created_at', None)
return ifs
- @ staticmethod
+ @staticmethod
def _k8sconverter(cluster):
setattr(cluster, 'name', cluster.cluster_name)
setattr(cluster, 'uuid',
cluster.name + '/' + str(cluster.uuid))
return cluster
- @ staticmethod
+ @staticmethod
def _k8shasher(cluster):
return str(hash((cluster.cluster_name,
cluster.cluster_api_endpoint, cluster.admin_user)))
class AlarmEvent2SMO(Serializer):
def __init__(self, eventtype: AlarmNotificationEventEnum,
- id: str, updatetime: str) -> None:
+ id: str, ref: str, updatetime: str) -> None:
self.notificationEventType = eventtype
self.id = id
+ self.objectRef = ref
self.updatetime = updatetime
if 'capabilities' in d and d['capabilities'] != '':
d['capabilities'] = json.loads(d['capabilities'])
+ if 'capacity' in d and d['capacity'] != '':
+ d['capacity'] = json.loads(d['capacity'])
return d
def get_notification_dict(self):
_notify_dms(uow, notifications, cmd.data)
elif msg_type == 'Resource':
_notify_resource(uow, notifications, cmd.data)
+ elif msg_type == 'OCloud':
+ _notify_ocloud(uow, notifications, cmd.data)
def __get_object_type_and_value(sub_filter):
def handle_filter(filter: str, f_type: str):
- print(filter)
if not filter:
return
.format(sub_data['subscriptionId'], data.id))
+def _notify_ocloud(uow, notifications, data):
+ with uow:
+ ocloud = uow.oclouds.get(data.id)
+ if ocloud is None:
+ logger.warning(
+ 'oCloud {} does not exists.'.format(data.id))
+ return
+
+ ocloud_dict = ocloud.get_notification_dict()
+
+ subs = uow.subscriptions.list()
+ for sub in subs:
+ sub_data = sub.serialize()
+ logger.debug('Subscription: {}'.format(sub_data['subscriptionId']))
+ filters = handle_filter(
+ sub_data['filter'], 'CloudInfo')
+ logger.debug(f'filters: {filters}, sub_data: {sub_data}')
+
+ if not filters or filters[0] == 0 or check_filters(
+ filters, sub_data, uow.oclouds,
+ ocloud.Ocloud,
+ ocloud.Ocloud.oCloudId, data.id):
+ callback_smo(notifications, sub, data, ocloud_dict)
+ continue
+
+ logger.info('Subscription {} filter hit, skip Cloud {}.'
+ .format(sub_data['subscriptionId'], data.id))
+
+
def _notify_resource(uow, notifications, data):
with uow:
resource = uow.resources.get(data.id)
# 'smoRegistrationService': fields.String
'extensions': fields.String(
example='',
- description='These are unspecified (not standardized) ' +\
- 'properties (keys) which are tailored by the vendor ' +\
+ description='These are unspecified (not standardized) ' +
+ 'properties (keys) which are tailored by the vendor ' +
'to extend the information provided about the O-Cloud.'),
},
- mask='{oCloudId,globalCloudId,globalcloudId,name,description,' +\
+ mask='{oCloudId,globalCloudId,globalcloudId,name,description,' +
'serviceUri}'
)
# 'resources': fields.String,
'extensions': fields.String(
example='',
- description='List of metadata key-value pairs ' +\
- 'used to associate meaningful metadata to ' +\
- 'the related resource pool.')
+ description=('List of metadata key-value pairs '
+ 'used to associate meaningful metadata to '
+ 'the related resource pool.'))
},
mask='{resourcePoolId,oCloudId,globalLocationId,name,description}'
)
'the Deployment Manager'),
})
+ capacity = api_ims_inventory_v1.model(
+ "DeploymentManagerCapacity", {
+ 'OS': fields.String(
+ example='low_latency',
+ description='Show the OS capacity of ' +
+ 'the Deployment Manager'),
+ })
+
deployment_manager_list = api_ims_inventory_v1.model(
"DeploymentManagerListDto",
{
example='https://128.224.115.51:6443',
description='The fully qualified URI to a Deployment ' +
'Management server for O2dms.'),
+ # Comment for the future implementation
# 'deploymentManagementServiceEndpoint': fields.String(
# attribute='serviceUri'),
- # 'supportedLocations': fields.String,
+ 'supportedLocations': fields.String,
'capabilities': fields.Nested(capabilities, True, True),
- # 'capacity': fields.String,
+ 'capacity': fields.Nested(capacity, True, True),
'profileSupportList': fields.List(
fields.String,
example=['native_k8sapi'],
'associate meaningful metadata to the related Deployment ' +
'Manager'),
},
- mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' + \
- 'profileSupportList}'
+ mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +
+ 'supportedLocations,capabilities,capacity,profileSupportList}'
)
profile = api_ims_inventory_v1.model("DeploymentManagerGetDtoProfile", {
'Management server for O2dms.'),
# 'deploymentManagementServiceEndpoint': fields.String(
# attribute='serviceUri'),
- # 'supportedLocations': fields.String,
+ 'supportedLocations': fields.String,
'capabilities': fields.Nested(capabilities, True, True),
- # 'capacity': fields.String,
+ 'capacity': fields.Nested(capacity, True, True),
'extensions': fields.Nested(extensions, True, True)
},
- mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +\
+ mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +
+ 'supportedLocations,capabilities,capacity,' +
'extensions{profileName,profileData}}'
)