119 lines
3.5 KiB
YAML
119 lines
3.5 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()
|
|
agent:
|
|
Contract: $.class(sys:Agent)
|
|
Usage: Runtime
|
|
ipAddresses:
|
|
Contract: [$.string()]
|
|
Usage: Out
|
|
networks:
|
|
Contract:
|
|
useEnvironmentNetwork: $.bool().notNull()
|
|
useFlatNetwork: $.bool().notNull()
|
|
customNetworks: [$.class(Network).notNull()]
|
|
Default:
|
|
useEnvironmentNetwork: true
|
|
useFlatNetwork: false
|
|
customNetworks: []
|
|
assignFloatingIp:
|
|
Contract: $.bool().notNull()
|
|
Default: false
|
|
floatingIpAddress:
|
|
Contract: $.string()
|
|
Usage: Out
|
|
|
|
Workflow:
|
|
initialize:
|
|
Body:
|
|
- $.environment: $.find(std:Environment).require()
|
|
- $.agent: new(sys:Agent, host => $)
|
|
- $.resources: new(sys:Resources)
|
|
|
|
deploy:
|
|
Body:
|
|
- If: $.networks.useEnvironmentNetwork
|
|
Then:
|
|
$.joinNet($.environment.defaultNetworks.environment)
|
|
- If: $.networks.useFlatNetwork
|
|
Then:
|
|
$.joinNet($.environment.defaultNetworks.flat)
|
|
- $.networks.customNetworks.select($this.joinNet($))
|
|
|
|
- $userData: $.prepareUserData()
|
|
- $template:
|
|
Resources:
|
|
$.name:
|
|
Type: 'AWS::EC2::Instance'
|
|
Properties:
|
|
InstanceType: $.flavor
|
|
ImageId: $.image
|
|
UserData: $userData
|
|
Outputs:
|
|
format('{0}-PublicIp', $.name):
|
|
Value:
|
|
- Fn::GetAtt: [$.name, PublicIp]
|
|
- $.environment.stack.updateTemplate($template)
|
|
- $.environment.stack.push()
|
|
- $outputs: $.environment.stack.output()
|
|
- $.ipAddresses: $outputs.get(format('{0}-PublicIp', $this.name))
|
|
- $.floatingIpAddress: $outputs.get(format('{0}-FloatingIPaddress', $this.name))
|
|
- $.environment.instanceNotifier.trackApplication($this)
|
|
|
|
joinNet:
|
|
Arguments:
|
|
- net:
|
|
Contract: $.class(Network)
|
|
Body:
|
|
- If: $net != null
|
|
Then:
|
|
- If: $.assignFloatingIp and (not bool($.getAttr(fipAssigned)))
|
|
Then:
|
|
- $assignFip: true
|
|
- $.setAttr(fipAssigned, true)
|
|
Else:
|
|
- $assignFip: false
|
|
- $net.addHostToNetwork($, $assignFip)
|
|
|
|
|
|
prepareUserData:
|
|
Body:
|
|
- If: !yaql "'w' in toLower($.image)"
|
|
Then:
|
|
- $configFile: $.resources.string('Agent-v1.template')
|
|
- $initScript: $.resources.string('windows-init.ps1')
|
|
Else:
|
|
- $configFile: $.resources.string('Agent-v2.template')
|
|
- $initScript: $.resources.string('linux-init.sh')
|
|
|
|
- $configReplacements:
|
|
"%RABBITMQ_HOST%": config(rabbitmq, host)
|
|
"%RABBITMQ_PORT%": config(rabbitmq, port)
|
|
"%RABBITMQ_USER%": config(rabbitmq, login)
|
|
"%RABBITMQ_PASSWORD%": config(rabbitmq, password)
|
|
"%RABBITMQ_VHOST%": config(rabbitmq, virtual_host)
|
|
"%RABBITMQ_SSL%": str(config(rabbitmq, ssl)).toLower()
|
|
"%RABBITMQ_INPUT_QUEUE%": $.agent.queueName()
|
|
"%RESULT_QUEUE%": $.environment.agentListener.queueName()
|
|
|
|
- $scriptReplacements:
|
|
"%AGENT_CONFIG_BASE64%": base64encode($configFile.replace($configReplacements))
|
|
"%INTERNAL_HOSTNAME%": $.name
|
|
"%MURANO_SERVER_ADDRESS%": coalesce(config(file_server), config(rabbitmq, host))
|
|
"%CA_ROOT_CERT_BASE64%": ""
|
|
|
|
- Return: $initScript.replace($scriptReplacements)
|