Ch sync
This commit is contained in:
parent
a59483020c
commit
75fee1c238
@ -1,4 +1,4 @@
|
||||
branch: lp:charm-helpers
|
||||
branch: lp:~gnuoy/charm-helpers/cepg-broker
|
||||
destination: hooks/charmhelpers
|
||||
include:
|
||||
- core
|
||||
|
@ -36,6 +36,7 @@ from subprocess import (
|
||||
CalledProcessError,
|
||||
)
|
||||
from charmhelpers.core.hookenv import (
|
||||
local_unit,
|
||||
relation_get,
|
||||
relation_ids,
|
||||
related_units,
|
||||
@ -414,7 +415,7 @@ class CephBrokerRq(object):
|
||||
"""
|
||||
def __init__(self, api_version=1):
|
||||
self.api_version = api_version
|
||||
self.rq_id = str(uuid.uuid1())
|
||||
self.request_id = str(uuid.uuid1())
|
||||
self.ops = []
|
||||
|
||||
def add_op_create_pool(self, name, replica_count=3):
|
||||
@ -424,7 +425,7 @@ class CephBrokerRq(object):
|
||||
@property
|
||||
def request(self):
|
||||
return json.dumps({'api-version': self.api_version, 'ops': self.ops,
|
||||
'request-id': self.rq_id})
|
||||
'request-id': self.request_id})
|
||||
|
||||
|
||||
class CephBrokerRsp(object):
|
||||
@ -434,12 +435,16 @@ class CephBrokerRsp(object):
|
||||
|
||||
The API is versioned and defaults to version 1.
|
||||
"""
|
||||
VALID = 0
|
||||
ABSENT = 1
|
||||
INVALID = 2
|
||||
|
||||
def __init__(self, encoded_rsp):
|
||||
self.api_version = None
|
||||
self.rsp = json.loads(encoded_rsp)
|
||||
|
||||
@property
|
||||
def req_id(self):
|
||||
def request_id(self):
|
||||
return self.rsp.get('request-id')
|
||||
|
||||
@property
|
||||
@ -449,3 +454,19 @@ class CephBrokerRsp(object):
|
||||
@property
|
||||
def exit_msg(self):
|
||||
return self.rsp.get('stderr')
|
||||
|
||||
def validate_request_id(self):
|
||||
pending_request_id = None
|
||||
pending_request_raw = relation_get(attribute='broker_req',
|
||||
unit=local_unit())
|
||||
if pending_request_raw:
|
||||
pending_request = json.loads(pending_request_raw)
|
||||
pending_request_id = pending_request.get('request-id')
|
||||
if not self.request_id:
|
||||
# back compat
|
||||
return self.ABSENT
|
||||
|
||||
if pending_request_id and self.request_id != pending_request_id:
|
||||
return self.INVALID
|
||||
|
||||
return self.VALID
|
||||
|
Loading…
Reference in New Issue
Block a user