├── actions └── .gitkeep ├── .gitignore ├── test-requirements.txt ├── .zuul.yaml ├── requirements.txt ├── .gitreview ├── layer.yaml ├── metadata.yaml ├── README.md ├── tox.ini ├── reactive └── layer_openstack_api.py ├── config.yaml └── LICENSE /actions/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .tox 2 | build 3 | -------------------------------------------------------------------------------- /test-requirements.txt: -------------------------------------------------------------------------------- 1 | flake8>=2.2.4 2 | os-testr>=0.4.1 3 | -------------------------------------------------------------------------------- /.zuul.yaml: -------------------------------------------------------------------------------- 1 | - project: 2 | templates: 3 | - python-charm-layer-jobs 4 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # Requirements to build the layer 2 | charm-tools==2.8.3 3 | simplejson 4 | -------------------------------------------------------------------------------- /.gitreview: -------------------------------------------------------------------------------- 1 | [gerrit] 2 | host=review.opendev.org 3 | port=29418 4 | project=openstack/charm-layer-openstack-api.git 5 | -------------------------------------------------------------------------------- /layer.yaml: -------------------------------------------------------------------------------- 1 | includes: ['layer:openstack-principle', 'interface:mysql-shared', 2 | 'interface:rabbitmq', 'interface:keystone', 3 | 'interface:hacluster', 'interface:openstack-ha'] 4 | exclude: ['.gitignore', '.gitreview', '.zuul.yaml', 'README.md', 5 | 'requirements.txt', 'test-requirements.txt'] 6 | repo: 'https://github.com/openstack/charm-layer-openstack-api' 7 | -------------------------------------------------------------------------------- /metadata.yaml: -------------------------------------------------------------------------------- 1 | name: openstack-api 2 | summary: Reative Layer - OpenStack API charms 3 | maintainer: OpenStack Charmers 4 | description: Layer for all OpenStack charms providing API services 5 | tags: 6 | - openstack 7 | series: [] 8 | subordinate: false 9 | extra-bindings: 10 | public: 11 | admin: 12 | internal: 13 | requires: 14 | shared-db: 15 | interface: mysql-shared 16 | amqp: 17 | interface: rabbitmq 18 | identity-service: 19 | interface: keystone 20 | ha: 21 | interface: hacluster 22 | scope: container 23 | peers: 24 | cluster: 25 | interface: openstack-ha 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | This layer provides the base layer for OpenStack charms that are will deploy 4 | API services, and provides all of the core functionality for: 5 | 6 | - HA (using the hacluster charm) 7 | - Juju 2.0 network space support for API endpoints 8 | - Configuration based network binding of API endpoints 9 | 10 | To use this layer, including the following in the layer.yaml of your charm: 11 | 12 | include: ['layer:openstack-api'] 13 | 14 | And then read the [new API charm](https://github.com/openstack/charm-guide/blob/master/doc/source/new-charm.rst) 15 | guide for details on how to use this layer in-conjuction with the 16 | charms.openstack Python module to quickly and easily put together a 17 | new API charm. 18 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | skipsdist = True 3 | envlist = pep8 4 | toxworkdir = /tmp/tox 5 | # NOTE(beisner): Avoid build/test env pollution by not enabling sitepackages. 6 | sitepackages = False 7 | # NOTE(beisner): Avoid false positives by not skipping missing interpreters. 8 | skip_missing_interpreters = False 9 | 10 | [testenv] 11 | setenv = VIRTUAL_ENV={envdir} 12 | PYTHONHASHSEED=0 13 | TERM=linux 14 | JUJU_REPOSITORY={envdir}/tmp/build 15 | passenv = http_proxy https_proxy 16 | install_command = 17 | pip install {opts} {packages} 18 | deps = 19 | -r{toxinidir}/requirements.txt 20 | whitelist_externals = /bin/true /bin/echo /bin/mkdir /bin/ln 21 | 22 | [testenv:build] 23 | # ``charm build`` refuses to output to a subdirectory to the source tree 24 | # The gate check will look for and validate the built artifacts in the source 25 | # tree. 26 | # Build the artifats under /tmp and link back to source directory to alleviate. 27 | basepython = python3 28 | commands = 29 | /bin/echo 'WARNING: *build* target is for testing only.' 30 | /bin/mkdir -p {envdir}/tmp 31 | charm-build --log-level DEBUG -o {envdir}/tmp/build/builds . 32 | /bin/ln -s {envdir}/tmp/build/builds {envdir}/tmp/build/trusty 33 | /bin/ln -s {envdir}/tmp/build {toxinidir}/build 34 | 35 | [testenv:venv] 36 | basepython = python3 37 | commands = {posargs} 38 | 39 | [testenv:py34] 40 | basepython = python3.4 41 | deps = -r{toxinidir}/test-requirements.txt 42 | # TODO: Need to write unit tests then remove the following command. 43 | commands = /bin/true 44 | 45 | [testenv:py35] 46 | basepython = python3.5 47 | deps = -r{toxinidir}/test-requirements.txt 48 | # TODO: Need to write unit tests then remove the following command. 49 | commands = /bin/true 50 | 51 | [testenv:py36] 52 | basepython = python3.6 53 | deps = -r{toxinidir}/test-requirements.txt 54 | # TODO: Need to write unit tests then remove the following command. 55 | commands = /bin/true 56 | 57 | [testenv:py37] 58 | basepython = python3.7 59 | deps = -r{toxinidir}/test-requirements.txt 60 | # TODO: Need to write unit tests then remove the following command. 61 | commands = /bin/true 62 | 63 | [testenv:pep8] 64 | basepython = python3 65 | deps = -r{toxinidir}/test-requirements.txt 66 | commands = flake8 --ignore=E402 actions/ reactive/ 67 | -------------------------------------------------------------------------------- /reactive/layer_openstack_api.py: -------------------------------------------------------------------------------- 1 | import charms.reactive as reactive 2 | 3 | import charms_openstack.charm as charm 4 | 5 | 6 | @reactive.when('amqp.connected', 7 | 'charms.openstack.do-default-amqp.connected') 8 | def default_amqp_connection(amqp): 9 | """Handle the default amqp connection. 10 | 11 | This requires that the charm implements get_amqp_credentials() to 12 | provide a tuple of the (user, vhost) for the amqp server 13 | """ 14 | with charm.provide_charm_instance() as instance: 15 | user, vhost = instance.get_amqp_credentials() 16 | amqp.request_access(username=user, vhost=vhost) 17 | instance.assess_status() 18 | 19 | 20 | @reactive.when('shared-db.connected', 21 | 'charms.openstack.do-default-shared-db.connected') 22 | def default_setup_database(database): 23 | """Handle the default database connection setup 24 | 25 | This requires that the charm implements get_database_setup() to provide 26 | a list of dictionaries; 27 | [{'database': ..., 'username': ..., 'hostname': ..., 'prefix': ...}] 28 | 29 | The prefix can be missing: it defaults to None. 30 | """ 31 | with charm.provide_charm_instance() as instance: 32 | for db in instance.get_database_setup(): 33 | database.configure(**db) 34 | instance.assess_status() 35 | 36 | 37 | @reactive.when('identity-service.connected', 38 | 'charms.openstack.do-default-identity-service.connected') 39 | def default_setup_endpoint_connection(keystone): 40 | """When the keystone interface connects, register this unit into the 41 | catalog. This is the default handler, and calls on the charm class to 42 | provide the endpoint information. If multiple endpoints are needed, 43 | then a custom endpoint handler will be needed. 44 | """ 45 | with charm.provide_charm_instance() as instance: 46 | keystone.register_endpoints(instance.service_type, 47 | instance.region, 48 | instance.public_url, 49 | instance.internal_url, 50 | instance.admin_url) 51 | instance.assess_status() 52 | 53 | 54 | @reactive.when('cluster.available') 55 | def default_update_peers(cluster): 56 | """Inform peers about this unit's API addresses. 57 | 58 | Set public-address, internal-address and admin-address on the 59 | (openstack-ha) peer relation. 60 | """ 61 | with charm.provide_charm_instance() as instance: 62 | # This function ONLY updates the peers if the data has changed. Thus 63 | # it's okay to call it on every hook invocation. 64 | instance.update_peers(cluster) 65 | -------------------------------------------------------------------------------- /config.yaml: -------------------------------------------------------------------------------- 1 | options: 2 | os-admin-network: 3 | type: string 4 | default: 5 | description: | 6 | The IP address and netmask of the OpenStack Admin network (e.g., 7 | 192.168.0.0/24) 8 | . 9 | This network will be used for admin endpoints. 10 | os-internal-network: 11 | type: string 12 | default: 13 | description: | 14 | The IP address and netmask of the OpenStack Internal network (e.g., 15 | 192.168.0.0/24) 16 | . 17 | This network will be used for internal endpoints. 18 | os-public-network: 19 | type: string 20 | default: 21 | description: | 22 | The IP address and netmask of the OpenStack Public network (e.g., 23 | 192.168.0.0/24) 24 | . 25 | This network will be used for public endpoints. 26 | os-public-hostname: 27 | type: string 28 | default: 29 | description: | 30 | The hostname or address of the public endpoints created in the keystone 31 | identity provider. 32 | . 33 | This value will be used for public endpoints. For example, an 34 | os-public-hostname set to 'api-public.example.com' with ssl enabled 35 | will create the following endpoint for neutron-api: 36 | . 37 | https://api-public.example.com:9696/ 38 | os-internal-hostname: 39 | type: string 40 | default: 41 | description: | 42 | The hostname or address of the internal endpoints created in the keystone 43 | identity provider. 44 | . 45 | This value will be used for internal endpoints. For example, an 46 | os-internal-hostname set to 'api-internal.example.com' with ssl enabled 47 | will create the following endpoint for neutron-api: 48 | . 49 | https://api-internal.example.com:9696/ 50 | os-admin-hostname: 51 | type: string 52 | default: 53 | description: | 54 | The hostname or address of the admin endpoints created in the keystone 55 | identity provider. 56 | . 57 | This value will be used for admin endpoints. For example, an 58 | os-admin-hostname set to 'api-admin.example.com' with ssl enabled 59 | will create the following endpoint for neutron-api: 60 | . 61 | https://api-admin.example.com:9696/ 62 | region: 63 | default: RegionOne 64 | type: string 65 | description: OpenStack Region 66 | worker-multiplier: 67 | type: float 68 | default: 69 | description: | 70 | The CPU core multiplier to use when configuring worker processes. By 71 | default, the number of workers for each daemon is set to twice the number 72 | of CPU cores a service unit has. This default value will be capped 73 | to 4 workers unless this configuration option is set. 74 | haproxy-server-timeout: 75 | type: int 76 | default: 77 | description: | 78 | Server timeout configuration in ms for haproxy, used in HA 79 | configurations. If not provided, default value of 90000ms is used. 80 | haproxy-client-timeout: 81 | type: int 82 | default: 83 | description: | 84 | Client timeout configuration in ms for haproxy, used in HA 85 | configurations. If not provided, default value of 90000ms is used. 86 | haproxy-queue-timeout: 87 | type: int 88 | default: 89 | description: | 90 | Queue timeout configuration in ms for haproxy, used in HA 91 | configurations. If not provided, default value of 9000ms is used. 92 | haproxy-connect-timeout: 93 | type: int 94 | default: 95 | description: | 96 | Connect timeout configuration in ms for haproxy, used in HA 97 | configurations. If not provided, default value of 9000ms is used. 98 | dns-ha: 99 | type: boolean 100 | default: False 101 | description: | 102 | Use DNS HA with MAAS 2.0. Note if this is set do not set vip settings 103 | below. 104 | vip: 105 | type: string 106 | default: 107 | description: | 108 | Virtual IP(s) to use to front API services in HA configuration. 109 | 110 | If multiple networks are being used, a VIP should be provided for each 111 | network, separated by spaces. 112 | vip_iface: 113 | type: string 114 | default: eth0 115 | description: | 116 | Default network interface to use for HA vip when it cannot be 117 | automatically determined. 118 | vip_cidr: 119 | type: int 120 | default: 24 121 | description: | 122 | Default CIDR netmask to use for HA vip when it cannot be automatically 123 | determined. 124 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------