Commit d76cda50 authored by Antoine Millet's avatar Antoine Millet

Implemented vmspec format in vm_define handler

parent a16b7ca6
......@@ -104,6 +104,10 @@ class NodeConfigParser(object):
self.plugins_store_path = config.get('node', 'plugins_store_path',
'/var/lib/cc-node/plugins')
# Path to define script
default_define_script = 'hkvm-define'
self.define_script = config.get('node', 'define_script', default_define_script)
# RPC handler ACLs
acl_section_name = 'node_handler'
if config.has_section(acl_section_name):
......
......@@ -16,6 +16,7 @@
import logging
import socket
import json
from StringIO import StringIO
from xml.etree import cElementTree as et
......@@ -37,6 +38,7 @@ from cloudcontrol.node.exc import (
from cloudcontrol.node.hypervisor.jobs import (
ImportVolume, ExportVolume, TCPTunnel, DRBD,
)
from cloudcontrol.node.utils import execute
logger = logging.getLogger(__name__)
......@@ -202,6 +204,25 @@ class Handler(HostHandler):
if format == 'xml':
return self.hypervisor.vm_define(data)
elif format == 'vmspec':
# Encode tags as description:
if 'tags' in data:
if 'description' not in data:
data['description'] = ''
for tag, value in data['tags'].iteritems():
data['description'] += '\n@%s=%s' % (tag, value)
# Delete the tags key which is not recognized by hkvm-define
try:
del data['tags']
except KeyError:
pass
rcode, output = execute(self.main, [self.main.config.define_script], stdin=json.dumps(data))
if rcode == 0:
return output.strip()
else:
raise RuntimeError(output.strip().split('\n')[-1].strip())
else:
raise NotImplementedError('Format not supported')
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment