split agent out into standby and decom classes
This commit is contained in:
parent
98b56fe53c
commit
f005c10d4f
|
@ -16,4 +16,5 @@ packages =
|
||||||
|
|
||||||
[entry_points]
|
[entry_points]
|
||||||
console_scripts =
|
console_scripts =
|
||||||
teeth-agent = teeth_agent.cmd.agent:run
|
teeth-standby-agent = teeth_agent.cmd.standby:run
|
||||||
|
teeth-decom-agent = teeth_agent.cmd.decom:run
|
||||||
|
|
|
@ -24,16 +24,6 @@ from werkzeug import serving
|
||||||
from teeth_agent import api
|
from teeth_agent import api
|
||||||
|
|
||||||
|
|
||||||
class TeethAgentOperationModes(object):
|
|
||||||
DECOM = 'DECOM'
|
|
||||||
STANDBY = 'STANDBY'
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def validate_mode(cls, mode):
|
|
||||||
if not hasattr(cls, mode) or getattr(cls, mode) != mode:
|
|
||||||
raise RuntimeError('Invalid mode: {}'.format(mode))
|
|
||||||
|
|
||||||
|
|
||||||
class TeethAgentStatus(encoding.Serializable):
|
class TeethAgentStatus(encoding.Serializable):
|
||||||
def __init__(self, mode, started_at, version):
|
def __init__(self, mode, started_at, version):
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
@ -49,9 +39,8 @@ class TeethAgentStatus(encoding.Serializable):
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
class TeethAgent(object):
|
class BaseTeethAgent(object):
|
||||||
def __init__(self, listen_host, listen_port, mode):
|
def __init__(self, listen_host, listen_port, mode):
|
||||||
TeethAgentOperationModes.validate_mode(mode)
|
|
||||||
self.listen_host = listen_host
|
self.listen_host = listen_host
|
||||||
self.listen_port = listen_port
|
self.listen_port = listen_port
|
||||||
self.started_at = None
|
self.started_at = None
|
||||||
|
@ -77,3 +66,13 @@ class TeethAgent(object):
|
||||||
|
|
||||||
self.started_at = time.time()
|
self.started_at = time.time()
|
||||||
serving.run_simple(self.listen_host, self.listen_port, self.api)
|
serving.run_simple(self.listen_host, self.listen_port, self.api)
|
||||||
|
|
||||||
|
|
||||||
|
class StandbyAgent(BaseTeethAgent):
|
||||||
|
def __init__(self, listen_host, listen_port):
|
||||||
|
super(StandbyAgent, self).__init__(listen_host, listen_port, 'STANDBY')
|
||||||
|
|
||||||
|
|
||||||
|
class DecomAgent(BaseTeethAgent):
|
||||||
|
def __init__(self, listen_host, listen_port):
|
||||||
|
super(StandbyAgent, self).__init__(listen_host, listen_port, 'DECOM')
|
|
@ -14,8 +14,8 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from teeth_agent import agent
|
from teeth_agent import decom
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
agent.TeethAgent('0.0.0.0', 9999, 'STANDBY').run()
|
decom.DecomAgent('0.0.0.0', 9999).run()
|
|
@ -0,0 +1,21 @@
|
||||||
|
"""
|
||||||
|
Copyright 2013 Rackspace, Inc.
|
||||||
|
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from teeth_agent import standby
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
standby.StandbyAgent('0.0.0.0', 9999).run()
|
|
@ -0,0 +1,22 @@
|
||||||
|
"""
|
||||||
|
Copyright 2013 Rackspace, Inc.
|
||||||
|
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from teeth_agent import base
|
||||||
|
|
||||||
|
|
||||||
|
class DecomAgent(base.BaseTeethAgent):
|
||||||
|
def __init__(self, listen_host, listen_port):
|
||||||
|
super(DecomAgent, self).__init__(listen_host, listen_port, 'DECOM')
|
|
@ -0,0 +1,22 @@
|
||||||
|
"""
|
||||||
|
Copyright 2013 Rackspace, Inc.
|
||||||
|
|
||||||
|
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.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from teeth_agent import base
|
||||||
|
|
||||||
|
|
||||||
|
class StandbyAgent(base.BaseTeethAgent):
|
||||||
|
def __init__(self, listen_host, listen_port):
|
||||||
|
super(StandbyAgent, self).__init__(listen_host, listen_port, 'STANDBY')
|
Loading…
Reference in New Issue