Merge "Split swarm atomic template"

This commit is contained in:
Jenkins 2016-09-21 16:08:24 +00:00 committed by Gerrit Code Review
commit db97365893
22 changed files with 149 additions and 128 deletions

View File

@ -0,0 +1,118 @@
# Copyright 2016 Rackspace Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from magnum.drivers.common import template_def
from oslo_config import cfg
CONF = cfg.CONF
DOCKER_PORT = '2376'
class SwarmApiAddressOutputMapping(template_def.OutputMapping):
def set_output(self, stack, cluster_template, cluster):
if self.cluster_attr is None:
return
output_value = self.get_output_value(stack)
if output_value is not None:
# Note(rocha): protocol should always be tcp as the docker
# command client does not handle https (see bug #1604812).
params = {
'protocol': 'tcp',
'address': output_value,
'port': DOCKER_PORT,
}
value = "%(protocol)s://%(address)s:%(port)s" % params
setattr(cluster, self.cluster_attr, value)
class SwarmFedoraTemplateDefinition(template_def.BaseTemplateDefinition):
"""Docker swarm template for a Fedora Atomic VM."""
def __init__(self):
super(SwarmFedoraTemplateDefinition, self).__init__()
self.add_parameter('cluster_uuid',
cluster_attr='uuid',
param_type=str)
self.add_parameter('number_of_nodes',
cluster_attr='node_count')
self.add_parameter('master_flavor',
cluster_template_attr='master_flavor_id')
self.add_parameter('node_flavor',
cluster_template_attr='flavor_id')
self.add_parameter('docker_volume_size',
cluster_template_attr='docker_volume_size')
self.add_parameter('volume_driver',
cluster_template_attr='volume_driver')
self.add_parameter('external_network',
cluster_template_attr='external_network_id',
required=True)
self.add_parameter('network_driver',
cluster_template_attr='network_driver')
self.add_parameter('tls_disabled',
cluster_template_attr='tls_disabled',
required=True)
self.add_parameter('registry_enabled',
cluster_template_attr='registry_enabled')
self.add_parameter('docker_storage_driver',
cluster_template_attr='docker_storage_driver')
self.add_parameter('swarm_version',
cluster_attr='coe_version')
self.add_output('api_address',
cluster_attr='api_address',
mapping_type=SwarmApiAddressOutputMapping)
self.add_output('swarm_master_private',
cluster_attr=None)
self.add_output('swarm_masters',
cluster_attr='master_addresses')
self.add_output('swarm_nodes_private',
cluster_attr=None)
self.add_output('swarm_nodes',
cluster_attr='node_addresses')
self.add_output('discovery_url',
cluster_attr='discovery_url')
def get_params(self, context, cluster_template, cluster, **kwargs):
extra_params = kwargs.pop('extra_params', {})
extra_params['discovery_url'] = self.get_discovery_url(cluster)
# HACK(apmelton) - This uses the user's bearer token, ideally
# it should be replaced with an actual trust token with only
# access to do what the template needs it to do.
osc = self.get_osc(context)
extra_params['magnum_url'] = osc.magnum_url()
label_list = ['flannel_network_cidr', 'flannel_backend',
'flannel_network_subnetlen', 'rexray_preempt']
extra_params['auth_url'] = context.auth_url
for label in label_list:
extra_params[label] = cluster_template.labels.get(label)
if cluster_template.registry_enabled:
extra_params['swift_region'] = CONF.docker_registry.swift_region
extra_params['registry_container'] = (
CONF.docker_registry.swift_registry_container)
return super(SwarmFedoraTemplateDefinition,
self).get_params(context, cluster_template, cluster,
extra_params=extra_params,
**kwargs)
def get_env_files(self, cluster_template):
if cluster_template.master_lb_enabled:
return [template_def.COMMON_ENV_PATH + 'with_master_lb.yaml']
else:
return [template_def.COMMON_ENV_PATH + 'no_master_lb.yaml']

View File

@ -13,116 +13,19 @@
# under the License.
import os
from magnum.drivers.common import template_def
from magnum.drivers.common import swarm_fedora_template_def as sftd
from oslo_config import cfg
CONF = cfg.CONF
DOCKER_PORT = '2376'
class SwarmApiAddressOutputMapping(template_def.OutputMapping):
def set_output(self, stack, cluster_template, cluster):
if self.cluster_attr is None:
return
output_value = self.get_output_value(stack)
if output_value is not None:
# Note(rocha): protocol should always be tcp as the docker
# command client does not handle https (see bug #1604812).
params = {
'protocol': 'tcp',
'address': output_value,
'port': DOCKER_PORT,
}
value = "%(protocol)s://%(address)s:%(port)s" % params
setattr(cluster, self.cluster_attr, value)
class AtomicSwarmTemplateDefinition(template_def.BaseTemplateDefinition):
class AtomicSwarmTemplateDefinition(sftd.SwarmFedoraTemplateDefinition):
"""Docker swarm template for a Fedora Atomic VM."""
provides = [
{'server_type': 'vm', 'os': 'fedora-atomic', 'coe': 'swarm'},
]
def __init__(self):
super(AtomicSwarmTemplateDefinition, self).__init__()
self.add_parameter('cluster_uuid',
cluster_attr='uuid',
param_type=str)
self.add_parameter('number_of_nodes',
cluster_attr='node_count')
self.add_parameter('master_flavor',
cluster_template_attr='master_flavor_id')
self.add_parameter('node_flavor',
cluster_template_attr='flavor_id')
self.add_parameter('docker_volume_size',
cluster_template_attr='docker_volume_size')
self.add_parameter('volume_driver',
cluster_template_attr='volume_driver')
self.add_parameter('external_network',
cluster_template_attr='external_network_id',
required=True)
self.add_parameter('network_driver',
cluster_template_attr='network_driver')
self.add_parameter('tls_disabled',
cluster_template_attr='tls_disabled',
required=True)
self.add_parameter('registry_enabled',
cluster_template_attr='registry_enabled')
self.add_parameter('docker_storage_driver',
cluster_template_attr='docker_storage_driver')
self.add_parameter('swarm_version',
cluster_attr='coe_version')
self.add_output('api_address',
cluster_attr='api_address',
mapping_type=SwarmApiAddressOutputMapping)
self.add_output('swarm_master_private',
cluster_attr=None)
self.add_output('swarm_masters',
cluster_attr='master_addresses')
self.add_output('swarm_nodes_private',
cluster_attr=None)
self.add_output('swarm_nodes',
cluster_attr='node_addresses')
self.add_output('discovery_url',
cluster_attr='discovery_url')
def get_params(self, context, cluster_template, cluster, **kwargs):
extra_params = kwargs.pop('extra_params', {})
extra_params['discovery_url'] = self.get_discovery_url(cluster)
# HACK(apmelton) - This uses the user's bearer token, ideally
# it should be replaced with an actual trust token with only
# access to do what the template needs it to do.
osc = self.get_osc(context)
extra_params['magnum_url'] = osc.magnum_url()
label_list = ['flannel_network_cidr', 'flannel_backend',
'flannel_network_subnetlen', 'rexray_preempt']
extra_params['auth_url'] = context.auth_url
for label in label_list:
extra_params[label] = cluster_template.labels.get(label)
if cluster_template.registry_enabled:
extra_params['swift_region'] = CONF.docker_registry.swift_region
extra_params['registry_container'] = (
CONF.docker_registry.swift_registry_container)
return super(AtomicSwarmTemplateDefinition,
self).get_params(context, cluster_template, cluster,
extra_params=extra_params,
**kwargs)
def get_env_files(self, cluster_template):
if cluster_template.master_lb_enabled:
return [template_def.COMMON_ENV_PATH + 'with_master_lb.yaml']
else:
return [template_def.COMMON_ENV_PATH + 'no_master_lb.yaml']
@property
def driver_module_path(self):
return __name__[:__name__.rindex('.')]

View File

@ -198,7 +198,7 @@ resources:
group: ungrouped
config:
str_replace:
template: {get_file: fragments/write-heat-params-master.yaml}
template: {get_file: ../../common/templates/swarm/fragments/write-heat-params-master.yaml}
params:
"$WAIT_HANDLE_ENDPOINT": {get_attr: [master_wait_handle, endpoint]}
"$WAIT_HANDLE_TOKEN": {get_attr: [master_wait_handle, token]}
@ -232,31 +232,31 @@ resources:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/write-network-config.sh}
config: {get_file: ../../common/templates/swarm/fragments/write-network-config.sh}
network_config_service:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/network-config-service.sh}
config: {get_file: ../../common/templates/swarm/fragments/network-config-service.sh}
network_service:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/network-service.sh}
config: {get_file: ../../common/templates/swarm/fragments/network-service.sh}
configure_etcd:
type: OS::Heat::SoftwareConfig
properties:
group: ungrouped
config: {get_file: fragments/configure-etcd.sh}
config: {get_file: ../../common/templates/swarm/fragments/configure-etcd.sh}
remove_docker_key:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/remove-docker-key.sh}
config: {get_file: ../../common/templates/swarm/fragments/remove-docker-key.sh}
configure_docker_storage:
type: OS::Heat::SoftwareConfig
@ -272,13 +272,13 @@ resources:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/make-cert.py}
config: {get_file: ../../common/templates/swarm/fragments/make-cert.py}
write_docker_service:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/write-docker-service.sh}
config: {get_file: ../../common/templates/swarm/fragments/write-docker-service.sh}
write_swarm_manager_failure_service:
type: "OS::Heat::SoftwareConfig"
@ -286,7 +286,7 @@ resources:
group: ungrouped
config:
str_replace:
template: {get_file: fragments/write-cluster-failure-service.yaml}
template: {get_file: ../../common/templates/swarm/fragments/write-cluster-failure-service.yaml}
params:
"$SERVICE": swarm-manager
"$WAIT_HANDLE_ENDPOINT": {get_attr: [master_wait_handle, endpoint]}
@ -296,7 +296,7 @@ resources:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/write-docker-socket.yaml}
config: {get_file: ../../common/templates/swarm/fragments/write-docker-socket.yaml}
write_swarm_master_service:
type: "OS::Heat::SoftwareConfig"
@ -304,7 +304,7 @@ resources:
group: ungrouped
config:
str_replace:
template: {get_file: fragments/write-swarm-master-service.sh}
template: {get_file: ../../common/templates/swarm/fragments/write-swarm-master-service.sh}
params:
"$ETCD_SERVER_IP": {get_attr: [etcd_address_switch, private_ip]}
"$NODE_IP": {get_attr: [swarm_master_eth0, fixed_ips, 0, ip_address]}
@ -322,7 +322,7 @@ resources:
group: ungrouped
config:
str_replace:
template: {get_file: fragments/enable-services.sh}
template: {get_file: ../../common/templates/swarm/fragments/enable-services.sh}
params:
"$NODE_SERVICES": "etcd docker.socket swarm-manager"
@ -330,25 +330,25 @@ resources:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/cfn-signal.sh}
config: {get_file: ../../common/templates/swarm/fragments/cfn-signal.sh}
disable_selinux:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/disable-selinux.sh}
config: {get_file: ../../common/templates/swarm/fragments/disable-selinux.sh}
add_proxy:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/add-proxy.sh}
config: {get_file: ../../common/templates/swarm/fragments/add-proxy.sh}
volume_service:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/volume-service.sh}
config: {get_file: ../../common/templates/swarm/fragments/volume-service.sh}
swarm_master_init:
type: "OS::Heat::MultipartMime"

View File

@ -183,7 +183,7 @@ resources:
group: ungrouped
config:
str_replace:
template: {get_file: fragments/write-heat-params-node.yaml}
template: {get_file: ../../common/templates/swarm/fragments/write-heat-params-node.yaml}
params:
"$WAIT_HANDLE_ENDPOINT": {get_attr: [node_wait_handle, endpoint]}
"$WAIT_HANDLE_TOKEN": {get_attr: [node_wait_handle, token]}
@ -221,13 +221,13 @@ resources:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/remove-docker-key.sh}
config: {get_file: ../../common/templates/swarm/fragments/remove-docker-key.sh}
make_cert:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/make-cert.py}
config: {get_file: ../../common/templates/swarm/fragments/make-cert.py}
configure_docker_storage:
type: OS::Heat::SoftwareConfig
@ -249,19 +249,19 @@ resources:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/write-docker-service.sh}
config: {get_file: ../../common/templates/swarm/fragments/write-docker-service.sh}
write_docker_socket:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/write-docker-socket.yaml}
config: {get_file: ../../common/templates/swarm/fragments/write-docker-socket.yaml}
network_service:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/network-service.sh}
config: {get_file: ../../common/templates/swarm/fragments/network-service.sh}
write_swarm_agent_failure_service:
type: "OS::Heat::SoftwareConfig"
@ -269,7 +269,7 @@ resources:
group: ungrouped
config:
str_replace:
template: {get_file: fragments/write-cluster-failure-service.yaml}
template: {get_file: ../../common/templates/swarm/fragments/write-cluster-failure-service.yaml}
params:
"$SERVICE": swarm-agent
"$WAIT_HANDLE_ENDPOINT": {get_attr: [node_wait_handle, endpoint]}
@ -279,7 +279,7 @@ resources:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/write-swarm-agent-service.sh}
config: {get_file: ../../common/templates/swarm/fragments/write-swarm-agent-service.sh}
enable_docker_registry:
type: OS::Heat::SoftwareConfig
@ -293,7 +293,7 @@ resources:
group: ungrouped
config:
str_replace:
template: {get_file: fragments/enable-services.sh}
template: {get_file: ../../common/templates/swarm/fragments/enable-services.sh}
params:
"$NODE_SERVICES": "docker.socket swarm-agent"
@ -301,25 +301,25 @@ resources:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/cfn-signal.sh}
config: {get_file: ../../common/templates/swarm/fragments/cfn-signal.sh}
disable_selinux:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/disable-selinux.sh}
config: {get_file: ../../common/templates/swarm/fragments/disable-selinux.sh}
add_proxy:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/add-proxy.sh}
config: {get_file: ../../common/templates/swarm/fragments/add-proxy.sh}
volume_service:
type: "OS::Heat::SoftwareConfig"
properties:
group: ungrouped
config: {get_file: fragments/volume-service.sh}
config: {get_file: ../../common/templates/swarm/fragments/volume-service.sh}
swarm_node_init:
type: "OS::Heat::MultipartMime"