alarm_id=alarm_descriptor['alarm-id'],
alarm_uuid=alarm_uuid,
nsr_id=nsr_id,
- vnf_member_index=int(vnfr['member-vnf-index-ref']),
+ vnf_member_index=vnfr['member-vnf-index-ref'],
vdu_name=vdur['name']
)
for action_type in ['ok', 'insufficient-data', 'alarm']:
try:
scaling_group_record = ScalingGroupRepository.get(
ScalingGroup.nsr_id == nsr_id,
- ScalingGroup.vnf_member_index == int(vnfr['member-vnf-index-ref']),
+ ScalingGroup.vnf_member_index == vnfr['member-vnf-index-ref'],
ScalingGroup.name == scaling_group['name']
)
log.debug("Found existing scaling group record in DB...")
alarm = ScalingAlarmRepository.create(
alarm_uuid=alarm_uuid,
action='scale_in',
- vnf_member_index=int(vnfr['member-vnf-index-ref']),
+ vnf_member_index=vnfr['member-vnf-index-ref'],
vdu_name=vdur['name'],
scaling_criteria=scaling_criteria_record
)
alarm = ScalingAlarmRepository.create(
alarm_uuid=alarm_uuid,
action='scale_out',
- vnf_member_index=int(vnfr['member-vnf-index-ref']),
+ vnf_member_index=vnfr['member-vnf-index-ref'],
vdu_name=vdur['name'],
scaling_criteria=scaling_criteria_record
)
raise Exception("Unknown database driver {}".format(config.get('section', 'driver')))
self.common_db.db_connect(config.get("database"))
- def get_vnfr(self, nsr_id: str, member_index: int):
+ def get_vnfr(self, nsr_id: str, member_index: str):
vnfr = self.common_db.get_one("vnfrs",
- {"nsr-id-ref": nsr_id, "member-vnf-index-ref": str(member_index)})
+ {"nsr-id-ref": nsr_id, "member-vnf-index-ref": member_index})
return vnfr
def get_vnfrs(self, nsr_id: str):
loop = asyncio.get_event_loop()
self.loop = loop
- async def scale(self, nsr_id: str, scaling_group_name: str, vnf_member_index: int, action: str):
+ async def scale(self, nsr_id: str, scaling_group_name: str, vnf_member_index: str, action: str):
log.debug("scale %s %s %s %s", nsr_id, scaling_group_name, vnf_member_index, action)
nslcmop = self._generate_nslcmop(nsr_id, scaling_group_name, vnf_member_index, action)
self.db_client.create_nslcmop(nslcmop)
log.debug("Sending scale action message: %s", json.dumps(nslcmop))
await self.msg_bus.aiowrite("ns", "scale", nslcmop)
- def _generate_nslcmop(self, nsr_id: str, scaling_group_name: str, vnf_member_index: int, action: str):
+ def _generate_nslcmop(self, nsr_id: str, scaling_group_name: str, vnf_member_index: str, action: str):
log.debug("_generate_nslcmop %s %s %s %s", nsr_id, scaling_group_name, vnf_member_index, action)
_id = str(uuid.uuid4())
now = time.time()
"scaleVnfType": action.upper(),
"scaleByStepData": {
"scaling-group-descriptor": scaling_group_name,
- "member-vnf-index": str(vnf_member_index)
+ "member-vnf-index": vnf_member_index
}
},
"scaleTime": "{}Z".format(datetime.datetime.utcnow().isoformat())
loop = asyncio.get_event_loop()
self.loop = loop
- async def create_alarm(self, metric_name: str, ns_id: str, vdu_name: str, vnf_member_index: int, threshold: int,
+ async def create_alarm(self, metric_name: str, ns_id: str, vdu_name: str, vnf_member_index: str, threshold: int,
statistic: str, operation: str):
cor_id = random.randint(1, 10e7)
msg = self._build_create_alarm_payload(cor_id,
raise ValueError('No alarm deletion response from MON. Is MON up?')
return alarm_uuid
- async def delete_alarm(self, ns_id: str, vnf_member_index: int, vdu_name: str, alarm_uuid: str):
+ async def delete_alarm(self, ns_id: str, vnf_member_index: str, vdu_name: str, alarm_uuid: str):
cor_id = random.randint(1, 10e7)
msg = self._build_delete_alarm_payload(cor_id, ns_id, vdu_name, vnf_member_index, alarm_uuid)
log.debug("Sending delete_alarm_request %s", msg)
metric_name: str,
ns_id: str,
vdu_name: str,
- vnf_member_index: int,
+ vnf_member_index: str,
threshold: int,
statistic: str,
operation: str):
return msg
def _build_delete_alarm_payload(self, cor_id: int, ns_id: str, vdu_name: str,
- vnf_member_index: int, alarm_uuid: str):
+ vnf_member_index: str, alarm_uuid: str):
alarm_delete_request = {
'correlation_id': cor_id,
'alarm_uuid': alarm_uuid,
class ScalingGroup(BaseModel):
nsr_id = CharField()
- vnf_member_index = IntegerField()
+ vnf_member_index = CharField()
name = CharField()
content = TextField()
class ScalingAlarm(BaseModel):
alarm_uuid = CharField(unique=True)
action = CharField()
- vnf_member_index = IntegerField()
+ vnf_member_index = CharField()
vdu_name = CharField()
scaling_criteria = ForeignKeyField(ScalingCriteria, related_name='scaling_alarms', on_delete='CASCADE')
last_status = CharField(default='insufficient-data')
alarm_id = CharField()
alarm_uuid = CharField(unique=True)
nsr_id = CharField()
- vnf_member_index = IntegerField()
+ vnf_member_index = CharField()
vdu_name = CharField()
--- /dev/null
+# -*- coding: utf-8 -*-
+
+# Copyright 2018 Whitestack, LLC
+# *************************************************************
+
+# This file is part of OSM Monitoring module
+# All Rights Reserved to Whitestack, LLC
+
+# 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.
+
+# For those usages not covered by the Apache License, Version 2.0 please
+# contact: bdiaz@whitestack.com or glavado@whitestack.com
+##
+"""Peewee migrations -- 005_change_vnf_index_member_to_str.py.
+
+Some examples (model - class or model name)::
+
+ > Model = migrator.orm['model_name'] # Return model in current state by name
+
+ > migrator.sql(sql) # Run custom SQL
+ > migrator.python(func, *args, **kwargs) # Run python code
+ > migrator.create_model(Model) # Create a model (could be used as decorator)
+ > migrator.remove_model(model, cascade=True) # Remove a model
+ > migrator.add_fields(model, **fields) # Add fields to a model
+ > migrator.change_fields(model, **fields) # Change fields
+ > migrator.remove_fields(model, *field_names, cascade=True)
+ > migrator.rename_field(model, old_field_name, new_field_name)
+ > migrator.rename_table(model, new_table_name)
+ > migrator.add_index(model, *col_names, unique=False)
+ > migrator.drop_index(model, *col_names)
+ > migrator.add_not_null(model, *field_names)
+ > migrator.drop_not_null(model, *field_names)
+ > migrator.add_default(model, field_name, default)
+
+"""
+
+import peewee as pw
+
+SQL = pw.SQL
+
+
+def migrate(migrator, database, fake=False, **kwargs):
+ """Write your migrations here."""
+
+ migrator.change_fields('scalingalarm', vnf_member_index=pw.CharField(max_length=255))
+ migrator.change_fields('vnfalarm', vnf_member_index=pw.CharField(max_length=255))
+ migrator.change_fields('scalinggroup', vnf_member_index=pw.CharField(max_length=255))
+
+
+def rollback(migrator, database, fake=False, **kwargs):
+ """Write your rollback migrations here."""
+
+ migrator.change_fields('scalingalarm', vnf_member_index=pw.IntegerField())
+ migrator.change_fields('vnfalarm', vnf_member_index=pw.IntegerField())
+ migrator.change_fields('scalinggroup', vnf_member_index=pw.IntegerField())