From f005c10d4fcf952a08584a6d285e7417a6bbf253 Mon Sep 17 00:00:00 2001 From: Russell Haering Date: Fri, 20 Dec 2013 12:57:38 -0800 Subject: [PATCH] split agent out into standby and decom classes --- setup.cfg | 3 ++- teeth_agent/{agent.py => base.py} | 23 +++++++++++------------ teeth_agent/cmd/{agent.py => decom.py} | 4 ++-- teeth_agent/cmd/standby.py | 21 +++++++++++++++++++++ teeth_agent/decom.py | 22 ++++++++++++++++++++++ teeth_agent/standby.py | 22 ++++++++++++++++++++++ 6 files changed, 80 insertions(+), 15 deletions(-) rename teeth_agent/{agent.py => base.py} (84%) rename teeth_agent/cmd/{agent.py => decom.py} (87%) create mode 100644 teeth_agent/cmd/standby.py create mode 100644 teeth_agent/decom.py create mode 100644 teeth_agent/standby.py diff --git a/setup.cfg b/setup.cfg index c26063b64..869d5d767 100644 --- a/setup.cfg +++ b/setup.cfg @@ -16,4 +16,5 @@ packages = [entry_points] 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 diff --git a/teeth_agent/agent.py b/teeth_agent/base.py similarity index 84% rename from teeth_agent/agent.py rename to teeth_agent/base.py index 4fd460d27..906cfee04 100644 --- a/teeth_agent/agent.py +++ b/teeth_agent/base.py @@ -24,16 +24,6 @@ from werkzeug import serving 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): def __init__(self, mode, started_at, version): 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): - TeethAgentOperationModes.validate_mode(mode) self.listen_host = listen_host self.listen_port = listen_port self.started_at = None @@ -77,3 +66,13 @@ class TeethAgent(object): self.started_at = time.time() 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') diff --git a/teeth_agent/cmd/agent.py b/teeth_agent/cmd/decom.py similarity index 87% rename from teeth_agent/cmd/agent.py rename to teeth_agent/cmd/decom.py index 630e7b61f..2bb19a4bf 100644 --- a/teeth_agent/cmd/agent.py +++ b/teeth_agent/cmd/decom.py @@ -14,8 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. """ -from teeth_agent import agent +from teeth_agent import decom def run(): - agent.TeethAgent('0.0.0.0', 9999, 'STANDBY').run() + decom.DecomAgent('0.0.0.0', 9999).run() diff --git a/teeth_agent/cmd/standby.py b/teeth_agent/cmd/standby.py new file mode 100644 index 000000000..db6c028c9 --- /dev/null +++ b/teeth_agent/cmd/standby.py @@ -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() diff --git a/teeth_agent/decom.py b/teeth_agent/decom.py new file mode 100644 index 000000000..d2e578e4b --- /dev/null +++ b/teeth_agent/decom.py @@ -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') diff --git a/teeth_agent/standby.py b/teeth_agent/standby.py new file mode 100644 index 000000000..70539fb02 --- /dev/null +++ b/teeth_agent/standby.py @@ -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')