summaryrefslogtreecommitdiffstats
path: root/deploy
diff options
context:
space:
mode:
Diffstat (limited to 'deploy')
-rw-r--r--deploy/config/schemas.py4
-rw-r--r--deploy/config/vm_environment/zte-virtual2/deploy.yml3
-rw-r--r--deploy/environment.py14
-rw-r--r--deploy/libvirt_utils.py35
4 files changed, 41 insertions, 15 deletions
diff --git a/deploy/config/schemas.py b/deploy/config/schemas.py
index 52ded2b4..7cc2c80e 100644
--- a/deploy/config/schemas.py
+++ b/deploy/config/schemas.py
@@ -13,6 +13,7 @@ from jsonschema import Draft4Validator, FormatChecker
MIN_DAISY_DISK_SIZE = 50
# minimal size of root_lv_size is 102400 mega-bytes
MIN_NODE_DISK_SIZE = 110
+MIN_CEPH_DISK_SIZE = 110
hosts_schema = {
'type': 'array',
@@ -36,7 +37,8 @@ disks_schema = {
'properties': {
'daisy': {'type': 'integer', 'minimum': MIN_DAISY_DISK_SIZE},
'controller': {'type': 'integer', 'minimum': MIN_NODE_DISK_SIZE},
- 'compute': {'type': 'integer', 'minimum': MIN_NODE_DISK_SIZE}
+ 'compute': {'type': 'integer', 'minimum': MIN_NODE_DISK_SIZE},
+ 'ceph': {'type': 'integer', 'minimum': MIN_CEPH_DISK_SIZE}
}
}
diff --git a/deploy/config/vm_environment/zte-virtual2/deploy.yml b/deploy/config/vm_environment/zte-virtual2/deploy.yml
index e086e7cf..646fa130 100644
--- a/deploy/config/vm_environment/zte-virtual2/deploy.yml
+++ b/deploy/config/vm_environment/zte-virtual2/deploy.yml
@@ -19,7 +19,8 @@ disks:
daisy: 50
controller: 110
compute: 110
+ ceph: 110
daisy_passwd: 'r00tme'
daisy_ip: '10.20.11.2'
daisy_gateway: '10.20.11.1'
-ceph_disk_name: ''
+ceph_disk_name: '/dev/sdb'
diff --git a/deploy/environment.py b/deploy/environment.py
index 21a0970a..d18bf550 100644
--- a/deploy/environment.py
+++ b/deploy/environment.py
@@ -13,6 +13,7 @@ import time
from config.schemas import (
MIN_NODE_DISK_SIZE,
+ MIN_CEPH_DISK_SIZE
)
from daisy_server import (
DaisyServer
@@ -176,7 +177,7 @@ class VirtualEnvironment(DaisyEnvironmentBase):
create_vm(template,
name=self.daisy_server_info['name'],
- disk_file=self.daisy_server_info['image'])
+ disks=[self.daisy_server_info['image']])
def create_daisy_server(self):
self.create_daisy_server_image()
@@ -206,7 +207,16 @@ class VirtualEnvironment(DaisyEnvironmentBase):
template = node['template']
disk_file = path_join(self.storage_dir, name + '.qcow2')
create_virtual_disk(disk_file, size)
- create_vm(template, name, disk_file)
+
+ disks = [disk_file]
+ ceph_disk_name = self.deploy_struct.get('ceph_disk_name', '')
+ if ceph_disk_name and ceph_disk_name != '/dev/sda' and 'CONTROLLER_LB' in roles:
+ ceph_size = self.deploy_struct.get('disks', {}).get('ceph', MIN_CEPH_DISK_SIZE)
+ ceph_disk_file = path_join(self.storage_dir, name + '_data.qcow2')
+ create_virtual_disk(ceph_disk_file, ceph_size)
+ disks.append(ceph_disk_file)
+
+ create_vm(template, name, disks)
def create_nodes(self):
# TODO: support virtNetTemplatePath in deploy.yml
diff --git a/deploy/libvirt_utils.py b/deploy/libvirt_utils.py
index cd203784..8c694c13 100644
--- a/deploy/libvirt_utils.py
+++ b/deploy/libvirt_utils.py
@@ -10,6 +10,7 @@
import commands
import libvirt
import os
+import string
import xml.etree.ElementTree as ET
from utils import (
@@ -47,13 +48,25 @@ def modify_vm_name(root, vm_name):
name_elem.text = vm_name
-def modify_vm_disk_file(root, disk_file):
- for disk in root.findall('./devices/disk'):
- if 'device' in disk.attrib and disk.attrib['device'] == 'disk':
- for source in disk.iterfind('source'):
- if 'file' in source.attrib:
- source.attrib['file'] = disk_file
- break
+def modify_vm_disk_file(root, disks):
+ dev_list = ['hd' + ch for ch in string.ascii_lowercase]
+ devices = root.find('./devices')
+ for disk in devices.findall('disk'):
+ if disk.attrib['device'] == 'disk':
+ devices.remove(disk)
+ else:
+ target = disk.find('target')
+ dev = target.attrib['dev']
+ if dev in dev_list:
+ dev_list.remove(dev)
+
+ for disk_file in disks:
+ dev = dev_list.pop(0)
+ disk = ET.Element('disk', attrib={'device': 'disk', 'type': 'file'})
+ disk.append(ET.Element('driver', attrib={'name': 'qemu', 'type': 'qcow2'}))
+ disk.append(ET.Element('source', attrib={'file': disk_file}))
+ disk.append(ET.Element('target', attrib={'dev': dev, 'bus': 'ide'}))
+ devices.append(disk)
def create_virtual_disk(disk_file, size):
@@ -66,16 +79,16 @@ def create_virtual_disk(disk_file, size):
err_exit('Fail to create qemu image !')
-def create_vm(template, name=None, disk_file=None):
+def create_vm(template, name=None, disks=None):
LI('Begin to create VM %s' % template)
- if name or disk_file:
+ if name or disks:
tree = ET.ElementTree(file=template)
root = tree.getroot()
if name:
modify_vm_name(root, name)
- if disk_file:
- modify_vm_disk_file(root, disk_file)
+ if disks:
+ modify_vm_disk_file(root, disks)
temp_file = path_join(WORKSPACE, 'tmp.xml')
tree.write(temp_file)