From 7f029b759c76babd46c7844860db447b62a02c28 Mon Sep 17 00:00:00 2001 From: Sam Yaple <sam@yaple.net> Date: Sat, 15 Aug 2015 01:38:35 +0000 Subject: [PATCH] Add Dockerfile template for kolla-ansible Change-Id: I53113d2a7595177839daebe74fa5bc409573f824 Partially-Implements: blueprint dockerfile-template --- .../kolla-ansible/kolla_keystone_service.py | 85 +------------------ .../kolla-ansible/kolla_keystone_user.py | 84 +----------------- .../kolla-ansible/kolla_keystone_service.py | 84 ++++++++++++++++++ .../kolla-ansible/kolla_keystone_user.py | 83 ++++++++++++++++++ docker_templates/kolla-ansible/Dockerfile.j2 | 36 ++++++++ .../kolla-ansible/kolla_keystone_service.py | 1 + .../kolla-ansible/kolla_keystone_user.py | 1 + tox.ini | 2 +- 8 files changed, 208 insertions(+), 168 deletions(-) mode change 100644 => 120000 docker/centos/binary/kolla-ansible/kolla_keystone_service.py mode change 100644 => 120000 docker/centos/binary/kolla-ansible/kolla_keystone_user.py create mode 100644 docker/common/kolla-ansible/kolla_keystone_service.py create mode 100644 docker/common/kolla-ansible/kolla_keystone_user.py create mode 100644 docker_templates/kolla-ansible/Dockerfile.j2 create mode 120000 docker_templates/kolla-ansible/kolla_keystone_service.py create mode 120000 docker_templates/kolla-ansible/kolla_keystone_user.py diff --git a/docker/centos/binary/kolla-ansible/kolla_keystone_service.py b/docker/centos/binary/kolla-ansible/kolla_keystone_service.py deleted file mode 100644 index 455aaf578..000000000 --- a/docker/centos/binary/kolla-ansible/kolla_keystone_service.py +++ /dev/null @@ -1,84 +0,0 @@ -#!/usr/bin/python - -# Copyright 2015 Sam Yaple -# -# 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. - -# This file is a barebones file needed to file a gap until Ansible 2.0. No error -# checking, no deletions, no updates. Idempotent creation only. - -# If you look closely, you will see we arent _really_ using the shade module -# we just use it to slightly abstract the authentication model. As patches land -# in upstream shade we will be able to use more of the shade module. Until then -# if we want to be 'stable' we really need to be using it as a passthrough - -import shade - -def main(): - module = AnsibleModule( - argument_spec = openstack_full_argument_spec( - description = dict(required=True, type='str'), - service_name = dict(required=True, type='str'), - service_type = dict(required=True, type='str'), - admin_url = dict(required=True, type='str'), - internal_url = dict(required=True, type='str'), - public_url = dict(required=True, type='str'), - endpoint_region = dict(required=True, type='str') - ) - ) - - try: - description = module.params.pop('description') - service_name = module.params.pop('service_name') - service_type = module.params.pop('service_type') - admin_url = module.params.pop('admin_url') - internal_url = module.params.pop('internal_url') - public_url = module.params.pop('public_url') - endpoint_region = module.params.pop('endpoint_region') - - changed = False - service = None - endpoint = None - - cloud = shade.operator_cloud(**module.params) - - for _service in cloud.keystone_client.services.list(): - if _service.type == service_type: - service = _service - - if service is not None: - for _endpoint in cloud.keystone_client.endpoints.list(): - if _endpoint.service_id == service.id: - endpoint = _endpoint - else: - service = cloud.keystone_client.services.create(name=service_name, - service_type=service_type, - description=description) - - if endpoint is None: - changed = True - cloud.keystone_client.endpoints.create(service_id=service.id, - adminurl=admin_url, - internalurl=public_url, - publicurl=public_url, - region=endpoint_region) - - module.exit_json(changed=changed) - except Exception as e: - module.exit_json(failed=True, changed=True, msg=e) - -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.openstack import * -if __name__ == '__main__': - main() diff --git a/docker/centos/binary/kolla-ansible/kolla_keystone_service.py b/docker/centos/binary/kolla-ansible/kolla_keystone_service.py new file mode 120000 index 000000000..835cfdf1b --- /dev/null +++ b/docker/centos/binary/kolla-ansible/kolla_keystone_service.py @@ -0,0 +1 @@ +../../../common/kolla-ansible/kolla_keystone_service.py \ No newline at end of file diff --git a/docker/centos/binary/kolla-ansible/kolla_keystone_user.py b/docker/centos/binary/kolla-ansible/kolla_keystone_user.py deleted file mode 100644 index 5d295c1e2..000000000 --- a/docker/centos/binary/kolla-ansible/kolla_keystone_user.py +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/python - -# Copyright 2015 Sam Yaple -# -# 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. - -# This file is a barebones file needed to file a gap until Ansible 2.0. No error -# checking, no deletions, no updates. Idempotent creation only. - -# If you look closely, you will see we arent _really_ using the shade module -# we just use it to slightly abstract the authentication model. As patches land -# in upstream shade we will be able to use more of the shade module. Until then -# if we want to be 'stable' we really need to be using it as a passthrough - -import shade - -def main(): - module = AnsibleModule( - argument_spec = openstack_full_argument_spec( - password = dict(required=True, type='str'), - project = dict(required=True, type='str'), - role = dict(required=True, type='str'), - user = dict(required=True, type='str') - ) - ) - - try: - password = module.params.pop('password') - project_name = module.params.pop('project') - role_name = module.params.pop('role') - user_name = module.params.pop('user') - - changed = False - project = None - role = None - user = None - - cloud = shade.operator_cloud(**module.params) - - for _project in cloud.keystone_client.tenants.list(): - if _project.name == project_name: - project = _project - - for _role in cloud.keystone_client.roles.list(): - if _role.name == role_name: - role = _role - - for _user in cloud.keystone_client.users.list(): - if _user.name == user_name: - user = _user - - if not project: - changed = True - project = cloud.keystone_client.tenants.create(tenant_name=project_name) - - if not role: - changed = True - role = cloud.keystone_client.roles.create(name=role_name) - - if not user: - changed = True - user = cloud.keystone_client.users.create(name=user_name, password=password, tenant_id=project.id) - cloud.keystone_client.roles.add_user_role(role=role.id, user=user.id, tenant=project.id) - - module.exit_json(changed=changed) - except Exception as e: - module.exit_json(failed=True, changed=True, msg=e) - -# import module snippets -from ansible.module_utils.basic import * -from ansible.module_utils.openstack import * -if __name__ == '__main__': - main() diff --git a/docker/centos/binary/kolla-ansible/kolla_keystone_user.py b/docker/centos/binary/kolla-ansible/kolla_keystone_user.py new file mode 120000 index 000000000..e1070edaf --- /dev/null +++ b/docker/centos/binary/kolla-ansible/kolla_keystone_user.py @@ -0,0 +1 @@ +../../../common/kolla-ansible/kolla_keystone_user.py \ No newline at end of file diff --git a/docker/common/kolla-ansible/kolla_keystone_service.py b/docker/common/kolla-ansible/kolla_keystone_service.py new file mode 100644 index 000000000..455aaf578 --- /dev/null +++ b/docker/common/kolla-ansible/kolla_keystone_service.py @@ -0,0 +1,84 @@ +#!/usr/bin/python + +# Copyright 2015 Sam Yaple +# +# 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. + +# This file is a barebones file needed to file a gap until Ansible 2.0. No error +# checking, no deletions, no updates. Idempotent creation only. + +# If you look closely, you will see we arent _really_ using the shade module +# we just use it to slightly abstract the authentication model. As patches land +# in upstream shade we will be able to use more of the shade module. Until then +# if we want to be 'stable' we really need to be using it as a passthrough + +import shade + +def main(): + module = AnsibleModule( + argument_spec = openstack_full_argument_spec( + description = dict(required=True, type='str'), + service_name = dict(required=True, type='str'), + service_type = dict(required=True, type='str'), + admin_url = dict(required=True, type='str'), + internal_url = dict(required=True, type='str'), + public_url = dict(required=True, type='str'), + endpoint_region = dict(required=True, type='str') + ) + ) + + try: + description = module.params.pop('description') + service_name = module.params.pop('service_name') + service_type = module.params.pop('service_type') + admin_url = module.params.pop('admin_url') + internal_url = module.params.pop('internal_url') + public_url = module.params.pop('public_url') + endpoint_region = module.params.pop('endpoint_region') + + changed = False + service = None + endpoint = None + + cloud = shade.operator_cloud(**module.params) + + for _service in cloud.keystone_client.services.list(): + if _service.type == service_type: + service = _service + + if service is not None: + for _endpoint in cloud.keystone_client.endpoints.list(): + if _endpoint.service_id == service.id: + endpoint = _endpoint + else: + service = cloud.keystone_client.services.create(name=service_name, + service_type=service_type, + description=description) + + if endpoint is None: + changed = True + cloud.keystone_client.endpoints.create(service_id=service.id, + adminurl=admin_url, + internalurl=public_url, + publicurl=public_url, + region=endpoint_region) + + module.exit_json(changed=changed) + except Exception as e: + module.exit_json(failed=True, changed=True, msg=e) + +# import module snippets +from ansible.module_utils.basic import * +from ansible.module_utils.openstack import * +if __name__ == '__main__': + main() diff --git a/docker/common/kolla-ansible/kolla_keystone_user.py b/docker/common/kolla-ansible/kolla_keystone_user.py new file mode 100644 index 000000000..5d295c1e2 --- /dev/null +++ b/docker/common/kolla-ansible/kolla_keystone_user.py @@ -0,0 +1,83 @@ +#!/usr/bin/python + +# Copyright 2015 Sam Yaple +# +# 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. + +# This file is a barebones file needed to file a gap until Ansible 2.0. No error +# checking, no deletions, no updates. Idempotent creation only. + +# If you look closely, you will see we arent _really_ using the shade module +# we just use it to slightly abstract the authentication model. As patches land +# in upstream shade we will be able to use more of the shade module. Until then +# if we want to be 'stable' we really need to be using it as a passthrough + +import shade + +def main(): + module = AnsibleModule( + argument_spec = openstack_full_argument_spec( + password = dict(required=True, type='str'), + project = dict(required=True, type='str'), + role = dict(required=True, type='str'), + user = dict(required=True, type='str') + ) + ) + + try: + password = module.params.pop('password') + project_name = module.params.pop('project') + role_name = module.params.pop('role') + user_name = module.params.pop('user') + + changed = False + project = None + role = None + user = None + + cloud = shade.operator_cloud(**module.params) + + for _project in cloud.keystone_client.tenants.list(): + if _project.name == project_name: + project = _project + + for _role in cloud.keystone_client.roles.list(): + if _role.name == role_name: + role = _role + + for _user in cloud.keystone_client.users.list(): + if _user.name == user_name: + user = _user + + if not project: + changed = True + project = cloud.keystone_client.tenants.create(tenant_name=project_name) + + if not role: + changed = True + role = cloud.keystone_client.roles.create(name=role_name) + + if not user: + changed = True + user = cloud.keystone_client.users.create(name=user_name, password=password, tenant_id=project.id) + cloud.keystone_client.roles.add_user_role(role=role.id, user=user.id, tenant=project.id) + + module.exit_json(changed=changed) + except Exception as e: + module.exit_json(failed=True, changed=True, msg=e) + +# import module snippets +from ansible.module_utils.basic import * +from ansible.module_utils.openstack import * +if __name__ == '__main__': + main() diff --git a/docker_templates/kolla-ansible/Dockerfile.j2 b/docker_templates/kolla-ansible/Dockerfile.j2 new file mode 100644 index 000000000..5fa1e5aec --- /dev/null +++ b/docker_templates/kolla-ansible/Dockerfile.j2 @@ -0,0 +1,36 @@ +FROM {{ namespace }}/{{ base_distro }}-{{ install_type }}-base:{{ tag }} +MAINTAINER Kolla Project (https://launchpad.net/kolla) + +{% if base_distro in ['fedora', 'centos', 'oraclelinux'] %} + +RUN yum -y install \ + git \ + gcc \ + libffi-devel \ + libxml2-devel \ + libxslt-devel \ + MySQL-python \ + openssl-devel \ + python-devel \ + openssh-clients \ + && yum clean all + +{% elif base_distro in ['ubuntu', 'debian'] %} + +RUN echo '{{ install_type }} not yet available for {{ base_distro }}' \ + && /bin/false + +{% endif %} + +RUN pip install -U pip wheel \ + && pip install python-openstackclient shade + +RUN git clone https://github.com/ansible/ansible.git \ + && cd ansible \ + && git submodule update --init --recursive \ + && pip install . + +RUN mkdir -p /etc/ansible /usr/share/ansible \ + && echo 'localhost ansible_connection=local' > /etc/ansible/hosts + +COPY kolla_keystone_service.py kolla_keystone_user.py /usr/share/ansible/ diff --git a/docker_templates/kolla-ansible/kolla_keystone_service.py b/docker_templates/kolla-ansible/kolla_keystone_service.py new file mode 120000 index 000000000..5e5632f17 --- /dev/null +++ b/docker_templates/kolla-ansible/kolla_keystone_service.py @@ -0,0 +1 @@ +../../docker/common/kolla-ansible/kolla_keystone_service.py \ No newline at end of file diff --git a/docker_templates/kolla-ansible/kolla_keystone_user.py b/docker_templates/kolla-ansible/kolla_keystone_user.py new file mode 120000 index 000000000..4d88dd8d5 --- /dev/null +++ b/docker_templates/kolla-ansible/kolla_keystone_user.py @@ -0,0 +1 @@ +../../docker/common/kolla-ansible/kolla_keystone_user.py \ No newline at end of file diff --git a/tox.ini b/tox.ini index eea486626..f6468cd6b 100644 --- a/tox.ini +++ b/tox.ini @@ -78,4 +78,4 @@ commands = [flake8] show-source = True -exclude=.git,.tox,doc,ansible/library,docker/centos/binary/kolla-ansible +exclude=.git,.tox,doc,ansible/library,docker/centos/binary/kolla-ansible,docker_templates/kolla-ansible,docker/common/kolla-ansible -- GitLab