summaryrefslogtreecommitdiff
path: root/ironic_python_agent
diff options
context:
space:
mode:
authorRussell Haering <russellhaering@gmail.com>2014-05-28 23:11:47 -0700
committerRussell Haering <russellhaering@gmail.com>2014-05-28 23:11:47 -0700
commitf69dd99a79ac7848b24f2034a98ff6fdcdc037cd (patch)
tree421e3fcec9a47e40e72c1c97fee5b1c5c8d75ae2 /ironic_python_agent
parent59d6523a3554897b4d327f9b0ec22d4af180bc48 (diff)
downloadironic-python-agent-f69dd99a79ac7848b24f2034a98ff6fdcdc037cd.tar.gz
Switch to oslo.config for CLI parsing
Use oslo.config instead of argparse for CLI parsing. As a side effect, a bunch of logging arguments including --debug become available with this change. Change-Id: Ia8c4e91448f2a8cb15eb570125ac9c236e13274c
Diffstat (limited to 'ironic_python_agent')
-rw-r--r--ironic_python_agent/cmd/agent.py132
1 files changed, 59 insertions, 73 deletions
diff --git a/ironic_python_agent/cmd/agent.py b/ironic_python_agent/cmd/agent.py
index 770d6f17..553a9ef3 100644
--- a/ironic_python_agent/cmd/agent.py
+++ b/ironic_python_agent/cmd/agent.py
@@ -12,23 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import argparse
+from oslo.config import cfg
from ironic_python_agent import agent
from ironic_python_agent.openstack.common import log
-
-log.setup('ironic-python-agent')
-LOG = log.getLogger(__name__)
+CONF = cfg.CONF
def _get_kernel_params():
- try:
- with open('/proc/cmdline') as f:
- cmdline = f.read()
- except Exception as e:
- LOG.exception('Could not read /proc/cmdline: {e}'.format(e=e))
- return {}
+ with open('/proc/cmdline') as f:
+ cmdline = f.read()
options = cmdline.split()
params = {}
@@ -40,68 +34,60 @@ def _get_kernel_params():
return params
+KPARAMS = _get_kernel_params()
+
+cli_opts = [
+ cfg.StrOpt('api-url',
+ required=('ipa-api-url' not in KPARAMS),
+ default=KPARAMS.get('ipa-api-url'),
+ help='URL of the Ironic API'),
+
+ cfg.StrOpt('listen-host',
+ default=KPARAMS.get('ipa-listen-host', '0.0.0.0'),
+ help='The IP address to listen on.'),
+
+ cfg.IntOpt('listen-port',
+ default=int(KPARAMS.get('ipa-listen-port', 9999)),
+ help='The port to listen on'),
+
+ cfg.StrOpt('advertise-host',
+ default=KPARAMS.get('ipa-advertise-host', '0.0.0.0'),
+ help='The host to tell Ironic to reply and send '
+ 'commands to.'),
+
+ cfg.IntOpt('advertise-port',
+ default=int(KPARAMS.get('ipa-advertise-port', 9999)),
+ help='The port to tell Ironic to reply and send '
+ 'commands to.'),
+
+ cfg.IntOpt('lookup-timeout',
+ default=int(KPARAMS.get('ipa-lookup-timeout', 300)),
+ help='The amount of time to retry the initial lookup '
+ 'call to Ironic. After the timeout, the agent '
+ 'will exit with a non-zero exit code.'),
+
+ cfg.IntOpt('lookup-interval',
+ default=int(KPARAMS.get('ipa-lookup-timeout', 1)),
+ help='The initial interval for retries on the initial '
+ 'lookup call to Ironic. The interval will be '
+ 'doubled after each failure until timeout is '
+ 'exceeded.'),
+
+ cfg.StrOpt('driver-name',
+ default=KPARAMS.get('ipa-driver-name', 'agent_ipmitool'),
+ help='The Ironic driver in use for this node')
+]
+
+CONF.register_cli_opts(cli_opts)
+
def run():
- kparams = _get_kernel_params()
-
- parser = argparse.ArgumentParser(
- description=('An agent that handles decomissioning and provisioning'
- ' on behalf of Ironic.'))
-
- api_url = kparams.get('ipa-api-url')
- if api_url is None:
- parser.add_argument('--api-url',
- required=True,
- help='URL of the Ironic API')
-
- parser.add_argument('--listen-host',
- default=kparams.get('ipa-listen-host', '0.0.0.0'),
- type=str,
- help='The IP address to listen on.')
-
- parser.add_argument('--listen-port',
- default=int(kparams.get('ipa-listen-port', 9999)),
- type=int,
- help='The port to listen on')
-
- parser.add_argument('--advertise-host',
- default=kparams.get('ipa-advertise-host', '0.0.0.0'),
- type=str,
- help='The host to tell Ironic to reply and send '
- 'commands to.')
-
- parser.add_argument('--advertise-port',
- default=int(kparams.get('ipa-advertise-port', 9999)),
- type=int,
- help='The port to tell Ironic to reply and send '
- 'commands to.')
-
- parser.add_argument('--lookup-timeout',
- default=int(kparams.get('ipa-lookup-timeout', 300)),
- type=int,
- help='The amount of time to retry the initial lookup '
- 'call to Ironic. After the timeout, the agent '
- 'will exit with a non-zero exit code.')
-
- parser.add_argument('--lookup-interval',
- default=int(kparams.get('ipa-lookup-timeout', 1)),
- type=int,
- help='The initial interval for retries on the initial '
- 'lookup call to Ironic. The interval will be '
- 'doubled after each failure until timeout is '
- 'exceeded.')
-
- parser.add_argument('--driver-name',
- default=kparams.get('ipa-driver-name',
- 'agent_ipmitool'),
- type=str,
- help='The Ironic driver in use for this node')
-
- args = parser.parse_args()
-
- agent.IronicPythonAgent(api_url or args.api_url,
- (args.advertise_host, args.advertise_port),
- (args.listen_host, args.listen_port),
- args.lookup_timeout,
- args.lookup_interval,
- args.driver_name).run()
+ CONF()
+ log.setup('ironic-python-agent')
+
+ agent.IronicPythonAgent(CONF.api_url,
+ (CONF.advertise_host, CONF.advertise_port),
+ (CONF.listen_host, CONF.listen_port),
+ CONF.lookup_timeout,
+ CONF.lookup_interval,
+ CONF.driver_name).run()