Switch to service-control
This commit is contained in:
parent
bfd4279546
commit
f3ae147a7d
34
README.md
Normal file
34
README.md
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# Overview
|
||||||
|
|
||||||
|
This interface is used for a charm to request a restart of a service managed by
|
||||||
|
another charm.
|
||||||
|
|
||||||
|
# Usage
|
||||||
|
|
||||||
|
The interface provides the `service-control.connected` state.
|
||||||
|
|
||||||
|
# metadata
|
||||||
|
|
||||||
|
To consume this interface in your charm or layer, add the following to
|
||||||
|
`layer.yaml`:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
includes: ['interface:service-control']
|
||||||
|
```
|
||||||
|
|
||||||
|
and add a provides interface of type `service-control` to your charm or layers
|
||||||
|
`metadata.yaml` eg:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
requires:
|
||||||
|
neutron-control:
|
||||||
|
interface: service-control
|
||||||
|
```
|
||||||
|
|
||||||
|
# Bugs
|
||||||
|
|
||||||
|
Please report bugs on
|
||||||
|
[Launchpad](https://bugs.launchpad.net/openstack-charms/+filebug).
|
||||||
|
|
||||||
|
For development questions please refer to the OpenStack [Charm
|
||||||
|
Guide](https://github.com/openstack/charm-guide).
|
20
copyright
20
copyright
@ -2,8 +2,20 @@ Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0
|
|||||||
|
|
||||||
Files: *
|
Files: *
|
||||||
Copyright: 2015, Canonical Ltd.
|
Copyright: 2015, Canonical Ltd.
|
||||||
License: GPL-3
|
License: Apache-2.0
|
||||||
|
|
||||||
License: GPL-3
|
License: Apache-2.0
|
||||||
On Debian GNU/Linux system you can find the complete text of the
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
GPL-3 license in '/usr/share/common-licenses/GPL-3'
|
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.
|
||||||
|
.
|
||||||
|
On Debian-based systems the full text of the Apache version 2.0 license
|
||||||
|
can be found in `/usr/share/common-licenses/Apache-2.0'.
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
name: neutron-control
|
name: service-control
|
||||||
summary: Interface for requesting restarts of neutron services
|
summary: Interface for requesting restarts of services
|
||||||
maintainer: OpenStack Charmers <openstack-dev@lists.openstack.org>
|
maintainer: OpenStack Charmers <openstack-dev@lists.openstack.org>
|
||||||
|
24
provides.py
24
provides.py
@ -1,24 +0,0 @@
|
|||||||
import uuid
|
|
||||||
|
|
||||||
from charms.reactive import hook
|
|
||||||
from charms.reactive import RelationBase
|
|
||||||
from charms.reactive import scopes
|
|
||||||
|
|
||||||
|
|
||||||
class NeutronControlProvides(RelationBase):
|
|
||||||
scope = scopes.GLOBAL
|
|
||||||
|
|
||||||
@hook('{provides:neutron-control}-relation-{joined,changed}')
|
|
||||||
def changed(self):
|
|
||||||
self.set_state('{relation_name}.connected')
|
|
||||||
|
|
||||||
@hook('{provides:neutron-control}-relation-{broken,departed}')
|
|
||||||
def broken(self):
|
|
||||||
self.remove_state('{relation_name}.connected')
|
|
||||||
|
|
||||||
def request_restart(self):
|
|
||||||
conversation = self.conversation()
|
|
||||||
relation_info = {
|
|
||||||
'restart-trigger': str(uuid.uuid4()),
|
|
||||||
}
|
|
||||||
conversation.set_remote(**relation_info)
|
|
34
requires.py
Normal file
34
requires.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
from charms.reactive import hook
|
||||||
|
from charms.reactive import RelationBase
|
||||||
|
from charms.reactive import scopes
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceControlRequires(RelationBase):
|
||||||
|
scope = scopes.GLOBAL
|
||||||
|
|
||||||
|
@hook('{requires:service-control}-relation-{joined,changed}')
|
||||||
|
def changed(self):
|
||||||
|
self.set_state('{relation_name}.connected')
|
||||||
|
|
||||||
|
@hook('{requires:service-control}-relation-{broken,departed}')
|
||||||
|
def broken(self):
|
||||||
|
self.remove_state('{relation_name}.connected')
|
||||||
|
|
||||||
|
def request_restart(self, service_type=None):
|
||||||
|
"""Request a restart of a set of remote services
|
||||||
|
|
||||||
|
:param service_type: string Service types to be restarted eg 'neutron'.
|
||||||
|
If ommitted a request to restart all
|
||||||
|
services is sent
|
||||||
|
"""
|
||||||
|
conversation = self.conversation()
|
||||||
|
if service_type:
|
||||||
|
key = 'restart-trigger-{}'.format(service_type)
|
||||||
|
else:
|
||||||
|
key = 'restart-trigger'
|
||||||
|
relation_info = {
|
||||||
|
key: str(uuid.uuid4()),
|
||||||
|
}
|
||||||
|
conversation.set_remote(**relation_info)
|
Loading…
Reference in New Issue
Block a user