diff --git a/magnum/conductor/template_definition.py b/magnum/conductor/template_definition.py index b05a288171..d7f2151088 100644 --- a/magnum/conductor/template_definition.py +++ b/magnum/conductor/template_definition.py @@ -571,6 +571,8 @@ class AtomicSwarmTemplateDefinition(BaseTemplateDefinition): param_type=str) self.add_parameter('server_flavor', baymodel_attr='flavor_id') + self.add_parameter('docker_volume_size', + baymodel_attr='docker_volume_size') self.add_parameter('external_network', baymodel_attr='external_network_id', required=True) diff --git a/magnum/templates/swarm/fragments/configure-docker-storage.sh b/magnum/templates/swarm/fragments/configure-docker-storage.sh new file mode 100644 index 0000000000..4159d36295 --- /dev/null +++ b/magnum/templates/swarm/fragments/configure-docker-storage.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +. /etc/sysconfig/heat-params + +DOCKER_DEV=/dev/disk/by-id/virtio-${DOCKER_VOLUME:0:20} + +attempts=60 +while [[ ! -b $DOCKER_DEV && $attempts != 0 ]]; do + echo "waiting for disk $DOCKER_DEV" + sleep 0.5 + udevadm trigger + let attempts-- +done + +if ! [ -b $DOCKER_DEV ]; then + echo "ERROR: device $DOCKER_DEV does not exist" >&2 + exit 1 +fi + +pvcreate $DOCKER_DEV +vgcreate docker $DOCKER_DEV + +cat > /etc/sysconfig/docker-storage-setup < + size of a cinder volume to allocate to docker for container/image + storage + default: 25 + fixed_network_cidr: type: string description: network range for fixed ip network @@ -192,6 +199,7 @@ resources: template: {get_file: fragments/write-heat-params.yaml} params: "$WAIT_HANDLE": {get_resource: cloud_init_wait_handle} + "$DOCKER_VOLUME": {get_resource: docker_volume} "$HTTP_PROXY": {get_param: http_proxy} "$HTTPS_PROXY": {get_param: https_proxy} "$NO_PROXY": {get_param: no_proxy} @@ -306,6 +314,12 @@ resources: group: ungrouped config: {get_file: fragments/disable-selinux.sh} + configure_docker_storage: + type: OS::Heat::SoftwareConfig + properties: + group: ungrouped + config: {get_file: fragments/configure-docker-storage.sh} + add_proxy: type: "OS::Heat::SoftwareConfig" properties: @@ -320,6 +334,7 @@ resources: - config: {get_resource: remove_docker_key} - config: {get_resource: write_heat_params} - config: {get_resource: make_cert} + - config: {get_resource: configure_docker_storage} - config: {get_resource: write_swarm_agent_failure_service} - config: {get_resource: write_swarm_manager_failure_service} - config: {get_resource: write_docker_service} @@ -387,6 +402,7 @@ resources: ssh_key_name: {get_param: ssh_key_name} server_image: {get_param: server_image} server_flavor: {get_param: server_flavor} + docker_volume_size: {get_param: docker_volume_size} fixed_network_id: {get_resource: fixed_network} fixed_subnet_id: {get_resource: fixed_subnet} external_network: {get_param: external_network} @@ -400,6 +416,24 @@ resources: magnum_url: {get_param: magnum_url} tls_disabled: {get_param: tls_disabled} + ###################################################################### + # + # docker storage. This allocates a cinder volume and attaches it + # to the master. + # + + docker_volume: + type: OS::Cinder::Volume + properties: + size: {get_param: docker_volume_size} + + docker_volume_attach: + type: OS::Cinder::VolumeAttachment + properties: + instance_uuid: {get_resource: swarm_master} + volume_id: {get_resource: docker_volume} + mountpoint: /dev/vdb + outputs: api_address: diff --git a/magnum/templates/swarm/swarmnode.yaml b/magnum/templates/swarm/swarmnode.yaml index 6cba804d4c..98ad55c58d 100644 --- a/magnum/templates/swarm/swarmnode.yaml +++ b/magnum/templates/swarm/swarmnode.yaml @@ -22,6 +22,12 @@ parameters: description: name of ssh key to be provisioned on our server default: lars + docker_volume_size: + type: number + description: > + size of a cinder volume to allocate to docker for container/image + storage + external_network: type: string description: uuid/name of a network to use for floating ip addresses @@ -127,6 +133,7 @@ resources: template: {get_file: fragments/write-heat-params.yaml} params: "$WAIT_HANDLE": {get_resource: node_cloud_init_wait_handle} + "$DOCKER_VOLUME": {get_resource: docker_volume} "$HTTP_PROXY": {get_param: http_proxy} "$HTTPS_PROXY": {get_param: https_proxy} "$NO_PROXY": {get_param: no_proxy} @@ -155,6 +162,12 @@ resources: group: ungrouped config: {get_file: fragments/make-cert.py} + configure_docker_storage: + type: OS::Heat::SoftwareConfig + properties: + group: ungrouped + config: {get_file: fragments/configure-docker-storage.sh} + write_docker_service: type: "OS::Heat::SoftwareConfig" properties: @@ -229,6 +242,7 @@ resources: - config: {get_resource: remove_docker_key} - config: {get_resource: write_heat_params} - config: {get_resource: make_cert} + - config: {get_resource: configure_docker_storage} - config: {get_resource: write_swarm_agent_failure_service} - config: {get_resource: write_swarm_agent_service} - config: {get_resource: write_docker_service} @@ -272,6 +286,24 @@ resources: port_id: get_resource: swarm_node_eth0 + ###################################################################### + # + # docker storage. This allocates a cinder volume and attaches it + # to the node. + # + + docker_volume: + type: OS::Cinder::Volume + properties: + size: {get_param: docker_volume_size} + + docker_volume_attach: + type: OS::Cinder::VolumeAttachment + properties: + instance_uuid: {get_resource: swarm_node} + volume_id: {get_resource: docker_volume} + mountpoint: /dev/vdb + outputs: swarm_node_ip: diff --git a/magnum/tests/unit/conductor/handlers/test_swarm_bay_conductor.py b/magnum/tests/unit/conductor/handlers/test_swarm_bay_conductor.py index 762dc96e78..3e90277390 100644 --- a/magnum/tests/unit/conductor/handlers/test_swarm_bay_conductor.py +++ b/magnum/tests/unit/conductor/handlers/test_swarm_bay_conductor.py @@ -31,6 +31,7 @@ class TestBayConductorWithSwarm(base.TestCase): 'flavor_id': 'flavor_id', 'keypair_id': 'keypair_id', 'dns_nameserver': 'dns_nameserver', + 'docker_volume_size': 20, 'external_network_id': 'external_network_id', 'fixed_network': '10.2.0.0/22', 'cluster_distro': 'fedora-atomic', @@ -80,6 +81,7 @@ class TestBayConductorWithSwarm(base.TestCase): 'server_image': 'image_id', 'server_flavor': 'flavor_id', 'number_of_nodes': '1', + 'docker_volume_size': 20, 'fixed_network_cidr': '10.2.0.0/22', 'discovery_url': 'token://39987da72f8386e0d0225ae8929e7cb4', 'http_proxy': 'http_proxy', @@ -102,8 +104,8 @@ class TestBayConductorWithSwarm(base.TestCase): 'test_discovery', group='bay') not_required = ['image_id', 'flavor_id', 'dns_nameserver', - 'fixed_network', 'http_proxy', 'https_proxy', - 'no_proxy'] + 'docker_volume_size', 'fixed_network', 'http_proxy', + 'https_proxy', 'no_proxy'] for key in not_required: self.baymodel_dict[key] = None self.bay_dict['discovery_url'] = None