deb-murano/meta/io.murano/Classes/resources/NeutronNetwork.yaml
Snihyr Kostyantyn 0122dfe1d0 Add joinedNetworks property to Instance class
This commit introduce new Out property in Instance class.
This property contains list of dicts with Network instance and
list of instance`s IPs in this network

Change-Id: I21efa2a69dfcc3fd8d1aae53cca4fbb0933597ee
Closes-bug: #1620269
2016-09-12 14:05:17 -07:00

244 lines
6.8 KiB
YAML

# 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.
Namespaces:
=: io.murano.resources
std: io.murano
sys: io.murano.system
Name: NeutronNetwork
Extends: NeutronNetworkBase
Properties:
name:
Contract: $.string().notNull()
externalRouterId:
Contract: $.string()
Usage: InOut
autoUplink:
Contract: $.bool().notNull()
Default: true
autogenerateSubnet:
Contract: $.bool().notNull()
Default: true
openstackId:
Contract: $.string()
Usage: Out
subnetCidr:
Contract: $.string()
Usage: InOut
dnsNameservers:
# This property is optional,
# since neutron default dns will be used in case of empty
Contract: [$.string()]
Usage: InOut
Methods:
.init:
Body:
- $._region: $.getRegion()
- $._netExplorer: new(sys:NetworkExplorer, $this)
deploy:
Body:
- If: not $.getAttr(deployed, false)
Then:
- If: len($.dnsNameservers) = 0
Then:
- $.dnsNameservers: $._netExplorer.getDefaultDns()
- $template: $._createNetwork()
- If: $.autoUplink and (not bool($.externalRouterId))
Then:
- $.externalRouterId: $._netExplorer.getDefaultRouter()
- If: $.autogenerateSubnet and (not bool($.subnetCidr))
Then:
- $.subnetCidr: $._netExplorer.getAvailableCidr($.externalRouterId, id($))
- $template: $template.mergeWith($._createSubnet())
- If: $.externalRouterId != null
Then:
- $template: $template.mergeWith($._createRouterInterface())
- $._region.stack.updateTemplate($template)
- $._region.stack.push()
- $outputs: $._region.stack.output()
- $.openstackId: $outputs.get(format('{0}-id', $this.name))
- $.setAttr(deployed, true)
_createNetwork:
Body:
- $netName: $._getNetworkName()
- $template:
resources:
$netName:
type: 'OS::Neutron::Net'
properties:
name: $._getHeatName()
outputs:
format('{0}-id', $.name):
description: format('ID of {0} network', $.name)
value:
get_resource: $netName
- Return: $template
_createSubnet:
Body:
- Return:
resources:
$._getSubnetName():
type: 'OS::Neutron::Subnet'
properties:
network: { get_resource: $._getNetworkName() }
ip_version: 4
dns_nameservers: $.dnsNameservers
cidr: $.subnetCidr
_createRouterInterface:
Body:
- Return:
resources:
$._getRouterInterfaceName():
type: 'OS::Neutron::RouterInterface'
properties:
router_id: $.externalRouterId
subnet: { get_resource: $._getSubnetName() }
joinInstance:
Arguments:
- instance:
Contract: $.class(Instance).notNull()
- securityGroupName:
Contract: $.string()
- assignFloatingIp:
Contract: $.bool().notNull()
- sharedIps:
Contract:
- $.class(std:SharedIp)
Body:
- $.deploy()
- $netRef: { get_resource: $._getNetworkName() }
- $subnetRef: { get_resource: $._getSubnetName() }
- $extNetId: null
- $fipName: null
- If: $assignFloatingIp
Then:
- $extNetId: $._getExternalNetId()
- $fipName: format('fip-{0}-{1}', id($), $instance.name)
- $result: $.joinInstanceToNetwork(
instance => $instance,
securityGroupName => $securityGroupName,
sharedIps => $sharedIps,
netRef => $netRef,
subnetRef => $subnetRef,
floatingIpResourceName => $fipName,
floatingIpNetRef => $extNetId
)
# (sjmc7) This is a workaround for https://bugs.launchpad.net/heat/+bug/1299259
- If: $externalRouterId != null
Then:
- $template:
resources:
$fipName:
depends_on:
- $._getRouterInterfaceName()
- $result.template: $result.template.mergeWith($template)
- $addressOutputName: format('adresses-{0}-in-{1}', $instance.name, $this.name)
- $ipsOutputTemplate:
outputs:
$addressOutputName:
description: format('Addresses for {0} in {1}', $instance.name, $this.name)
value:
get_attr: [$instance.name, 'addresses', $._getHeatName()]
- $result.template: $result.template.mergeWith($ipsOutputTemplate)
- $result.instanceOutputs: $result.instanceOutputs.append($addressOutputName)
- Return: $result
describe:
Body:
- $.deploy()
- $subnet: $._netExplorer.listSubnetworks().where(
$.network_id = $this.openstackId).first()
- Return:
provider: Neutron
netName: $.name
netId: $.openstackId
subnetId: $subnet.id
cidr: $subnet.cidr
dns: $subnet.dns_nameservers
gateway: $subnet.gateway_ip
floatingIpNetId: $._getExternalNetId()
releaseResources:
Body:
- $template: $._region.stack.current()
- $template.resources: $template.resources.delete($._getHeatName())
- $template.resources: $template.resources.delete($._getSubnetName())
- $template.outputs: $template.outputs.delete(format('{0}-id', $.name))
- If: $.externalRouterId != null
Then:
$template.resources: $template.resources.delete($._getRouterInterfaceName())
- $._regiont.stack.setTemplate($template)
- $._region.stack.push()
- $.openstackId: null
getInstanceIpList:
Arguments:
- instance:
Contract: $.class(Instance).notNull()
Body:
- Return: $._region.stack.output().get(format('adresses-{0}-in-{1}', $instance.name, $this.name)).select($["addr"]).distinct()
_getRouterInterfaceName:
Body:
Return: format('ri-{0}', id($))
_getNetworkName:
Body:
Return: format('network-{0}', id($))
_getSubnetName:
Body:
Return: format('subnet-{0}', id($))
_getExternalNetId:
Body:
Return: $._netExplorer.getExternalNetworkIdForRouter($.externalRouterId)
_getHeatName:
Body:
Return: format('{0}-{1}', $.name, id($))