[Pkg-xen-changes] [xen] 07/07: Handle JSON output from xl in xendomains init script

Bastian Blank waldi at moszumanska.debian.org
Sat Sep 6 14:36:48 UTC 2014


This is an automated email from the git hooks/post-receive script.

waldi pushed a commit to branch develop
in repository xen.

commit 8cd95262eff08511baa85e10ee1c8a9bd5e3dba9
Author: Bastian Blank <waldi at debian.org>
Date:   Sat Sep 6 16:32:30 2014 +0200

    Handle JSON output from xl in xendomains init script
---
 debian/changelog                        |  4 +++
 debian/scripts/xen-init-list            | 30 +++++++---------
 debian/scripts/xen-init-name            | 61 +++++++++++++++++++++++++++++++++
 debian/xen-utils-common.xendomains.init |  2 +-
 4 files changed, 79 insertions(+), 18 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index d068769..8bc1067 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,5 +1,6 @@
 xen (4.4.0-5) UNRELEASED; urgency=medium
 
+  [ Ian Campbell ]
   * Expand on the descriptions of some packages. (Closes: #466683)
   * Clarify where xen-utils-common is required. (Closes: #612403)
   * No longer depend on gawk. Xen can now use any awk one of which is always
@@ -7,6 +8,9 @@ xen (4.4.0-5) UNRELEASED; urgency=medium
   * Put core dumps in /var/lib/xen/dump and ensure it exists.
     (Closes: #444000)
 
+  [ Bastian Blank ]
+  * Handle JSON output from xl in xendomains init script.
+
  -- Ian Campbell <ijc at hellion.org.uk>  Sun, 31 Aug 2014 02:08:45 +0100
 
 xen (4.4.0-4) unstable; urgency=medium
diff --git a/debian/scripts/xen-init-list b/debian/scripts/xen-init-list
index 4b1924c..c7a69e5 100755
--- a/debian/scripts/xen-init-list
+++ b/debian/scripts/xen-init-list
@@ -1,7 +1,5 @@
 #!/usr/bin/python
 
-from __future__ import print_function
-
 import json
 import re
 import sys
@@ -12,32 +10,31 @@ class SXPParser(object):
     tokenizer_rules = r""" (?P<open> \( ) | (?P<close> \) ) | (?P<whitespace> \s+ ) | [^()^\s]+ """
     tokenizer_re = re.compile(tokenizer_rules, re.X)
 
-    def __init__(self):
-        self.stack = []
-        self.data = []
-
-    def __call__(self, input):
+    @classmethod
+    def loads(cls, input):
+        data = []
+        stack = []
         for match in self.tokenizer_re.finditer(input):
             if match.group('open'):
-                self.stack.append([])
+                stack.append([])
             elif match.group('close'):
-                top = self.stack.pop()
-                if self.stack:
-                    self.stack[-1].append(top)
+                top = stack.pop()
+                if stack:
+                    stack[-1].append(top)
                 else:
-                    self.data.append(top)
+                    data.append(top)
             elif match.group('whitespace'):
                 pass
             else:
-                if self.stack:
-                    self.stack[-1].append(match.group())
-        return self.data
+                if stack:
+                    stack[-1].append(match.group())
+        return data
 
 
 class Data(object):
     def __call__(self, out):
         for domid, info in sorted(self.data.iteritems(), reverse=True):
-            print(str(domid), *info)
+            out.write('{!s} {}\n'.format(domid, *info))
 
 
 class DataJSON(Data):
@@ -74,4 +71,3 @@ if __name__ == '__main__':
     else:
         d = DataJSON(p)
     d(sys.stdout)
-
diff --git a/debian/scripts/xen-init-name b/debian/scripts/xen-init-name
new file mode 100755
index 0000000..0efcb85
--- /dev/null
+++ b/debian/scripts/xen-init-name
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+import json
+import re
+import sys
+import subprocess
+
+
+class SXPParser(object):
+    tokenizer_rules = r""" (?P<open> \( ) | (?P<close> \) ) | (?P<whitespace> \s+ ) | [^()^\s]+ """
+    tokenizer_re = re.compile(tokenizer_rules, re.X)
+
+    @classmethod
+    def loads(cls, input):
+        data = []
+        stack = []
+        for match in cls.tokenizer_re.finditer(input):
+            if match.group('open'):
+                stack.append([])
+            elif match.group('close'):
+                top = stack.pop()
+                if stack:
+                    stack[-1].append(top)
+                else:
+                    data.append(top)
+            elif match.group('whitespace'):
+                pass
+            else:
+                if stack:
+                    stack[-1].append(match.group())
+        return data
+
+
+class Data(object):
+    def __call__(self, out):
+        out.write('{}\n'.format(self.name))
+
+
+class DataJSON(Data):
+    def __init__(self, p):
+        s = json.loads(p)
+        self.name = s['config']['c_info']['name']
+
+
+class DataSXP(Data):
+    def __init__(self, p):
+        s = SXPParser.loads(p)
+        for i in s:
+            if i and i[0] == 'domain':
+                data = dict(j for j in i if len(j) == 2)
+                self.name = data['name']
+                break
+
+
+if __name__ == '__main__':
+    p = subprocess.check_output(('xen', 'create', '--quiet', '--dryrun', '--defconfig', sys.argv[1]))
+    if p[0] == '(':
+        d = DataSXP(p)
+    else:
+        d = DataJSON(p)
+    d(sys.stdout)
diff --git a/debian/xen-utils-common.xendomains.init b/debian/xen-utils-common.xendomains.init
index 9d35423..5fd5a5d 100644
--- a/debian/xen-utils-common.xendomains.init
+++ b/debian/xen-utils-common.xendomains.init
@@ -42,7 +42,7 @@ shopt -s nullglob
 
 check_config_name()
 {
-  xen create --quiet --dryrun --defconfig "$1" | sed -n 's/^.*(name \(.*\))$/\1/p'
+  /usr/lib/xen-common/bin/xen-init-name "$1" 2>/dev/null
 }
 
 check_running()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-xen/xen.git



More information about the Pkg-xen-changes mailing list