Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support reservation policy in heat-translator
Implementation of reservation policy in heat-translator Tacker Blueprint: https://blueprints.launchpad.net/tacker/+spec/reservation-vnfm Tacker Spec: https://review.openstack.org/#/c/561840/ Depends-On: Ic5d790df938b40d75bc50252e1e688e9c09eb568 Change-Id: I2b989a49ac3447995a82ddb7193bf478bb847b73
- Loading branch information
1 parent
c1c09ee
commit 30f4d2f
Showing
11 changed files
with
232 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Copyright (C) 2018 NTT DATA | ||
# All Rights Reserved. | ||
# | ||
# 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. | ||
|
||
import logging | ||
from translator.hot.syntax.hot_resource import HotResource | ||
|
||
# Name used to dynamically load appropriate map class. | ||
TARGET_CLASS_NAME = 'ToscaReservation' | ||
|
||
log = logging.getLogger('heat-translator') | ||
|
||
|
||
class ToscaReservation(HotResource): | ||
'''Translate TOSCA node type tosca.policies.Reservation''' | ||
|
||
toscatype = 'tosca.policies.Reservation' | ||
|
||
def __init__(self, policy, csar_dir=None): | ||
hot_type = "OS::Aodh::EventAlarm" | ||
super(ToscaReservation, self).__init__(policy, | ||
type=hot_type, | ||
csar_dir=csar_dir) | ||
self.policy = policy | ||
self.filter = list() | ||
|
||
def handle_expansion(self): | ||
extra_resources = list() | ||
hot_type = 'OS::Aodh::EventAlarm' | ||
for action_name in self.filter: | ||
prop = self._get_event_type(action_name) | ||
resrv_resources = HotResource(self.nodetemplate, | ||
type=hot_type, | ||
name=action_name, | ||
properties=prop) | ||
extra_resources.append(resrv_resources) | ||
return extra_resources | ||
|
||
def handle_properties(self): | ||
if self.policy.entity_tpl.get('reservation'): | ||
reservation_prop = self.policy.entity_tpl["reservation"].items() | ||
for action_name, action_dict in reservation_prop: | ||
if action_name != 'properties': | ||
self.filter.append(action_name) | ||
self.name = self.filter[0] | ||
|
||
def _get_event_type(self, action): | ||
if action == 'start_actions': | ||
return {'event_type': 'lease.event.start_lease'} | ||
if action == 'before_end_actions': | ||
return {'event_type': 'lease.event.before_end_lease'} | ||
if action == 'end_actions': | ||
return {'event_type': 'lease.event.end_lease'} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
translator/tests/data/hot_output/reservation/SP_RSV_res.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
heat_template_version: 2013-05-23 | ||
|
||
description: Tacker Scaling template | ||
|
||
resources: | ||
VDU1: | ||
type: OS::Nova::Server | ||
properties: | ||
user_data_format: SOFTWARE_CONFIG | ||
image: cirros-0.4.0-x86_64-disk | ||
flavor: | ||
get_param: flavor | ||
networks: | ||
- port: { get_resource: CP1 } | ||
config_drive: false | ||
CP1: | ||
type: OS::Neutron::Port | ||
properties: | ||
anti_spoofing_protection: false | ||
management: true | ||
network: net_mgmt | ||
VL1: | ||
type: OS::Neutron::Net |
44 changes: 44 additions & 0 deletions
44
translator/tests/data/hot_output/reservation/hot_reservation_scaling.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
heat_template_version: 2013-05-23 | ||
|
||
description: > | ||
VNF TOSCA template with reservation_id input parameters. | ||
parameters: | ||
flavor: {type: string, description: Flavor Information} | ||
lease_id: {type: string, description: lease id} | ||
resources: | ||
start_actions: | ||
type: OS::Aodh::EventAlarm | ||
properties: | ||
event_type: lease.event.start_lease | ||
SP_RSV_scale_out: | ||
type: OS::Heat::ScalingPolicy | ||
properties: | ||
auto_scaling_group_id: {get_resource: SP_RSV_group} | ||
adjustment_type: change_in_capacity | ||
scaling_adjustment: 2 | ||
cooldown: 120 | ||
SP_RSV_group: | ||
type: OS::Heat::AutoScalingGroup | ||
properties: | ||
min_size: 0 | ||
desired_capacity: 0 | ||
cooldown: 120 | ||
resource: {type: SP_RSV_res.yaml} | ||
max_size: 3 | ||
SP_RSV_scale_in: | ||
type: OS::Heat::ScalingPolicy | ||
properties: | ||
auto_scaling_group_id: {get_resource: SP_RSV_group} | ||
adjustment_type: change_in_capacity | ||
scaling_adjustment: -2 | ||
cooldown: 120 | ||
before_end_actions: | ||
type: OS::Aodh::EventAlarm | ||
properties: | ||
event_type: lease.event.before_end_lease | ||
end_actions: | ||
type: OS::Aodh::EventAlarm | ||
properties: | ||
event_type: lease.event.end_lease | ||
outputs: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
translator/tests/data/reservation/tosca-vnfd-reservation-id.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
tosca_definitions_version: tosca_simple_profile_for_nfv_1_0_0 | ||
|
||
description: VNF TOSCA template with reservation_id input parameters. | ||
|
||
imports: | ||
- translator/tests/data/nfv/tacker_defs.yaml | ||
- translator/tests/data/nfv/tacker_nfv_defs.yaml | ||
|
||
topology_template: | ||
inputs: | ||
flavor: | ||
type: string | ||
description: Flavor Information | ||
|
||
lease_id: | ||
type: string | ||
description: lease id | ||
|
||
node_templates: | ||
VDU1: | ||
type: tosca.nodes.nfv.VDU.Tacker | ||
properties: | ||
image: cirros-0.4.0-x86_64-disk | ||
flavor: { get_input: flavor } | ||
|
||
CP1: | ||
type: tosca.nodes.nfv.CP.Tacker | ||
properties: | ||
management: true | ||
order: 0 | ||
anti_spoofing_protection: false | ||
requirements: | ||
- virtualLink: | ||
node: VL1 | ||
- virtualBinding: | ||
node: VDU1 | ||
VL1: | ||
type: tosca.nodes.nfv.VL | ||
properties: | ||
network_name: net_mgmt | ||
vendor: Tacker | ||
|
||
policies: | ||
- RSV: | ||
type: tosca.policies.tacker.Reservation | ||
reservation: | ||
start_actions: [SP_RSV] | ||
before_end_actions: [SP_RSV] | ||
end_actions: [noop] | ||
properties: | ||
lease_id: { get_input: lease_id } | ||
- SP_RSV: | ||
type: tosca.policies.tacker.Scaling | ||
properties: | ||
increment: 2 | ||
cooldown: 120 | ||
min_instances: 0 | ||
max_instances: 3 | ||
default_instances: 0 | ||
targets: [VDU1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters