Add more classes to Instance inheritance hierarchy

Instance class is too generic and contains some dirty workarounds to differently handle
Windows and Linux images, different ways to bootstrap the instance etc.

It is suggested to add more classes to build a better hierarchy:

Base Instance class becomes abstract and agnostic of the desired OS and agent type
It is inherited by two classes: LinuxInstance and WindowsInstance
LinuxInstance adds a default security rule for Linux, opening a standard SSH port
WindowsInstance adds a default security rule for Windows, opening an RDP port
At the same time WindowsInstance prepares a user-data allowing to use Murano v1 agent

LinuxInstance is inherited by two other classes, having different software config method
LinuxMuranoInstance adds a user-data preparation to configure Murano v2 agent
LinuxUDInstance adds a custom user-data field, allowing the services to supply their own
user data

Change-Id: I7394a10d1940c0cb746df6db9d326375dc5e7ccb
This commit is contained in:
Alexander Tivelkov 2014-05-08 19:22:54 +04:00 committed by Timur Sufiev
parent 871d097a74
commit 16d751adaf
6 changed files with 123 additions and 53 deletions

View File

@ -122,58 +122,5 @@ Workflow:
Arguments:
- groupName:
Contract: $.string().notNull()
Body:
# TODO: This is a temporary (and quite dirty) workaround. It should be
# implemented using polymorphism, by overriding parts of this method in
# derived classes related to particular OS type
# However bug #1314618 does not allow to do it
- If: !yaql "'w' in toLower($.image)"
Then:
- $rules:
- ToPort: 3389
IpProtocol: tcp
FromPort: 3389
External: true
Else:
- $rules:
- ToPort: 22
IpProtocol: tcp
FromPort: 22
External: true
- $.environment.securityGroupManager.addGroupIngress(
rules => $rules, groupName => $groupName)
getDefaultSecurityRules:
prepareUserData:
Body:
# TODO: This is a temporary (and quite dirty) workaround. It should be
# implemented using polymorphism, by overriding parts of this method in
# derived classes related to particular OS type
# However bug #1314618 does not allow to do it
- 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)

View File

@ -0,0 +1,21 @@
Namespaces:
=: io.murano.resources
std: io.murano
Name: LinuxInstance
Extends: Instance
Workflow:
createDefaultInstanceSecurityGroupRules:
Arguments:
- groupName:
Contract: $.string().notNull()
Body:
- $rules:
- ToPort: 22
IpProtocol: tcp
FromPort: 22
External: true
- $.environment.securityGroupManager.addGroupIngress(
rules => $rules, groupName => $groupName)

View File

@ -0,0 +1,30 @@
Namespaces:
=: io.murano.resources
std: io.murano
Name: LinuxMuranoInstance
Extends:
- LinuxInstance
Workflow:
prepareUserData:
Body:
- $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)

View File

@ -0,0 +1,26 @@
Namespaces:
=: io.murano.resources
std: io.murano
Name: LinuxUDInstance
Extends:
- LinuxInstance
Properties:
customUserData:
Contract: $.string()
Usage: InOut
Default: null
Workflow:
prepareUserData:
Body:
- Return: $.customUserData
setCustomUserData:
Arguments:
- data:
Contract: $.string().notNull()
Body:
- $.customUserData: $data

View File

@ -0,0 +1,41 @@
Namespaces:
=: io.murano.resources
std: io.murano
Name: WindowsInstance
Extends: Instance
Workflow:
createDefaultInstanceSecurityGroupRules:
Arguments:
- groupName:
Contract: $.string().notNull()
Body:
- $rules:
- ToPort: 3389
IpProtocol: tcp
FromPort: 3389
External: true
- $.environment.securityGroupManager.addGroupIngress(
rules => $rules, groupName => $groupName)
prepareUserData:
Body:
- $configFile: $.resources.string('Agent-v1.template')
- $initScript: $.resources.string('windows-init.ps1')
- $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)

View File

@ -22,3 +22,8 @@ Classes:
io.murano.resources.Network: resources/Network.yaml
io.murano.resources.Instance: resources/Instance.yaml
io.murano.resources.LinuxInstance: resources/LinuxInstance.yaml
io.murano.resources.LinuxMuranoInstance: resources/LinuxMuranoInstance.yaml
io.murano.resources.LinuxUDInstance: resources/LinuxUDInstance.yaml
io.murano.resources.WindowsInstance: resources/WindowsInstance.yaml