Skip to content

Commit

Permalink
[Core-Library] Add ability to boot instance from volume
Browse files Browse the repository at this point in the history
Change-Id: I96af96f11ea89b58653816ed30e98e1e138b29b1
  • Loading branch information
Dmytro Dovbii committed Feb 11, 2016
1 parent db25225 commit 5dae8d8
Showing 1 changed file with 56 additions and 8 deletions.
64 changes: 56 additions & 8 deletions meta/io.murano/Classes/resources/Instance.yaml
Expand Up @@ -25,7 +25,8 @@ Properties:
flavor:
Contract: $.string().notNull()
image:
Contract: $.string().notNull()
Contract: $.string()
Default: null
keyname:
Contract: $.string()
Default: null
Expand Down Expand Up @@ -68,6 +69,13 @@ Properties:
volumes:
Contract:
$.string().notNull(): $.class(Volume).notNull()
blockDevices:
Contract:
- volume: $.class(Volume).notNull()
deviceName: $.string()
deviceType: $.string().check($ in list(disk, cdrom, null))
bootIndex: $.int()
Default: []

Methods:
initialize:
Expand Down Expand Up @@ -97,6 +105,7 @@ Methods:

deploy:
Body:
- $.validateBootSource()
- $securityGroupName: coalesce(
$.securityGroupName,
$.environment.securityGroupManager.defaultGroupName
Expand All @@ -116,17 +125,26 @@ Methods:
- $preparedUserData: $.prepareUserData()
# Create MQ queue to communicate with the VM
- $.agent.prepare()
- $properties:
flavor: $.flavor
availability_zone: $.availabilityZone
user_data: $preparedUserData.data
user_data_format: $preparedUserData.format
key_name: $.keyname

- If: len($.blockDevices) > 0
Then:
- $bdmDefinition: $.blockDevices.select($this.buidBlockDeviceDefinition($))
- $properties.block_device_mapping_v2: $bdmDefinition
Else:
$properties.image: $.image

- $template:
resources:
$.name:
type: 'OS::Nova::Server'
properties:
flavor: $.flavor
image: $.image
availability_zone: $.availabilityZone
user_data: $preparedUserData.data
user_data_format: $preparedUserData.format
key_name: $.keyname
properties: $properties

outputs:
format('{0}-assigned-ips', $.name):
description: format('Network IPs assigned to {0} instance', $.name)
Expand Down Expand Up @@ -254,6 +272,23 @@ Methods:
- $.setAttr(instanceResources, $.getAttr(instanceResources, []).concat($attachment.get(instanceResources, [])))
- $.setAttr(instanceOutputs, $.getAttr(instanceOutputs, []).concat($attachment.get(instanceOutputs, [])))

buidBlockDeviceDefinition:
Arguments:
blockDevice:
Contract:
volume: $.class(Volume).notNull()
deviceName: $.string()
deviceType: $.string().check($ in list(disk, cdrom, null))
bootIndex: $.int()

Body:
- $blockDevice.volume.deploy()
- Return:
device_name: $volItem.deviceName
volume_id: $volItem.volume.getRef()
device_type: $volItem.deviceType
boot_index: $volItem.bootIndex

releaseResources:
Body:
- $template: $.environment.stack.current()
Expand All @@ -277,6 +312,19 @@ Methods:
- $.setAttr(instanceOutputs, [])
- $.setAttr(fipAssigned, false)

validateBootSource:
Body:
- If: $.image = null and len($.blockDevices) = 0
Then:
- $msg: format('Neither image nor bootable volumes is specified for instance {0}', $.name)
- Throw: ResourceNotFound
Message: $msg
- If: $.image != null and len($.blockDevices) > 0
Then:
- $msg: 'Both image and list of bootable volumes are specified'
- Throw: ResourceConflict
Message: $msg

destroy:
Body:
- $.releaseResources()
Expand Down

0 comments on commit 5dae8d8

Please sign in to comment.