[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [test-API PATCH 3/4] example: modify define.py to use the feature



    repos/domain/define.py
    repos/domain/xmls/kvm_guest_define.xml:
    the define.py will use the kvm_guest_define.xml by default.
    it also support a file given by user.
---
 repos/domain/define.py                 |   50 ++++++++++++++-----------------
 repos/domain/xmls/kvm_guest_define.xml |   47 ++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 27 deletions(-)
 create mode 100644 repos/domain/xmls/kvm_guest_define.xml

diff --git a/repos/domain/define.py b/repos/domain/define.py
index c8fe20e..18e87ac 100644
--- a/repos/domain/define.py
+++ b/repos/domain/define.py
@@ -14,21 +14,21 @@ from src import sharedmod
 from utils import utils
 from utils import xmlbuilder
 
-required_params = ('guestname', 'guesttype',)
-optional_params = ('uuid',
-                   'memory',
-                   'vcpu',
-                   'disksize',
-                   'fullimagepath',
-                   'imagetype',
-                   'hdmodel',
-                   'nicmodel',
-                   'macaddr',
-                   'ifacetype',
-                   'source',)
+required_params = ('guestname', 'diskpath',)
+optional_params = {'memory': 1048576,
+                   'vcpu': 1,
+                   'hddriver' : 'virtio',
+                   'nicdriver': 'virtio',
+                   'macaddr': '52:54:00:97:e4:28',
+                   'uuid' : '05867c1a-afeb-300e-e55e-2673391ae080',
+                   'username': None,
+                   'password': None,
+                   'guesttype': 'kvm',
+                   'xml': 'xmls/kvm_guest_define.xml'
+                  }
 
 def check_define_domain(guestname, guesttype, hostname, username, \
-                        password, util, logger):
+                        password, logger):
     """Check define domain result, if define domain is successful,
        guestname.xml will exist under /etc/libvirt/qemu/
        and can use virt-xml-validate tool to check the file validity
@@ -59,29 +59,25 @@ def define(params):
     """Define a domain from xml"""
     logger = params['logger']
     guestname = params['guestname']
-    guesttype = params['guesttype']
+
+    xmlstr = params['xml']
+    logger.debug("domain xml:\n%s" % xmlstr)
+
     conn = sharedmod.libvirtobj['conn']
     uri = conn.getURI()
 
-    hostname = utils.parser_uri(uri)[1]
+    hostname = utils.parse_uri(uri)[1]
+    username = params.get('username', '')
+    password = params.get('password', '')
+    guesttype = params.get('guesttype', 'kvm')
 
-    username = params['username']
-    password = params['password']
     logger.info("define domain on %s" % uri)
 
-    # Generate damain xml
-    xml_obj = xmlbuilder.XmlBuilder()
-    domain = xml_obj.add_domain(params)
-    xml_obj.add_disk(params, domain)
-    xml_obj.add_interface(params, domain)
-    dom_xml = xml_obj.build_domain(domain)
-    logger.debug("domain xml:\n%s" %dom_xml)
-
     # Define domain from xml
     try:
-        conn.defineXML(dom_xml)
+        conn.defineXML(xmlstr)
         if check_define_domain(guestname, guesttype, hostname, \
-                               username, password, util, logger):
+                               username, password, logger):
             logger.info("define a domain form xml is successful")
         else:
             logger.error("fail to check define domain")
diff --git a/repos/domain/xmls/kvm_guest_define.xml b/repos/domain/xmls/kvm_guest_define.xml
new file mode 100644
index 0000000..385ec66
--- /dev/null
+++ b/repos/domain/xmls/kvm_guest_define.xml
@@ -0,0 +1,47 @@
+<domain type='kvm'>
+  <name>GUESTNAME</name>
+  <uuid>UUID</uuid>
+  <memory unit='KiB'>MEMORY</memory>
+  <currentMemory unit='KiB'>MEMORY</currentMemory>
+  <vcpu>VCPU</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc-0.14'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <pae/>
+  </features>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>restart</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='qemu' type='qcow2'/>
+      <source file='DISKPATH'/>
+      <target dev='vda' bus='HDDRIVER'/>
+    </disk>
+    <interface type='network'>
+      <mac address='MACADDR'/>
+      <model type='NICDRIVER'/>
+      <source network='default'/>
+    </interface>
+    <serial type='pty'>
+      <target port='0'/>
+    </serial>
+    <console type='pty'>
+      <target type='serial' port='0'/>
+    </console>
+    <input type='mouse' bus='ps2'/>
+    <graphics type='vnc' port='-1' autoport='yes'/>
+    <sound model='ich6'>
+    </sound>
+    <video>
+      <model type='cirrus' vram='9216' heads='1'/>
+    </video>
+    <memballoon model='virtio'>
+    </memballoon>
+  </devices>
+</domain>
-- 
1.7.7.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]