Refactored coe_cluster{,_template} modules again

Change-Id: If9e28cf236db9a617657f177c0a7176eabc752ea
This commit is contained in:
Jakob Meng 2023-01-27 15:02:30 +01:00
parent 19d1d41ee0
commit 5b77519b89
6 changed files with 243 additions and 268 deletions

View File

@ -1,18 +1,26 @@
expected_fields: expected_fields:
# Magnum might return more fields according to its documentation [0] but - api_address
# openstacksdk normalizes coe cluster resources, moving most fields from
# top level into a 'properties' field [1].
# [0] https://docs.openstack.org/api-ref/container-infrastructure-management/#create-new-cluster
# [1] https://opendev.org/openstack/openstacksdk/src/commit/d57c1fcab3b6cbe806cbae735fefa4983b200ab2/openstack/cloud/_normalize.py#L484
- cluster_template_id - cluster_template_id
- coe_version
- create_timeout - create_timeout
- created_at
- discovery_url
- fixed_network
- fixed_subnet
- flavor_id
- id - id
- is_floating_ip_enabled
- is_master_lb_enabled
- keypair - keypair
- location - labels
- master_addresses
- master_count - master_count
- master_flavor_id
- name - name
- node_addresses
- node_count - node_count
- properties
- stack_id - stack_id
- status - status
- status_reason
- updated_at
- uuid - uuid

View File

@ -69,8 +69,8 @@
external_network_id: '{{ external_network.network.id }}' external_network_id: '{{ external_network.network.id }}'
fixed_network: ansible_internal_network fixed_network: ansible_internal_network
fixed_subnet: ansible_internal_subnet fixed_subnet: ansible_internal_subnet
floating_ip_enabled: true
image_id: '{{ image_id }}' image_id: '{{ image_id }}'
is_floating_ip_enabled: true
keypair_id: '{{ keypair.keypair.id }}' keypair_id: '{{ keypair.keypair.id }}'
name: k8s name: k8s
state: present state: present
@ -90,8 +90,8 @@
- name: Assert return values of coe_cluster module - name: Assert return values of coe_cluster module
assert: assert:
that: that:
# openstack.cloud.coe_cluster will only return 'id' on cluster creation when wait is false # allow new fields to be introduced but prevent fields from being removed
- "['id']|difference(coe_cluster.cluster.keys())|length == 0" - expected_fields|difference(coe_cluster.cluster.keys())|length == 0
- name: Pause for 1 minutes to allow Magnum to create the Kubernetes cluster - name: Pause for 1 minutes to allow Magnum to create the Kubernetes cluster
ansible.builtin.pause: ansible.builtin.pause:

View File

@ -1,40 +1,33 @@
expected_fields: expected_fields:
# Magnum might return more fields according to its documentation [0] but
# openstacksdk normalizes coe cluster template resources, moving most
# fields from top level into a 'properties' field [1].
# [0] https://docs.openstack.org/api-ref/container-infrastructure-management/#create-new-cluster
# [1] https://opendev.org/openstack/openstacksdk/src/commit/d57c1fcab3b6cbe806cbae735fefa4983b200ab2/openstack/cloud/_normalize.py#L522
- apiserver_port - apiserver_port
- cluster_distro - cluster_distro
- coe - coe
- created_at - created_at
- dns_nameserver - dns_nameserver
- docker_storage_driver
- docker_volume_size - docker_volume_size
- external_network_id - external_network_id
- fixed_network - fixed_network
- fixed_subnet - fixed_subnet
- flavor_id - flavor_id
- floating_ip_enabled
- http_proxy - http_proxy
- https_proxy - https_proxy
- id - id
- image_id - image_id
- insecure_registry - insecure_registry
- is_floating_ip_enabled
- is_hidden
- is_master_lb_enabled
- is_public - is_public
- is_registry_enabled - is_registry_enabled
- is_tls_disabled - is_tls_disabled
- keypair_id - keypair_id
- labels - labels
- location
- master_flavor_id - master_flavor_id
- name - name
- network_driver - network_driver
- no_proxy - no_proxy
- properties
- public
- registry_enabled
- server_type - server_type
- tls_disabled
- updated_at - updated_at
- uuid - uuid
- volume_driver - volume_driver

View File

@ -21,7 +21,7 @@
openstack.cloud.coe_cluster_template: openstack.cloud.coe_cluster_template:
cloud: "{{ cloud }}" cloud: "{{ cloud }}"
coe: kubernetes coe: kubernetes
floating_ip_enabled: false is_floating_ip_enabled: false
image_id: '{{ image_id }}' image_id: '{{ image_id }}'
keypair_id: '{{ keypair.keypair.id }}' keypair_id: '{{ keypair.keypair.id }}'
name: k8s name: k8s
@ -38,7 +38,7 @@
openstack.cloud.coe_cluster_template: openstack.cloud.coe_cluster_template:
cloud: "{{ cloud }}" cloud: "{{ cloud }}"
coe: kubernetes coe: kubernetes
floating_ip_enabled: false is_floating_ip_enabled: false
image_id: '{{ image_id }}' image_id: '{{ image_id }}'
keypair_id: '{{ keypair.keypair.id }}' keypair_id: '{{ keypair.keypair.id }}'
name: k8s name: k8s

View File

@ -22,25 +22,22 @@ options:
description: description:
- URL used for cluster node discovery. - URL used for cluster node discovery.
type: str type: str
docker_volume_size:
description:
- The size in GB of the docker volume.
type: int
flavor_id: flavor_id:
description: description:
- The flavor of the minion node for this cluster template. - The flavor of the minion node for this cluster template.
type: str type: str
floating_ip_enabled: is_floating_ip_enabled:
description: description:
- Indicates whether created cluster should have a floating ip. - Indicates whether created cluster should have a floating ip.
- Whether enable or not using the floating IP of cloud provider. Some - Whether enable or not using the floating IP of cloud provider. Some
cloud providers used floating IP, some used public IP, thus Magnum cloud providers used floating IP, some used public IP, thus Magnum
provide this option for specifying the choice of using floating IP. provide this option for specifying the choice of using floating IP.
- If not set, the value of I(floating_ip_enabled) of the cluster template - If not set, the value of I(is_floating_ip_enabled) of the cluster template
specified with I(cluster_template_id) will be used. specified with I(cluster_template_id) will be used.
- When I(floating_ip_enabled) is set to C(true), then - When I(is_floating_ip_enabled) is set to C(true), then
I(external_network_id) in cluster template must be defined. I(external_network_id) in cluster template must be defined.
type: bool type: bool
aliases: ['floating_ip_enabled']
keypair: keypair:
description: description:
- Name of the keypair to use. - Name of the keypair to use.
@ -74,82 +71,131 @@ options:
choices: [present, absent] choices: [present, absent]
default: present default: present
type: str type: str
notes:
- Return values of this module are preliminary and will most likely change
when openstacksdk has finished its transition of cloud layer functions to
resource proxies.
extends_documentation_fragment: extends_documentation_fragment:
- openstack.cloud.openstack - openstack.cloud.openstack
''' '''
# TODO: Update return values when coe related functions in openstacksdk
# have been ported to resource proxies.
RETURN = r''' RETURN = r'''
cluster: cluster:
description: Dictionary describing the cluster. description: Dictionary describing the cluster.
returned: On success when I(state) is C(present). returned: On success when I(state) is C(present).
type: complex type: dict
contains: contains:
api_address:
description: The endpoint URL of COE API exposed to end-users.
type: str
sample: https://172.24.4.30:6443
cluster_template_id: cluster_template_id:
description: The cluster_template UUID description: The UUID of the cluster template.
type: str type: str
sample: '7b1418c8-cea8-48fc-995d-52b66af9a9aa' sample: '7b1418c8-cea8-48fc-995d-52b66af9a9aa'
coe_version:
description: Version info of chosen COE in bay/cluster for helping
client in picking the right version of client.
type: str
sample: v1.11.1
create_timeout: create_timeout:
description: Timeout for creating the cluster in minutes. description: Timeout for creating the cluster in minutes.
Default to 60 if not set. Default to 60 if not set.
type: int type: int
sample: 60 sample: 60
created_at:
description: The date and time in UTC at which the cluster is created.
type: str
sample: "2018-08-16T10:29:45+00:00"
discovery_url:
description: The custom discovery url for node discovery. This is used
by the COE to discover the servers that have been created
to host the containers. The actual discovery mechanism
varies with the COE. In some cases, the service fills in
the server info in the discovery service. In other cases,
if the discovery_url is not specified, the service will
use the public discovery service at
U(https://discovery.etcd.io). In this case, the service
will generate a unique url here for each bay and store the
info for the servers.
type: str
sample: https://discovery.etcd.io/a42ee38e7113f31f4d6324f24367aae5
fixed_network:
description: The name or ID of the network to provide connectivity to the
internal network for the bay/cluster.
type: str
fixed_subnet:
description: The fixed subnet to use when allocating network addresses
for nodes in bay/cluster.
type: str
flavor_id:
description: The flavor name or ID to use when booting the node servers.
Defaults to m1.small.
type: str
id: id:
description: Unique UUID for this cluster. description: Unique UUID for this cluster.
type: str type: str
sample: '86246a4d-a16c-4a58-9e96ad7719fe0f9d' sample: '86246a4d-a16c-4a58-9e96ad7719fe0f9d'
is_floating_ip_enabled:
description: Indicates whether created clusters should have a
floating ip or not.
type: bool
sample: true
is_master_lb_enabled:
description: Indicates whether created clusters should have a load
balancer for master nodes or not.
type: bool
sample: true
keypair: keypair:
description: Name of the keypair to use. description: Name of the keypair to use.
type: str type: str
sample: mykey sample: mykey
location: labels:
description: The OpenStack location of this resource. description: One or more key/value pairs.
type: str type: dict
sample: {'key1': 'value1', 'key2': 'value2'}
master_addresses:
description: A list of floating IPs of all master nodes.
type: list
sample: ['172.24.4.5']
master_count: master_count:
description: The number of master nodes for this cluster. description: The number of servers that will serve as master for the
bay/cluster. Set to more than 1 master to enable High
Availability. If the option master-lb-enabled is specified
in the baymodel/cluster template, the master servers will
be placed in a load balancer pool. Defaults to 1.
type: int type: int
sample: 1 sample: 1
master_flavor_id:
description: The flavor of the master node for this baymodel/cluster
template.
type: str
sample: c1.c1r1
name: name:
description: Name that has to be given to the cluster. description: Name that has to be given to the cluster.
type: str type: str
sample: k8scluster sample: k8scluster
node_addresses:
description: A list of floating IPs of all servers that serve as nodes.
type: list
sample: ['172.24.4.8']
node_count: node_count:
description: The number of master nodes for this cluster. description: The number of master nodes for this cluster.
type: int type: int
sample: 1 sample: 1
properties:
description: Additional properties of the cluster template.
type: dict
sample: |
{
'api_address': 'https://172.24.4.30:6443',
'coe_version': 'v1.11.1',
'container_version': '1.12.6',
'created_at': '2018-08-16T10:29:45+00:00',
'discovery_url': 'https://discovery.etcd.io/a42...aae5',
'faults': {'0': 'ResourceInError: resources[0].resources...'},
'flavor_id': 'c1.c1r1',
'floating_ip_enabled': true,
'labels': {'key1': 'value1', 'key2': 'value2'},
'master_addresses': ['172.24.4.5'],
'master_flavor_id': 'c1.c1r1',
'node_addresses': ['172.24.4.8'],
'status_reason': 'Stack CREATE completed successfully',
'updated_at': '2018-08-16T10:39:25+00:00',
}
stack_id: stack_id:
description: Stack id of the Heat stack. description: The reference UUID of orchestration stack from Heat
orchestration service.
type: str type: str
sample: '07767ec6-85f5-44cb-bd63-242a8e7f0d9d' sample: '07767ec6-85f5-44cb-bd63-242a8e7f0d9d'
status: status:
description: Status of the cluster from the heat stack. description: Status of the cluster from the heat stack.
type: str type: str
sample: 'CREATE_COMLETE' sample: 'CREATE_COMLETE'
status_reason:
description: Status reason of the cluster from the heat stack
type: str
sample: 'Stack CREATE completed successfully'
updated_at:
description: The date and time in UTC at which the cluster was updated.
type: str
sample: '2018-08-16T10:39:25+00:00'
uuid: uuid:
description: Unique UUID for this cluster. description: Unique UUID for this cluster.
type: str type: str
@ -174,9 +220,9 @@ class COEClusterModule(OpenStackModule):
argument_spec = dict( argument_spec = dict(
cluster_template_id=dict(), cluster_template_id=dict(),
discovery_url=dict(), discovery_url=dict(),
docker_volume_size=dict(type='int'),
flavor_id=dict(), flavor_id=dict(),
floating_ip_enabled=dict(type='bool'), is_floating_ip_enabled=dict(type='bool',
aliases=['floating_ip_enabled']),
keypair=dict(no_log=False), # := noqa no-log-needed keypair=dict(no_log=False), # := noqa no-log-needed
labels=dict(type='raw'), labels=dict(type='raw'),
master_count=dict(type='int'), master_count=dict(type='int'),
@ -204,10 +250,7 @@ class COEClusterModule(OpenStackModule):
# Create cluster # Create cluster
cluster = self._create() cluster = self._create()
self.exit_json(changed=True, self.exit_json(changed=True,
# TODO: Add .to_dict(computed=False) when Munch cluster=cluster.to_dict(computed=False))
# object has been replaced with openstacksdk
# resource object.
cluster=cluster)
elif state == 'present' and cluster: elif state == 'present' and cluster:
# Update cluster # Update cluster
@ -216,10 +259,7 @@ class COEClusterModule(OpenStackModule):
cluster = self._update(cluster, update) cluster = self._update(cluster, update)
self.exit_json(changed=bool(update), self.exit_json(changed=bool(update),
# TODO: Add .to_dict(computed=False) when Munch cluster=cluster.to_dict(computed=False))
# object has been replaced with openstacksdk
# resource object.
cluster=cluster)
elif state == 'absent' and cluster: elif state == 'absent' and cluster:
# Delete cluster # Delete cluster
@ -235,9 +275,8 @@ class COEClusterModule(OpenStackModule):
# TODO: Implement support for updates. # TODO: Implement support for updates.
non_updateable_keys = [k for k in ['cluster_template_id', non_updateable_keys = [k for k in ['cluster_template_id',
'discovery_url', 'discovery_url', 'flavor_id',
'docker_volume_size', 'flavor_id', 'is_floating_ip_enabled', 'keypair',
'floating_ip_enabled', 'keypair',
'master_count', 'master_flavor_id', 'master_count', 'master_flavor_id',
'name', 'node_count'] 'name', 'node_count']
if self.params[k] is not None if self.params[k] is not None
@ -270,9 +309,8 @@ class COEClusterModule(OpenStackModule):
# specifying names in addition to IDs. # specifying names in addition to IDs.
kwargs = dict((k, self.params[k]) kwargs = dict((k, self.params[k])
for k in ['cluster_template_id', 'discovery_url', for k in ['cluster_template_id', 'discovery_url',
'docker_volume_size', 'flavor_id', 'flavor_id', 'is_floating_ip_enabled',
'floating_ip_enabled', 'keypair', 'keypair', 'master_count', 'master_flavor_id',
'master_count', 'master_flavor_id',
'name', 'node_count'] 'name', 'node_count']
if self.params[k] is not None) if self.params[k] is not None)
@ -285,57 +323,33 @@ class COEClusterModule(OpenStackModule):
kwargs['create_timeout'] = self.params['timeout'] kwargs['create_timeout'] = self.params['timeout']
# TODO: Replace with self.conn.container_infrastructure_management.\ cluster = self.conn.container_infrastructure_management.\
# create_cluster() when available in openstacksdk. create_cluster(**kwargs)
cluster = self.conn.create_coe_cluster(**kwargs)
if not self.params['wait']: if not self.params['wait']:
# openstacksdk's create_coe_cluster() returns a cluster's uuid only # openstacksdk's create_cluster() returns a cluster's id only
# but we cannot use self.conn.get_coe_cluster(cluster_id) because # but we cannot use self.conn.container_infrastructure_management.\
# it might return None as long as the cluster is being set up. # get_cluster(cluster_id) because it might return None as long as
# the cluster is being set up.
return cluster return cluster
cluster_id = cluster['id']
if self.params['wait']: if self.params['wait']:
# TODO: Replace with self.sdk.resource.wait_for_status() when cluster = self.sdk.resource.wait_for_status(
# resource creation has been ported to self.conn.\ self.conn.container_infrastructure_management, cluster,
# container_infrastructure_management.create_cluster() status='active',
for count in self.sdk.utils.iterate_timeout( failures=['error'],
timeout=self.params['timeout'], wait=self.params['timeout'])
message="Timeout waiting for cluster to be present"
):
# Fetch cluster again
cluster = self.conn.get_coe_cluster(cluster_id)
if cluster is None:
continue
elif cluster.status.lower() == 'active':
break
elif cluster.status.lower() in ['error']:
self.fail_json(msg="{0} transitioned to failure state {1}"
.format(cluster.name, 'error'))
return cluster return cluster
def _delete(self, cluster): def _delete(self, cluster):
# TODO: Replace with self.conn.container_infrastructure_management.\ self.conn.container_infrastructure_management.\
# delete_cluster() when available in openstacksdk. delete_cluster(cluster['id'])
self.conn.delete_coe_cluster(cluster.name)
# TODO: Replace with self.sdk.resource.wait_for_delete() when
# resource fetch has been ported to self.conn.\
# container_infrastructure_management.find_cluster()
if self.params['wait']: if self.params['wait']:
for count in self.sdk.utils.iterate_timeout( self.sdk.resource.wait_for_delete(
timeout=self.params['timeout'], self.conn.container_infrastructure_management, cluster,
message="Timeout waiting for cluster to be absent" interval=None, wait=self.params['timeout'])
):
cluster = self.conn.get_coe_cluster(cluster.id)
if cluster is None:
break
elif cluster['status'].lower() == 'deleted':
break
def _find(self): def _find(self):
name = self.params['name'] name = self.params['name']
@ -345,18 +359,14 @@ class COEClusterModule(OpenStackModule):
if cluster_template_id is not None: if cluster_template_id is not None:
filters['cluster_template_id'] = cluster_template_id filters['cluster_template_id'] = cluster_template_id
# TODO: Replace with self.conn.container_infrastructure_management.\
# find_cluster() when available in openstacksdk.
return self.conn.get_coe_cluster(name_or_id=name, filters=filters) return self.conn.get_coe_cluster(name_or_id=name, filters=filters)
def _update(self, cluster, update): def _update(self, cluster, update):
attributes = update.get('attributes') attributes = update.get('attributes')
if attributes: if attributes:
# TODO: Implement support for updates. # TODO: Implement support for updates.
# TODO: Replace with self.conn.\ # cluster = self.conn.container_infrastructure_management.\
# container_infrastructure_management.\ # update_cluster(...)
# update_cluster() when available in openstacksdk.
# cluster = self.conn.update_coe_cluster(...)
pass pass
return cluster return cluster

View File

@ -36,7 +36,7 @@ options:
external_network_id: external_network_id:
description: description:
- The external network to attach to the cluster. - The external network to attach to the cluster.
- When I(floating_ip_enabled) is set to C(true), then - When I(is_floating_ip_enabled) is set to C(true), then
I(external_network_id) must be defined. I(external_network_id) must be defined.
type: str type: str
fixed_network: fixed_network:
@ -51,13 +51,41 @@ options:
description: description:
- The flavor of the minion node for this cluster template. - The flavor of the minion node for this cluster template.
type: str type: str
floating_ip_enabled: is_floating_ip_enabled:
description: description:
- Indicates whether created clusters should have a floating ip or not. - Indicates whether created clusters should have a floating ip or not.
- When I(floating_ip_enabled) is set to C(true), then - When I(is_floating_ip_enabled) is set to C(true), then
I(external_network_id) must be defined. I(external_network_id) must be defined.
type: bool type: bool
default: true default: true
aliases: ['floating_ip_enabled']
is_master_lb_enabled:
description:
- Indicates whether created clusters should have a load balancer
for master nodes or not.
- Magnum's default value for I(is_master_lb_enabled) is C(true),
ours is C(false).
type: bool
default: false
aliases: ['master_lb_enabled']
is_public:
description:
- Indicates whether the cluster template is public or not.
- Magnum's default value for I(is_public) is C(false).
type: bool
aliases: ['public']
is_registry_enabled:
description:
- Indicates whether the docker registry is enabled.
- Magnum's default value for I(is_registry_enabled) is C(false).
type: bool
aliases: ['registry_enabled']
is_tls_disabled:
description:
- Indicates whether the TLS should be disabled.
- Magnum's default value for I(is_tls_disabled) is C(false).
type: bool
aliases: ['tls_disabled']
keypair_id: keypair_id:
description: description:
- Name or ID of the keypair to use. - Name or ID of the keypair to use.
@ -85,14 +113,6 @@ options:
description: description:
- The flavor of the master node for this cluster template. - The flavor of the master node for this cluster template.
type: str type: str
master_lb_enabled:
description:
- Indicates whether created clusters should have a load balancer
for master nodes or not.
- Magnum's default value for I(master_lb_enabled) is C(true),
ours is C(false).
type: bool
default: false
name: name:
description: description:
- Name that has to be given to the cluster template. - Name that has to be given to the cluster template.
@ -108,16 +128,6 @@ options:
- A comma separated list of IPs for which proxies should not be - A comma separated list of IPs for which proxies should not be
used in the cluster. used in the cluster.
type: str type: str
public:
description:
- Indicates whether the cluster template is public or not.
- Magnum's default value for I(public) is C(false).
type: bool
registry_enabled:
description:
- Indicates whether the docker registry is enabled.
- Magnum's default value for I(registry_enabled) is C(false).
type: bool
server_type: server_type:
description: description:
- Server type for this cluster template. - Server type for this cluster template.
@ -130,31 +140,20 @@ options:
choices: [present, absent] choices: [present, absent]
default: present default: present
type: str type: str
tls_disabled:
description:
- Indicates whether the TLS should be disabled.
- Magnum's default value for I(tls_disabled) is C(false).
type: bool
volume_driver: volume_driver:
description: description:
- The name of the driver used for instantiating container volumes. - The name of the driver used for instantiating container volumes.
choices: [cinder, rexray] choices: [cinder, rexray]
type: str type: str
notes:
- Return values of this module are preliminary and will most likely change
when openstacksdk has finished its transition of cloud layer functions to
resource proxies.
extends_documentation_fragment: extends_documentation_fragment:
- openstack.cloud.openstack - openstack.cloud.openstack
''' '''
# TODO: Update return values when coe related functions in openstacksdk
# have been ported to resource proxies.
RETURN = r''' RETURN = r'''
cluster_template: cluster_template:
description: Dictionary describing the template. description: Dictionary describing the template.
returned: On success when I(state) is C(present). returned: On success when I(state) is C(present).
type: complex type: dict
contains: contains:
apiserver_port: apiserver_port:
description: The exposed port of COE API server. description: The exposed port of COE API server.
@ -165,26 +164,33 @@ cluster_template:
type: str type: str
coe: coe:
description: The Container Orchestration Engine for this cluster description: The Container Orchestration Engine for this cluster
template. template. Supported COEs include kubernetes, swarm, mesos.
type: str type: str
sample: kubernetes sample: kubernetes
created_at: created_at:
description: The date and time when the resource was created. description: The date and time when the resource was created.
type: str type: str
dns_nameserver: dns_nameserver:
description: The DNS nameserver address description: The DNS nameserver for the servers and containers in the
bay/cluster to use.
type: str type: str
sample: '8.8.8.8' sample: '8.8.8.8'
docker_storage_driver:
description: "The name of a driver to manage the storage for the images
and the container's writable layer."
type: str
docker_volume_size: docker_volume_size:
description: The size in GB of the docker volume description: The size in GB for the local storage on each server for the
Docker daemon to cache the images and host the containers.
type: int type: int
sample: 5 sample: 5
external_network_id: external_network_id:
description: The external network to attach to the cluster description: The name or network ID of a Neutron network to provide
connectivity to the external internet for the bay/cluster.
type: str type: str
sample: public sample: public
fixed_network: fixed_network:
description: The fixed network name to attach to the cluster description: The fixed network name to attach to the cluster.
type: str type: str
sample: 07767ec6-85f5-44cb-bd63-242a8e7f0d9d sample: 07767ec6-85f5-44cb-bd63-242a8e7f0d9d
fixed_subnet: fixed_subnet:
@ -192,14 +198,9 @@ cluster_template:
type: str type: str
sample: 05567ec6-85f5-44cb-bd63-242a8e7f0d9d sample: 05567ec6-85f5-44cb-bd63-242a8e7f0d9d
flavor_id: flavor_id:
description: The flavor of the minion node for this cluster template. description: The nova flavor ID or name for booting the node servers.
type: str type: str
sample: c1.c1r1 sample: c1.c1r1
floating_ip_enabled:
description: Indicates whether created clusters should have a
floating ip or not.
type: bool
sample: true
http_proxy: http_proxy:
description: Address of a proxy that will receive all HTTP requests description: Address of a proxy that will receive all HTTP requests
and relay them. The format is a URL including a port and relay them. The format is a URL including a port
@ -216,13 +217,28 @@ cluster_template:
description: The UUID of the cluster template. description: The UUID of the cluster template.
type: str type: str
image_id: image_id:
description: Image id the cluster will be based on. description: The name or UUID of the base image in Glance to boot the
servers for the bay/cluster.
type: str type: str
sample: 05567ec6-85f5-44cb-bd63-242a8e7f0e9d sample: 05567ec6-85f5-44cb-bd63-242a8e7f0e9d
insecure_registry: insecure_registry:
description: "The URL pointing to users's own private insecure docker description: "The URL pointing to users's own private insecure docker
registry to deploy and run docker containers." registry to deploy and run docker containers."
type: str type: str
is_floating_ip_enabled:
description: Indicates whether created clusters should have a
floating ip or not.
type: bool
sample: true
is_hidden:
description: Indicates whether the cluster template is hidden or not.
type: bool
sample: false
is_master_lb_enabled:
description: Indicates whether created clusters should have a load
balancer for master nodes or not.
type: bool
sample: true
is_public: is_public:
description: Access to a baymodel/cluster template is normally limited to description: Access to a baymodel/cluster template is normally limited to
the admin, owner or users within the same tenant as the the admin, owner or users within the same tenant as the
@ -230,6 +246,7 @@ cluster_template:
template public and accessible by other users. The default template public and accessible by other users. The default
is not public. is not public.
type: bool type: bool
sample: false
is_registry_enabled: is_registry_enabled:
description: "Docker images by default are pulled from the public Docker description: "Docker images by default are pulled from the public Docker
registry, but in some cases, users may want to use a registry, but in some cases, users may want to use a
@ -238,6 +255,7 @@ cluster_template:
local registry in the bay/cluster backed by swift to host local registry in the bay/cluster backed by swift to host
the images. The default is to use the public registry." the images. The default is to use the public registry."
type: bool type: bool
sample: false
is_tls_disabled: is_tls_disabled:
description: Transport Layer Security (TLS) is normally enabled to secure description: Transport Layer Security (TLS) is normally enabled to secure
the bay/cluster. In some cases, users may want to disable the bay/cluster. In some cases, users may want to disable
@ -246,33 +264,27 @@ cluster_template:
will disable TLS so that users can access the COE endpoints will disable TLS so that users can access the COE endpoints
without a certificate. The default is TLS enabled. without a certificate. The default is TLS enabled.
type: bool type: bool
sample: false
keypair_id: keypair_id:
description: Name or ID of the keypair to use. description: Name of the SSH keypair to configure in the bay/cluster
servers for ssh access.
type: str type: str
sample: mykey sample: mykey
labels: labels:
description: One or more key/value pairs. description: One or more key/value pairs.
type: dict type: dict
sample: {'key1': 'value1', 'key2': 'value2'} sample: {'key1': 'value1', 'key2': 'value2'}
location:
description: The OpenStack location of this resource.
type: str
master_flavor_id: master_flavor_id:
description: The flavor of the master node for this cluster template. description: The flavor of the master node for this cluster template.
type: str type: str
sample: c1.c1r1 sample: c1.c1r1
master_lb_enabled:
description: Indicates whether created clusters should have a load
balancer for master nodes or not.
type: bool
sample: true
name: name:
description: Name that has to be given to the cluster template. description: Name that has to be given to the cluster template.
type: str type: str
sample: k8scluster sample: k8scluster
network_driver: network_driver:
description: description: The name of a network driver for providing the networks for
- The name of the driver used for instantiating container networks the containers
type: str type: str
sample: calico sample: calico
no_proxy: no_proxy:
@ -280,48 +292,10 @@ cluster_template:
not be used in the cluster. not be used in the cluster.
type: str type: str
sample: 10.0.0.4,10.0.0.5 sample: 10.0.0.4,10.0.0.5
properties:
description: Additional properties of the cluster template.
type: dict
sample: |
{
"docker_storage_driver": null,
"hidden": false,
"master_lb_enabled": false,
"project_id": "8fb245a1bd714d9a82e419f2b7bb69dd",
"tags": null,
"user_id": "51510ce12e294d5d9c7391bececcd1e8"
}
public:
description: Access to a baymodel/cluster template is normally limited
to the admin, owner or users within the same tenant as the
owners. Setting this flag makes the baymodel/cluster
template public and accessible by other users. The default
is not public.
type: bool
sample: false
registry_enabled:
description: "Docker images by default are pulled from the public Docker
registry, but in some cases, users may want to use a
private registry. This option provides an alternative
registry based on the Registry V2: Magnum will create a
local registry in the bay/cluster backed by swift to host
the images. The default is to use the public registry."
type: bool
sample: false
server_type: server_type:
description: Server type for this cluster template. description: The servers in the bay/cluster can be vm or baremetal.
type: str type: str
sample: vm sample: vm
tls_disabled:
description: Transport Layer Security (TLS) is normally enabled to secure
the bay/cluster. In some cases, users may want to disable
TLS in the bay/cluster, for instance during development or
to troubleshoot certain problems. Specifying this parameter
will disable TLS so that users can access the COE endpoints
without a certificate. The default is TLS enabled.
type: bool
sample: false
updated_at: updated_at:
description: The date and time when the resource was updated. description: The date and time when the resource was updated.
type: str type: str
@ -329,8 +303,8 @@ cluster_template:
description: The UUID of the cluster template. description: The UUID of the cluster template.
type: str type: str
volume_driver: volume_driver:
description: The name of the driver used for instantiating container description: The name of a volume driver for managing the persistent
volumes. storage for the containers.
type: str type: str
sample: cinder sample: cinder
''' '''
@ -343,7 +317,7 @@ EXAMPLES = r'''
image_id: 2a8c9888-9054-4b06-a1ca-2bb61f9adb72 image_id: 2a8c9888-9054-4b06-a1ca-2bb61f9adb72
keypair_id: mykey keypair_id: mykey
name: k8s name: k8s
public: no is_public: no
''' '''
from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule from ansible_collections.openstack.cloud.plugins.module_utils.openstack import OpenStackModule
@ -360,22 +334,24 @@ class COEClusterTemplateModule(OpenStackModule):
fixed_network=dict(), fixed_network=dict(),
fixed_subnet=dict(), fixed_subnet=dict(),
flavor_id=dict(), flavor_id=dict(),
floating_ip_enabled=dict(type='bool', default=True),
http_proxy=dict(), http_proxy=dict(),
https_proxy=dict(), https_proxy=dict(),
image_id=dict(), image_id=dict(),
is_floating_ip_enabled=dict(type='bool', default=True,
aliases=['floating_ip_enabled']),
keypair_id=dict(), keypair_id=dict(),
labels=dict(type='raw'), labels=dict(type='raw'),
master_flavor_id=dict(), master_flavor_id=dict(),
master_lb_enabled=dict(type='bool', default=False), is_master_lb_enabled=dict(type='bool', default=False,
aliases=['master_lb_enabled']),
is_public=dict(type='bool', aliases=['public']),
is_registry_enabled=dict(type='bool', aliases=['registry_enabled']),
is_tls_disabled=dict(type='bool', aliases=['tls_disabled']),
name=dict(required=True), name=dict(required=True),
network_driver=dict(choices=['flannel', 'calico', 'docker']), network_driver=dict(choices=['flannel', 'calico', 'docker']),
no_proxy=dict(), no_proxy=dict(),
public=dict(type='bool'),
registry_enabled=dict(type='bool'),
server_type=dict(choices=['vm', 'bm']), server_type=dict(choices=['vm', 'bm']),
state=dict(default='present', choices=['absent', 'present']), state=dict(default='present', choices=['absent', 'present']),
tls_disabled=dict(type='bool'),
volume_driver=dict(choices=['cinder', 'rexray']), volume_driver=dict(choices=['cinder', 'rexray']),
) )
module_kwargs = dict( module_kwargs = dict(
@ -398,9 +374,7 @@ class COEClusterTemplateModule(OpenStackModule):
cluster_template = self._create() cluster_template = self._create()
self.exit_json( self.exit_json(
changed=True, changed=True,
# TODO: Add .to_dict(computed=False) when Munch object has cluster_template=cluster_template.to_dict(computed=False))
# been replaced with openstacksdk resource object.
cluster_template=cluster_template)
elif state == 'present' and cluster_template: elif state == 'present' and cluster_template:
# Update cluster_template # Update cluster_template
@ -410,9 +384,7 @@ class COEClusterTemplateModule(OpenStackModule):
self.exit_json( self.exit_json(
changed=bool(update), changed=bool(update),
# TODO: Add .to_dict(computed=False) when Munch object has cluster_template=cluster_template.to_dict(computed=False))
# been replaced with openstacksdk resource object.
cluster_template=cluster_template)
elif state == 'absent' and cluster_template: elif state == 'absent' and cluster_template:
# Delete cluster_template # Delete cluster_template
@ -426,9 +398,9 @@ class COEClusterTemplateModule(OpenStackModule):
def _build_update(self, cluster_template): def _build_update(self, cluster_template):
update = {} update = {}
if self.params['floating_ip_enabled'] \ if self.params['is_floating_ip_enabled'] \
and self.params['external_network_id'] is None: and self.params['external_network_id'] is None:
raise ValueError('floating_ip_enabled is True' raise ValueError('is_floating_ip_enabled is True'
' but external_network_id is missing') ' but external_network_id is missing')
# TODO: Implement support for updates. # TODO: Implement support for updates.
@ -438,18 +410,16 @@ class COEClusterTemplateModule(OpenStackModule):
'external_network_id', 'external_network_id',
'fixed_network', 'fixed_network',
'fixed_subnet', 'flavor_id', 'fixed_subnet', 'flavor_id',
'floating_ip_enabled',
'http_proxy', 'https_proxy', 'http_proxy', 'https_proxy',
'image_id', 'keypair_id', 'image_id',
'master_flavor_id', 'is_floating_ip_enabled',
'master_lb_enabled', 'name', 'is_master_lb_enabled',
'is_public', 'is_registry_enabled',
'is_tls_disabled', 'keypair_id',
'master_flavor_id', 'name',
'network_driver', 'no_proxy', 'network_driver', 'no_proxy',
'public', 'registry_enabled', 'server_type', 'volume_driver']
'server_type', 'tls_disabled',
'volume_driver']
if self.params[k] is not None if self.params[k] is not None
and k in cluster_template # drop when
# cluster_template got ported to resource proxy
and self.params[k] != cluster_template[k]] and self.params[k] != cluster_template[k]]
labels = self.params['labels'] labels = self.params['labels']
@ -475,9 +445,9 @@ class COEClusterTemplateModule(OpenStackModule):
return update return update
def _create(self): def _create(self):
if self.params['floating_ip_enabled'] \ if self.params['is_floating_ip_enabled'] \
and self.params['external_network_id'] is None: and self.params['external_network_id'] is None:
raise ValueError('floating_ip_enabled is True' raise ValueError('is_floating_ip_enabled is True'
' but external_network_id is missing') ' but external_network_id is missing')
# TODO: Complement *_id parameters with find_* functions to allow # TODO: Complement *_id parameters with find_* functions to allow
@ -486,13 +456,14 @@ class COEClusterTemplateModule(OpenStackModule):
for k in ['coe', 'dns_nameserver', for k in ['coe', 'dns_nameserver',
'docker_storage_driver', 'docker_volume_size', 'docker_storage_driver', 'docker_volume_size',
'external_network_id', 'fixed_network', 'external_network_id', 'fixed_network',
'fixed_subnet', 'flavor_id', 'fixed_subnet', 'flavor_id', 'http_proxy',
'floating_ip_enabled', 'http_proxy', 'https_proxy', 'image_id',
'https_proxy', 'image_id', 'keypair_id', 'is_floating_ip_enabled',
'master_flavor_id', 'master_lb_enabled', 'is_master_lb_enabled', 'is_public',
'name', 'network_driver', 'no_proxy', 'public', 'is_registry_enabled', 'is_tls_disabled',
'registry_enabled', 'server_type', 'keypair_id', 'master_flavor_id', 'name',
'tls_disabled', 'volume_driver'] 'network_driver', 'no_proxy', 'server_type',
'volume_driver']
if self.params[k] is not None) if self.params[k] is not None)
labels = self.params['labels'] labels = self.params['labels']
@ -502,14 +473,12 @@ class COEClusterTemplateModule(OpenStackModule):
for kv in labels.split(",")]) for kv in labels.split(",")])
kwargs['labels'] = labels kwargs['labels'] = labels
# TODO: Replace with self.conn.container_infrastructure_management.\ return self.conn.container_infrastructure_management.\
# create_cluster_template() when available in openstacksdk. create_cluster_template(**kwargs)
return self.conn.create_cluster_template(**kwargs)
def _delete(self, cluster_template): def _delete(self, cluster_template):
# TODO: Replace with self.conn.container_infrastructure_management.\ self.conn.container_infrastructure_management.\
# delete_cluster_template() when available in openstacksdk. delete_cluster_template(cluster_template['id'])
self.conn.delete_cluster_template(cluster_template.name)
def _find(self): def _find(self):
name = self.params['name'] name = self.params['name']
@ -523,20 +492,15 @@ class COEClusterTemplateModule(OpenStackModule):
if coe is not None: if coe is not None:
filters['coe'] = coe filters['coe'] = coe
# TODO: Replace with self.conn.container_infrastructure_management.\
# find_cluster_template() when available in openstacksdk.
return self.conn.get_cluster_template(name_or_id=name, return self.conn.get_cluster_template(name_or_id=name,
filters=filters, filters=filters)
detail=True)
def _update(self, cluster_template, update): def _update(self, cluster_template, update):
attributes = update.get('attributes') attributes = update.get('attributes')
if attributes: if attributes:
# TODO: Implement support for updates. # TODO: Implement support for updates.
# TODO: Replace with self.conn.\ # cluster_template = self.conn.\
# container_infrastructure_management.\ # container_infrastructure_management.update_cluster_template(...)
# update_cluster_template() when available in openstacksdk.
# cluster_template = self.conn.update_cluster_template(...)
pass pass
return cluster_template return cluster_template