log = logging.getLogger(__name__)
-ALLOWED_KAFKA_KEYS = ["instantiated", "scaled", "terminated", "notify_alarm", "policy_updated", "vnf_terminated"]
+ALLOWED_KAFKA_KEYS = [
+ "instantiated",
+ "scaled",
+ "terminated",
+ "notify_alarm",
+ "policy_updated",
+ "vnf_terminated",
+]
class PolicyModuleAgent:
- def __init__(self, config: Config, loop=None):
+ def __init__(self, config: Config):
self.conf = config
- if not loop:
- loop = asyncio.get_event_loop()
- self.loop = loop
self.msg_bus = MessageBusClient(config)
self.db_client = CommonDbClient(config)
- self.autoscaling_service = AutoscalingService(config, loop)
- self.alarming_service = AlarmingService(config, loop)
- self.healing_service = HealingService(config, loop)
+ self.autoscaling_service = AutoscalingService(config)
+ self.alarming_service = AlarmingService(config)
+ self.healing_service = HealingService(config)
def run(self):
- self.loop.run_until_complete(self.start())
+ asyncio.run(self.start())
async def start(self):
Path("/tmp/osm_pol_agent_health_flag").touch()
log.debug("_process_msg topic=%s key=%s msg=%s", topic, key, msg)
try:
if key in ALLOWED_KAFKA_KEYS:
-
if key == "instantiated":
await self._handle_instantiated(msg)
async def _handle_policy_update(self, content):
log.info("_handle_policy_update: %s", content)
- nsr_id = content['nsr_id']
- vnf_member_index = content['vnf_member_index']
+ nsr_id = content["nsr_id"]
+ vnf_member_index = content["vnf_member_index"]
if (
content["operationState"] == "COMPLETED"
or content["operationState"] == "PARTIALLY_COMPLETED"
):
log.info(
"Updating policies of VNF with nsr_id: %s and vnf-member-index: %s"
- % (nsr_id, vnf_member_index))
- await self.autoscaling_service.delete_scaling_groups(nsr_id, vnf_member_index)
+ % (nsr_id, vnf_member_index)
+ )
+ await self.autoscaling_service.delete_scaling_groups(
+ nsr_id, vnf_member_index
+ )
await self.alarming_service.delete_vnf_alarms(nsr_id, vnf_member_index)
- await self.autoscaling_service.configure_scaling_groups(nsr_id, vnf_member_index)
+ await self.autoscaling_service.configure_scaling_groups(
+ nsr_id, vnf_member_index
+ )
await self.alarming_service.configure_vnf_alarms(nsr_id, vnf_member_index)
else:
log.info(
"Network service is not in COMPLETED or PARTIALLY_COMPLETED state. "
"Current state is %s. Skipping...",
- content['operationState'])
+ content["operationState"],
+ )
async def _handle_vnf_terminated(self, content):
- nsr_id = content['nsr_id']
- vnf_member_index = content['vnf_member_index']
+ nsr_id = content["nsr_id"]
+ vnf_member_index = content["vnf_member_index"]
if (
content["operationState"] == "COMPLETED"
or content["operationState"] == "PARTIALLY_COMPLETED"
):
log.info(
"Deleting policies of VNF with nsr_id: %s and vnf-member-index: %s"
- % (nsr_id, vnf_member_index))
- await self.autoscaling_service.delete_scaling_groups(nsr_id, vnf_member_index)
+ % (nsr_id, vnf_member_index)
+ )
+ await self.autoscaling_service.delete_scaling_groups(
+ nsr_id, vnf_member_index
+ )
await self.alarming_service.delete_vnf_alarms(nsr_id, vnf_member_index)
else:
log.info(
"Network service is not in COMPLETED or PARTIALLY_COMPLETED state. "
"Current state is %s. Skipping...",
- content['operationState'])
+ content["operationState"],
+ )