ia64/xen-unstable

changeset 12100:8e5e7399e9b5

[XEND] Fix many typos with VM interface to XenAPI

1. Python XMLRPC does not allow integer keys to structs.
2. Typo with on_suspend and on_preserve
3. Changed all tuples in constants to lists so .index() works.
4. Made get_vcpus_utils to return seconds of CPU time.
5. Fix flawed login in VM.get_record()
author Alastair Tse <atse@xensource.com>
date Thu Oct 05 18:48:54 2006 +0100 (2006-10-05)
parents acb85833be66
children 8728365bac33
files tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendAPIConstants.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/xen/xend/XendAPI.py	Thu Oct 05 18:24:18 2006 +0100
     1.2 +++ b/tools/python/xen/xend/XendAPI.py	Thu Oct 05 18:48:54 2006 +0100
     1.3 @@ -847,6 +847,9 @@ class XendAPI:
     1.4      def vm_get_record(self, session, vm_ref):
     1.5          xendom = XendDomain.instance()
     1.6          xeninfo = xendom.get_vm_by_uuid(vm_ref)
     1.7 +        if not xeninfo:
     1.8 +            return xen_api_error(XEND_ERROR_VM_INVALID)
     1.9 +        
    1.10          record = {
    1.11              'uuid': xeninfo.get_uuid(),
    1.12              'power_state': xeninfo.get_power_state(),
    1.13 @@ -870,7 +873,7 @@ class XendAPI:
    1.14              'vcpus_features_force_off': [],
    1.15              'actions_after_shutdown': xeninfo.get_on_shutdown(),
    1.16              'actions_after_reboot': xeninfo.get_on_reboot(),
    1.17 -            'actions_after_suspend': xeninfo.get_on_preserve(),
    1.18 +            'actions_after_suspend': xeninfo.get_on_suspend(),
    1.19              'actions_after_crash': xeninfo.get_on_crash(),
    1.20              'vifs': xeninfo.get_vifs(),
    1.21              'vbds': xeninfo.get_vbds(),
    1.22 @@ -886,17 +889,13 @@ class XendAPI:
    1.23              'boot_method': xeninfo.get_boot_method(),
    1.24              'kernel_kernel': xeninfo.get_kernel_image(),
    1.25              'kernel_initrd': xeninfo.get_kernel_initrd(),
    1.26 -            'kernel_args': xeninfo.get_boot_args(),
    1.27 +            'kernel_args': xeninfo.get_kernel_args(),
    1.28              'grub_cmdline': xeninfo.get_grub_cmdline(),
    1.29              'pci_bus': xeninfo.get_pci_bus(),
    1.30              'tools_version': xeninfo.get_tools_version(),
    1.31              'otherconfig': xeninfo.get_other_config()
    1.32          }
    1.33 -        
    1.34 -        if not xeninfo:
    1.35 -            xen_api_error(XEND_ERROR_VM_INVALID)
    1.36 -        else:
    1.37 -            xen_api_success(record)
    1.38 +        return xen_api_success(record)
    1.39  
    1.40      def vm_clean_reboot(self, session, vm_ref):
    1.41          xendom = XendDomain.instance()
     2.1 --- a/tools/python/xen/xend/XendAPIConstants.py	Thu Oct 05 18:24:18 2006 +0100
     2.2 +++ b/tools/python/xen/xend/XendAPIConstants.py	Thu Oct 05 18:48:54 2006 +0100
     2.3 @@ -19,14 +19,14 @@
     2.4  # Xen API Enums
     2.5  #
     2.6  
     2.7 -XEN_API_VM_POWER_STATE = (
     2.8 +XEN_API_VM_POWER_STATE = [
     2.9      'Halted',
    2.10      'Paused',
    2.11      'Running',
    2.12      'Suspended',
    2.13      'ShuttingDown',
    2.14      'Unknown'
    2.15 -)
    2.16 +]
    2.17  
    2.18  XEN_API_VM_POWER_STATE_HALTED = 0
    2.19  XEN_API_VM_POWER_STATE_PAUSED = 1
    2.20 @@ -35,7 +35,7 @@ XEN_API_VM_POWER_STATE_SUSPENDED = 3
    2.21  XEN_API_VM_POWER_STATE_SHUTTINGDOWN = 4
    2.22  XEN_API_VM_POWER_STATE_UNKNOWN = 5
    2.23  
    2.24 -XEN_API_CPU_FEATURE = (
    2.25 +XEN_API_CPU_FEATURE = [
    2.26      'FPU', 'VME', 'DE', 'PSE', 'TSC', 'MSR', 'PAE'
    2.27      'MCE', 'CX8', 'APIC', 'SEP', 'MTRR', 'PGE', 'MCA',
    2.28      'CMOV', 'PAT', 'PSE36', 'PN', 'CLFLSH', 'DTES',
    2.29 @@ -47,29 +47,29 @@ XEN_API_CPU_FEATURE = (
    2.30      'XMM3', 'MWAIT', 'DSCPL', 'EST', 'TM2', 'CID', 'CX16',
    2.31      'XTPR', 'XSTORE', 'XSTORE_EN', 'XCRYPT', 'XCRYPT_EN',
    2.32      'LAHF_LM', 'CMP_LEGACY'
    2.33 -)
    2.34 +]
    2.35  
    2.36 -XEN_API_ON_NORMAL_EXIT = (
    2.37 +XEN_API_ON_NORMAL_EXIT = [
    2.38      'destroy',
    2.39      'restart',
    2.40 -)
    2.41 +]
    2.42  
    2.43 -XEN_API_ON_CRASH_BEHAVIOUR = (
    2.44 +XEN_API_ON_CRASH_BEHAVIOUR = [
    2.45      'destroy',
    2.46      'coredump_and_destroy',
    2.47      'restart',
    2.48      'coredump_and_restart',
    2.49      'preserve',
    2.50      'rename_restart'
    2.51 -)
    2.52 +]
    2.53  
    2.54 -XEN_API_BOOT_TYPE = (
    2.55 +XEN_API_BOOT_TYPE = [
    2.56      'bios',
    2.57      'grub',
    2.58      'kernel_external',
    2.59      'kernel_internal'
    2.60 -)
    2.61 +]
    2.62  
    2.63 -XEN_API_VBD_MODE = ('RO', 'RW')
    2.64 +XEN_API_VBD_MODE = ['RO', 'RW']
    2.65  
    2.66 -XEN_API_DRIVER_TYPE = ('ioemu', 'paravirtualised')
    2.67 +XEN_API_DRIVER_TYPE = ['ioemu', 'paravirtualised']
     3.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Oct 05 18:24:18 2006 +0100
     3.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Oct 05 18:48:54 2006 +0100
     3.3 @@ -807,7 +807,6 @@ class XendDomainInfo:
     3.4      def getVCpuCount(self):
     3.5          return self.info['vcpus']
     3.6  
     3.7 -
     3.8      def setVCpuCount(self, vcpus):
     3.9          self.info['vcpu_avail'] = (1 << vcpus) - 1
    3.10          self.storeVm('vcpu_avail', self.info['vcpu_avail'])
    3.11 @@ -1646,7 +1645,7 @@ class XendDomainInfo:
    3.12      def get_uuid(self):
    3.13          return self.info['uuid']
    3.14      def get_memory_static_max(self):
    3.15 -        return self.info['memmax']
    3.16 +        return self.info['maxmem']
    3.17      def get_memory_static_min(self):
    3.18          return self.info['memory']
    3.19      def get_vcpus_policy(self):
    3.20 @@ -1761,19 +1760,21 @@ class XendDomainInfo:
    3.21  
    3.22      def get_vcpus_util(self):
    3.23          # TODO: this returns the total accum cpu time, rather than util
    3.24 +        # TODO: spec says that key is int, however, python does not allow
    3.25 +        #       non-string keys to dictionaries.
    3.26          vcpu_util = {}
    3.27 -        if 'max_vcpu_id' in self.info:
    3.28 +        if 'max_vcpu_id' in self.info and self.domid != None:
    3.29              for i in range(0, self.info['max_vcpu_id']+1):
    3.30                  info = xc.vcpu_getinfo(self.domid, i)
    3.31 -                vcpu_util[i] = info['cpu_time']
    3.32 +                vcpu_util[str(i)] = info['cpu_time']/1000000000.0
    3.33                  
    3.34          return vcpu_util
    3.35  
    3.36      def get_vifs(self):
    3.37 -        return self.info['vif_refs']
    3.38 +        return self.info.get('vif_refs', [])
    3.39  
    3.40      def get_vbds(self):
    3.41 -        return self.info['vbd_refs']
    3.42 +        return self.info.get('vbd_refs', [])
    3.43  
    3.44      def create_vbd(self, xenapi_vbd):
    3.45          """Create a VBD device from the passed struct in Xen API format.