Switch to service-control

This commit is contained in:
Liam Young 2016-08-31 10:42:05 +00:00
parent bfd4279546
commit f3ae147a7d
5 changed files with 86 additions and 30 deletions

34
README.md Normal file
View 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).

View File

@ -2,8 +2,20 @@ Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0
Files: *
Copyright: 2015, Canonical Ltd.
License: GPL-3
License: Apache-2.0
License: GPL-3
On Debian GNU/Linux system you can find the complete text of the
GPL-3 license in '/usr/share/common-licenses/GPL-3'
License: Apache-2.0
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.
.
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'.

View File

@ -1,3 +1,3 @@
name: neutron-control
summary: Interface for requesting restarts of neutron services
name: service-control
summary: Interface for requesting restarts of services
maintainer: OpenStack Charmers <openstack-dev@lists.openstack.org>

View File

@ -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
View 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)