248 lines
7.7 KiB
YAML
248 lines
7.7 KiB
YAML
Namespaces:
|
|
=: io.murano.resources
|
|
std: io.murano
|
|
sys: io.murano.system
|
|
|
|
|
|
Name: Instance
|
|
|
|
|
|
Properties:
|
|
name:
|
|
Contract: $.string().notNull()
|
|
flavor:
|
|
Contract: $.string().notNull()
|
|
image:
|
|
Contract: $.string().notNull()
|
|
keyname:
|
|
Contract: $.string()
|
|
Default: null
|
|
|
|
agent:
|
|
Contract: $.class(sys:Agent)
|
|
Usage: Runtime
|
|
ipAddresses:
|
|
Contract: [$.string()]
|
|
Usage: Out
|
|
networks:
|
|
Contract:
|
|
useEnvironmentNetwork: $.bool().notNull()
|
|
useFlatNetwork: $.bool().notNull()
|
|
customNetworks: [$.class(Network).notNull()]
|
|
primaryNetwork: $.class(Network).notOwned()
|
|
Default:
|
|
useEnvironmentNetwork: true
|
|
useFlatNetwork: false
|
|
customNetworks: []
|
|
primaryNetwork: null
|
|
assignFloatingIp:
|
|
Contract: $.bool().notNull()
|
|
Default: false
|
|
floatingIpAddress:
|
|
Contract: $.string()
|
|
Usage: Out
|
|
securityGroupName:
|
|
Contract: $.string()
|
|
Default: null
|
|
sharedIps:
|
|
Contract:
|
|
- $.class(std:SharedIp)
|
|
Usage: InOut # as it is set in setSharedIps
|
|
|
|
Methods:
|
|
initialize:
|
|
Body:
|
|
- $.environment: $.find(std:Environment).require()
|
|
- $.agent: new(sys:Agent, host => $)
|
|
- $.resources: new(sys:Resources)
|
|
|
|
setSharedIps:
|
|
Arguments:
|
|
ips:
|
|
Contract:
|
|
- $.class(std:SharedIp)
|
|
Body:
|
|
$.sharedIps: $ips
|
|
|
|
deploy:
|
|
Body:
|
|
- $securityGroupName: coalesce(
|
|
$.securityGroupName,
|
|
$.environment.securityGroupManager.defaultGroupName
|
|
)
|
|
- $.createDefaultInstanceSecurityGroupRules($securityGroupName)
|
|
- $.detectPrimaryNetwork()
|
|
- $.ensureSharedIpsDeployed()
|
|
- $.ensureNetworksDeployed()
|
|
- If: $.networks.useEnvironmentNetwork and $.environment.defaultNetworks.environment!=null
|
|
Then:
|
|
$.joinNet($.environment.defaultNetworks.environment, $securityGroupName)
|
|
- If: $.networks.useFlatNetwork and $.environment.defaultNetworks.flat!=null
|
|
Then:
|
|
$.joinNet($.environment.defaultNetworks.flat, $securityGroupName)
|
|
- $.networks.customNetworks.select($this.joinNet($, $securityGroupName))
|
|
|
|
- $userData: $.prepareUserData()
|
|
|
|
- $template:
|
|
resources:
|
|
$.name:
|
|
type: 'OS::Nova::Server'
|
|
properties:
|
|
flavor: $.flavor
|
|
image: $.image
|
|
user_data: $userData
|
|
key_name: $.keyname
|
|
outputs:
|
|
format('{0}-assigned-ip', $.name):
|
|
description: format('IP address assigned to {0} instance', $.name)
|
|
value:
|
|
get_attr: [$.name, addresses]
|
|
- $.environment.stack.updateTemplate($template)
|
|
- $.environment.stack.push()
|
|
- $outputs: $.environment.stack.output()
|
|
- $.ipAddresses: $outputs.get(format('{0}-assigned-ip', $this.name)).values().flatten().addr.list()
|
|
- $.floatingIpAddress: $outputs.get(format('{0}-FloatingIPaddress', $this.name))
|
|
- $.environment.instanceNotifier.trackCloudInstance($this)
|
|
|
|
detectPrimaryNetwork:
|
|
Body:
|
|
- $.primaryNetwork: null
|
|
- If: $.networks.primaryNetwork != null
|
|
Then:
|
|
- $.primaryNetwork: $.networks.primaryNetwork
|
|
Else:
|
|
- If: $.networks.useEnvironmentNetwork and $.environment.defaultNetworks.environment!=null
|
|
Then:
|
|
- $.primaryNetwork: $.environment.defaultNetworks.environment
|
|
Else:
|
|
- If: $.networks.useFlatNetwork and $.environment.defaultNetworks.flat!=null
|
|
Then:
|
|
- $.primaryNetwork: $.environment.defaultNetworks.flat
|
|
|
|
ensureNetworksDeployed:
|
|
Body:
|
|
- If: $.networks.useEnvironmentNetwork and $.environment.defaultNetworks.environment!=null
|
|
Then:
|
|
- $.environment.defaultNetworks.environment.deploy()
|
|
- If: $.networks.useFlatNetwork and $.environment.defaultNetworks.flat!=null
|
|
Then:
|
|
- $.environment.defaultNetworks.flat.deploy()
|
|
- $.networks.customNetworks.pselect($.deploy())
|
|
|
|
ensureSharedIpsDeployed:
|
|
Body:
|
|
- $.sharedIps.pselect($.deploy())
|
|
|
|
joinNet:
|
|
Arguments:
|
|
- net:
|
|
Contract: $.class(Network).notNull()
|
|
- securityGroupName:
|
|
Contract: $.string()
|
|
Body:
|
|
- If: $net = $.primaryNetwork
|
|
Then:
|
|
- $primary: true
|
|
Else:
|
|
- $primary: false
|
|
|
|
- If: $primary and $.assignFloatingIp and not $.getAttr(fipAssigned, false)
|
|
Then:
|
|
- $assignFip: true
|
|
|
|
Else:
|
|
- $assignFip: false
|
|
|
|
- $portname: $.name + '-port-to-' + $net.id()
|
|
- $netRef: $net.getNetworkReference()
|
|
- $subnetRef: $net.getSubnetReference()
|
|
- $template:
|
|
resources:
|
|
$portname:
|
|
type: 'OS::Neutron::Port'
|
|
properties:
|
|
network_id: $netRef
|
|
fixed_ips:
|
|
- subnet_id: $subnetRef
|
|
security_groups:
|
|
- get_resource: $securityGroupName
|
|
$.name:
|
|
properties:
|
|
networks:
|
|
- port:
|
|
get_resource: $portname
|
|
- $.environment.stack.updateTemplate($template)
|
|
|
|
- If: $primary
|
|
Then:
|
|
- For: sip
|
|
In: $.sharedIps
|
|
Do:
|
|
- $template:
|
|
resources:
|
|
$portname:
|
|
properties:
|
|
allowed_address_pairs:
|
|
- ip_address: $sip.getSharedIpRef()
|
|
- $.environment.stack.updateTemplate($template)
|
|
|
|
- If: $assignFip
|
|
Then:
|
|
- $extNetId: $net.getExternalNetId()
|
|
- If: $extNetId != null
|
|
Then:
|
|
- $fip_name: $.name + '-FloatingIP-' + $net.id()
|
|
- $template:
|
|
resources:
|
|
$fip_name:
|
|
type: 'OS::Neutron::FloatingIP'
|
|
properties:
|
|
floating_network_id: $extNetId
|
|
$.name + '-FloatingIpAssoc-' + $net.id():
|
|
type: 'OS::Neutron::FloatingIPAssociation'
|
|
properties:
|
|
floatingip_id:
|
|
get_resource: $fip_name
|
|
port_id:
|
|
get_resource: $portname
|
|
outputs:
|
|
$.name + '-FloatingIPaddress':
|
|
value:
|
|
get_attr: [$fip_name, floating_ip_address]
|
|
description: Floating IP assigned
|
|
- $.environment.stack.updateTemplate($template)
|
|
- $.setAttr(fipAssigned, true)
|
|
|
|
destroy:
|
|
# Fixme(smelikyan): We need to remove all associated resources on destroy
|
|
Body:
|
|
- $template: $.environment.stack.current()
|
|
# Remove OS::Nova::Server resource
|
|
- $patchBlock:
|
|
op: remove
|
|
path: format('/resources/{0}', $.name)
|
|
- $template: patch($template, $patchBlock)
|
|
# Remove Ip Addresses Outputs assigned to this Instance
|
|
- $assignedIpBlock:
|
|
op: remove
|
|
path: format('/outputs/{0}-assigned-ip', $.name)
|
|
- $template: patch($template, $assignedIpBlock)
|
|
# Remove Floatting IP Addresses Outputs
|
|
- If: $.getAttr(fipAssigned, false)
|
|
Then:
|
|
- $assignedFloatingIpBlock:
|
|
op: remove
|
|
path: format('/outputs/{0}-FloatingIPaddress', $.name)
|
|
- $template: patch($template, $assignedFloatingIpBlock)
|
|
- $.environment.stack.setTemplate($template)
|
|
- $.environment.stack.push()
|
|
- $.environment.instanceNotifier.untrackCloudInstance($this)
|
|
|
|
createDefaultInstanceSecurityGroupRules:
|
|
Arguments:
|
|
- groupName:
|
|
Contract: $.string().notNull()
|
|
|
|
prepareUserData:
|