Merge lp:~jk0/nova/lp784693 into lp:~hudson-openstack/nova/trunk

Proposed by Josh Kearney
Status: Merged
Approved by: Sandy Walsh
Approved revision: 1085
Merged at revision: 1085
Proposed branch: lp:~jk0/nova/lp784693
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 211 lines (+187/-4)
2 files modified
nova/virt/xenapi_conn.py (+4/-4)
plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost (+183/-0)
To merge this branch: bzr merge lp:~jk0/nova/lp784693
Reviewer Review Type Date Requested Status
Sandy Walsh (community) Approve
Ed Leafe (community) Approve
Chris Behrens (community) Approve
Review via email: mp+61437@code.launchpad.net

Description of the change

Added missing xenhost plugin. This was causing warnings to pop up in the compute logs during periodic_task runs. It must have not been bzr add'd when this code was merged.

To post a comment you must log in.
Revision history for this message
Ed Leafe (ed-leafe) wrote :

Didn't comstud recently change the reference for 'self._session' to 'session' to avoid a concurrency problem? Check with him before changing it back.

Revision history for this message
Chris Behrens (cbehrens) wrote :

If someone did, it wasn't me.

Revision history for this message
Chris Behrens (cbehrens) wrote :

Oh, now I know what dabo is referring to. Yes, I did change XenAPI, but not this part of the code, as it was fine. It's possible this does break concurrent sessions/queries. Let me look again.

Revision history for this message
Chris Behrens (cbehrens) wrote :

Ok. It's fine. It's just setting ._session once during init(). That session is static throughout the life of XenAPIConnection, so there's no issue here..

review: Approve
Revision history for this message
Ed Leafe (ed-leafe) wrote :

lgtm

review: Approve
Revision history for this message
Sandy Walsh (sandy-walsh) wrote :

sorry, missed that file.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/virt/xenapi_conn.py'
2--- nova/virt/xenapi_conn.py 2011-05-13 16:45:42 +0000
3+++ nova/virt/xenapi_conn.py 2011-05-18 16:32:31 +0000
4@@ -169,15 +169,15 @@
5
6 def __init__(self, url, user, pw):
7 super(XenAPIConnection, self).__init__()
8- session = XenAPISession(url, user, pw)
9- self._vmops = VMOps(session)
10- self._volumeops = VolumeOps(session)
11+ self._session = XenAPISession(url, user, pw)
12+ self._vmops = VMOps(self._session)
13+ self._volumeops = VolumeOps(self._session)
14 self._host_state = None
15
16 @property
17 def HostState(self):
18 if not self._host_state:
19- self._host_state = HostState(self.session)
20+ self._host_state = HostState(self._session)
21 return self._host_state
22
23 def init_host(self, host):
24
25=== added file 'plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost'
26--- plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost 1970-01-01 00:00:00 +0000
27+++ plugins/xenserver/xenapi/etc/xapi.d/plugins/xenhost 2011-05-18 16:32:31 +0000
28@@ -0,0 +1,183 @@
29+#!/usr/bin/env python
30+
31+# Copyright 2011 OpenStack LLC.
32+# Copyright 2011 United States Government as represented by the
33+# Administrator of the National Aeronautics and Space Administration.
34+# All Rights Reserved.
35+#
36+# Licensed under the Apache License, Version 2.0 (the "License"); you may
37+# not use this file except in compliance with the License. You may obtain
38+# a copy of the License at
39+#
40+# http://www.apache.org/licenses/LICENSE-2.0
41+#
42+# Unless required by applicable law or agreed to in writing, software
43+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
44+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
45+# License for the specific language governing permissions and limitations
46+# under the License.
47+
48+#
49+# XenAPI plugin for reading/writing information to xenstore
50+#
51+
52+try:
53+ import json
54+except ImportError:
55+ import simplejson as json
56+import os
57+import random
58+import re
59+import subprocess
60+import tempfile
61+import time
62+
63+import XenAPIPlugin
64+
65+from pluginlib_nova import *
66+configure_logging("xenhost")
67+
68+host_data_pattern = re.compile(r"\s*(\S+) \([^\)]+\) *: ?(.*)")
69+
70+
71+def jsonify(fnc):
72+ def wrapper(*args, **kwargs):
73+ return json.dumps(fnc(*args, **kwargs))
74+ return wrapper
75+
76+
77+class TimeoutError(StandardError):
78+ pass
79+
80+
81+def _run_command(cmd):
82+ """Abstracts out the basics of issuing system commands. If the command
83+ returns anything in stderr, a PluginError is raised with that information.
84+ Otherwise, the output from stdout is returned.
85+ """
86+ pipe = subprocess.PIPE
87+ proc = subprocess.Popen([cmd], shell=True, stdin=pipe, stdout=pipe,
88+ stderr=pipe, close_fds=True)
89+ proc.wait()
90+ err = proc.stderr.read()
91+ if err:
92+ raise pluginlib.PluginError(err)
93+ return proc.stdout.read()
94+
95+
96+@jsonify
97+def host_data(self, arg_dict):
98+ """Runs the commands on the xenstore host to return the current status
99+ information.
100+ """
101+ cmd = "xe host-list | grep uuid"
102+ resp = _run_command(cmd)
103+ host_uuid = resp.split(":")[-1].strip()
104+ cmd = "xe host-param-list uuid=%s" % host_uuid
105+ resp = _run_command(cmd)
106+ parsed_data = parse_response(resp)
107+ # We have the raw dict of values. Extract those that we need,
108+ # and convert the data types as needed.
109+ ret_dict = cleanup(parsed_data)
110+ return ret_dict
111+
112+
113+def parse_response(resp):
114+ data = {}
115+ for ln in resp.splitlines():
116+ if not ln:
117+ continue
118+ mtch = host_data_pattern.match(ln.strip())
119+ try:
120+ k, v = mtch.groups()
121+ data[k] = v
122+ except AttributeError:
123+ # Not a valid line; skip it
124+ continue
125+ return data
126+
127+
128+def cleanup(dct):
129+ """Take the raw KV pairs returned and translate them into the
130+ appropriate types, discarding any we don't need.
131+ """
132+ def safe_int(val):
133+ """Integer values will either be string versions of numbers,
134+ or empty strings. Convert the latter to nulls.
135+ """
136+ try:
137+ return int(val)
138+ except ValueError:
139+ return None
140+
141+ def strip_kv(ln):
142+ return [val.strip() for val in ln.split(":", 1)]
143+
144+ out = {}
145+
146+# sbs = dct.get("supported-bootloaders", "")
147+# out["host_supported-bootloaders"] = sbs.split("; ")
148+# out["host_suspend-image-sr-uuid"] = dct.get("suspend-image-sr-uuid", "")
149+# out["host_crash-dump-sr-uuid"] = dct.get("crash-dump-sr-uuid", "")
150+# out["host_local-cache-sr"] = dct.get("local-cache-sr", "")
151+ out["host_memory"] = omm = {}
152+ omm["total"] = safe_int(dct.get("memory-total", ""))
153+ omm["overhead"] = safe_int(dct.get("memory-overhead", ""))
154+ omm["free"] = safe_int(dct.get("memory-free", ""))
155+ omm["free-computed"] = safe_int(
156+ dct.get("memory-free-computed", ""))
157+
158+# out["host_API-version"] = avv = {}
159+# avv["vendor"] = dct.get("API-version-vendor", "")
160+# avv["major"] = safe_int(dct.get("API-version-major", ""))
161+# avv["minor"] = safe_int(dct.get("API-version-minor", ""))
162+
163+ out["host_uuid"] = dct.get("uuid", None)
164+ out["host_name-label"] = dct.get("name-label", "")
165+ out["host_name-description"] = dct.get("name-description", "")
166+# out["host_host-metrics-live"] = dct.get(
167+# "host-metrics-live", "false") == "true"
168+ out["host_hostname"] = dct.get("hostname", "")
169+ out["host_ip_address"] = dct.get("address", "")
170+ oc = dct.get("other-config", "")
171+ out["host_other-config"] = ocd = {}
172+ if oc:
173+ for oc_fld in oc.split("; "):
174+ ock, ocv = strip_kv(oc_fld)
175+ ocd[ock] = ocv
176+# out["host_capabilities"] = dct.get("capabilities", "").split("; ")
177+# out["host_allowed-operations"] = dct.get(
178+# "allowed-operations", "").split("; ")
179+# lsrv = dct.get("license-server", "")
180+# out["host_license-server"] = ols = {}
181+# if lsrv:
182+# for lspart in lsrv.split("; "):
183+# lsk, lsv = lspart.split(": ")
184+# if lsk == "port":
185+# ols[lsk] = safe_int(lsv)
186+# else:
187+# ols[lsk] = lsv
188+# sv = dct.get("software-version", "")
189+# out["host_software-version"] = osv = {}
190+# if sv:
191+# for svln in sv.split("; "):
192+# svk, svv = strip_kv(svln)
193+# osv[svk] = svv
194+ cpuinf = dct.get("cpu_info", "")
195+ out["host_cpu_info"] = ocp = {}
196+ if cpuinf:
197+ for cpln in cpuinf.split("; "):
198+ cpk, cpv = strip_kv(cpln)
199+ if cpk in ("cpu_count", "family", "model", "stepping"):
200+ ocp[cpk] = safe_int(cpv)
201+ else:
202+ ocp[cpk] = cpv
203+# out["host_edition"] = dct.get("edition", "")
204+# out["host_external-auth-service-name"] = dct.get(
205+# "external-auth-service-name", "")
206+ return out
207+
208+
209+if __name__ == "__main__":
210+ XenAPIPlugin.dispatch(
211+ {"host_data": host_data})