direct-io.hg

changeset 12344:913324616183

The attached patch implements more of the Xen-API functionality related
to the vTPM.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
author Ewan Mellor <ewan@xensource.com>
date Thu Nov 09 15:27:32 2006 +0000 (2006-11-09)
parents 62376b480034
children 2e35cf028ff0
files tools/python/scripts/xapi.domcfg.py tools/python/scripts/xapi.py tools/python/scripts/xapi.vtpmcfg.py tools/python/xen/xend/XendAPI.py tools/python/xen/xend/XendDomainInfo.py
line diff
     1.1 --- a/tools/python/scripts/xapi.domcfg.py	Thu Nov 09 11:40:28 2006 +0000
     1.2 +++ b/tools/python/scripts/xapi.domcfg.py	Thu Nov 09 15:27:32 2006 +0000
     1.3 @@ -20,8 +20,6 @@ actions_after_shutdown =  'destroy'
     1.4  actions_after_reboot =  'restart'
     1.5  actions_after_suspend =  'destroy'
     1.6  actions_after_crash =  'restart'
     1.7 -TPM_instance =  ''
     1.8 -TPM_backend =  ''
     1.9  bios_boot =  ''
    1.10  platform_std_VGA =  False
    1.11  platform_serial =  ''
     2.1 --- a/tools/python/scripts/xapi.py	Thu Nov 09 11:40:28 2006 +0000
     2.2 +++ b/tools/python/scripts/xapi.py	Thu Nov 09 15:27:32 2006 +0000
     2.3 @@ -42,6 +42,7 @@ COMMANDS = {
     2.4      'vdi-rename': ('<vdi_uuid> <new_name>', 'Rename VDI'),
     2.5      'vdi-delete': ('<vdi_uuid>', 'Delete VDI'),
     2.6      'vif-create': ('<domname> <pycfg>', 'Create VIF attached to domname'),
     2.7 +    'vtpm-create' : ('<domname> <pycfg>', 'Create VTPM attached to domname'),
     2.8  
     2.9      'vm-create': ('<pycfg>', 'Create VM with python config'),
    2.10      'vm-destroy': ('<domname>', 'Delete VM'),
    2.11 @@ -208,16 +209,22 @@ def xapi_vm_list(*args):
    2.12          if is_long:
    2.13              vbds = vm_info['vbds']
    2.14              vifs = vm_info['vifs']
    2.15 +            vtpms = vm_info['vtpms']
    2.16              vif_infos = []
    2.17              vbd_infos = []
    2.18 +            vtpm_infos = []
    2.19              for vbd in vbds:
    2.20                  vbd_info = execute(server.VBD.get_record, session, vbd)
    2.21                  vbd_infos.append(vbd_info)
    2.22              for vif in vifs:
    2.23                  vif_info = execute(server.VIF.get_record, session, vif)
    2.24                  vif_infos.append(vif_info)
    2.25 +            for vtpm in vtpms:
    2.26 +                vtpm_info = execute(server.VTPM.get_record, session, vtpm)
    2.27 +                vtpm_infos.append(vtpm_info)
    2.28              vm_info['vbds'] = vbd_infos
    2.29              vm_info['vifs'] = vif_infos
    2.30 +            vm_info['vtpms'] = vtpm_infos
    2.31              pprint(vm_info)
    2.32          else:
    2.33              print VM_LIST_FORMAT % _stringify(vm_info)
    2.34 @@ -377,8 +384,30 @@ def xapi_vdi_rename(*args):
    2.35      print 'Renaming VDI %s to %s' % (vdi_uuid, vdi_name)
    2.36      result = execute(server.VDI.set_name_label, session, vdi_uuid, vdi_name)
    2.37      print 'Done.'
    2.38 -    
    2.39 -        
    2.40 +
    2.41 +
    2.42 +def xapi_vtpm_create(*args):
    2.43 +    server, session = _connect()
    2.44 +    domname = args[0]
    2.45 +    cfg = _read_python_cfg(args[1])
    2.46 +
    2.47 +    vm_uuid = resolve_vm(server, session, domname)
    2.48 +    cfg['VM'] = vm_uuid
    2.49 +    print "Creating vTPM with cfg = %s" % cfg
    2.50 +    vtpm_uuid = execute(server.VTPM.create, session, cfg)
    2.51 +    print "Done. (%s)" % vtpm_uuid
    2.52 +    vtpm_id = execute(server.VTPM.get_instance, session, vtpm_uuid)
    2.53 +    print "Has instance number '%s'" % vtpm_id
    2.54 +    vtpm_be = execute(server.VTPM.get_backend, session, vtpm_uuid)
    2.55 +    print "Has backend in '%s'" % vtpm_be
    2.56 +    driver = execute(server.VTPM.get_driver, session, vtpm_uuid)
    2.57 +    print "Has driver type '%s'" % driver
    2.58 +    vtpm_rec = execute(server.VTPM.get_record, session, vtpm_uuid)
    2.59 +    print "Has vtpm record '%s'" % vtpm_rec
    2.60 +    vm = execute(server.VTPM.get_VM, session, vtpm_uuid)
    2.61 +    print "Has VM '%s'" % vm
    2.62 +
    2.63 +
    2.64  #
    2.65  # Command Line Utils
    2.66  #
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/python/scripts/xapi.vtpmcfg.py	Thu Nov 09 15:27:32 2006 +0000
     3.3 @@ -0,0 +1,3 @@
     3.4 +type = 'paravirtualised'
     3.5 +backend = 'Domain-0'
     3.6 +instance = 1
     4.1 --- a/tools/python/xen/xend/XendAPI.py	Thu Nov 09 11:40:28 2006 +0000
     4.2 +++ b/tools/python/xen/xend/XendAPI.py	Thu Nov 09 15:27:32 2006 +0000
     4.3 @@ -1282,11 +1282,11 @@ class XendAPI:
     4.4      # Xen API: Class VTPM
     4.5      # ----------------------------------------------------------------
     4.6  
     4.7 -    VTPM_attr_ro = [ ]
     4.8 -    VTPM_attr_rw = ['type',
     4.9 -                    'VM',
    4.10 +    VTPM_attr_rw = [ ]
    4.11 +    VTPM_attr_ro = ['VM',
    4.12                      'backend',
    4.13 -                    'instance']
    4.14 +                    'instance',
    4.15 +                    'driver']
    4.16  
    4.17      VTPM_attr_inst = VTPM_attr_rw
    4.18  
    4.19 @@ -1307,17 +1307,61 @@ class XendAPI:
    4.20  
    4.21          return xen_api_success(cfg)
    4.22  
    4.23 +    # Class Functions
    4.24 +    def vtpm_get_instance(self, session, vtpm_ref):
    4.25 +        xendom = XendDomain.instance()
    4.26 +        vm = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref)
    4.27 +        if not vm:
    4.28 +            return xen_api_error(XEND_ERROR_VTPM_INVALID)
    4.29 +        cfg = vm.get_dev_xenapi_config('vtpm', vtpm_ref)
    4.30 +        if not cfg:
    4.31 +            return xen_api_error(XEND_ERROR_VTPM_INVALID)
    4.32 +        if cfg.has_key('instance'):
    4.33 +            instance = cfg['instance']
    4.34 +        else:
    4.35 +            instance = -1
    4.36 +        return xen_api_success(instance)
    4.37 +
    4.38 +    def vtpm_get_driver(self, session, vtpm_ref):
    4.39 +        xendom = XendDomain.instance()
    4.40 +        vm = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref)
    4.41 +        if not vm:
    4.42 +            return xen_api_error(XEND_ERROR_VTPM_INVALID)
    4.43 +        cfg = vm.get_dev_xenapi_config('vtpm', vtpm_ref)
    4.44 +        if not cfg:
    4.45 +            return xen_api_error(XEND_ERROR_VTPM_INVALID)
    4.46 +        if cfg.has_key('type'):
    4.47 +            driver = cfg['type']
    4.48 +        else:
    4.49 +            driver = "Unknown"
    4.50 +        return xen_api_success(driver)
    4.51 +
    4.52 +    def vtpm_get_backend(self, session, vtpm_ref):
    4.53 +        xendom = XendDomain.instance()
    4.54 +        vm = xendom.get_vm_with_dev_uuid('vtpm', vtpm_ref)
    4.55 +        if not vm:
    4.56 +            return xen_api_error(XEND_ERROR_VTPM_INVALID)
    4.57 +        cfg = vm.get_dev_xenapi_config('vtpm', vtpm_ref)
    4.58 +        if not cfg:
    4.59 +            return xen_api_error(XEND_ERROR_VTPM_INVALID)
    4.60 +        if cfg.has_key('backend'):
    4.61 +            backend = cfg['backend']
    4.62 +        else:
    4.63 +            backend = "Domain-0"
    4.64 +        return xen_api_success(backend)
    4.65 +
    4.66 +    def vtpm_get_vm(self, session, vtpm_ref):
    4.67 +        xendom = XendDomain.instance()
    4.68 +        return xen_api_success(xendom.get_dev_property('vtpm', vtpm_ref, 'VM'))
    4.69 +
    4.70      # class methods
    4.71      def vtpm_create(self, session, vtpm_struct):
    4.72          xendom = XendDomain.instance()
    4.73          if xendom.is_valid_vm(vtpm_struct['VM']):
    4.74              dom = xendom.get_vm_by_uuid(vtpm_struct['VM'])
    4.75 -            try:
    4.76 -                vtpm_ref = dom.create_vtpm(vtpm_struct)
    4.77 -                xendom.managed_config_save(dom)
    4.78 -                return xen_api_success(vtpm_ref)
    4.79 -            except XendError:
    4.80 -                return xen_api_error(XEND_ERROR_TODO)
    4.81 +            vtpm_ref = dom.create_vtpm(vtpm_struct)
    4.82 +            xendom.managed_config_save(dom)
    4.83 +            return xen_api_success(vtpm_ref)
    4.84          else:
    4.85              return xen_api_error(XEND_ERROR_DOMAIN_INVALID)
    4.86  
     5.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Thu Nov 09 11:40:28 2006 +0000
     5.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Nov 09 15:27:32 2006 +0000
     5.3 @@ -1689,10 +1689,6 @@ class XendDomainInfo:
     5.4          return '' # TODO
     5.5      def get_power_state(self):
     5.6          return XEN_API_VM_POWER_STATE[self.state]
     5.7 -    def get_tpm_instance(self):
     5.8 -        return '' # TODO
     5.9 -    def get_tpm_backend(self):
    5.10 -        return '' # TODO
    5.11      def get_bios_boot(self):
    5.12          return '' # TODO
    5.13      def get_platform_std_vga(self):
    5.14 @@ -1833,6 +1829,9 @@ class XendDomainInfo:
    5.15              else:
    5.16                  config['mode'] = 'RW'
    5.17  
    5.18 +        if dev_class == 'vtpm':
    5.19 +            config['driver'] = 'paravirtualised' # TODO
    5.20 +
    5.21          return config
    5.22  
    5.23      def get_dev_property(self, dev_class, dev_uuid, field):
    5.24 @@ -1927,15 +1926,14 @@ class XendDomainInfo:
    5.25          @rtype: string
    5.26          """
    5.27  
    5.28 +        if self.state not in (DOM_STATE_HALTED,):
    5.29 +            raise VmError("Can only add vTPM to a halted domain.")
    5.30 +        if self.get_vtpms() != []:
    5.31 +            raise VmError('Domain already has a vTPM.')
    5.32          dev_uuid = self.info.device_add('vtpm', cfg_xenapi = xenapi_vtpm)
    5.33          if not dev_uuid:
    5.34              raise XendError('Failed to create device')
    5.35  
    5.36 -        if self.state in (DOM_STATE_HALTED,):
    5.37 -            sxpr = self.info.device_sxpr(dev_uuid)
    5.38 -            devid = self.getDeviceController('vtpm').createDevice(sxpr)
    5.39 -            raise XendError("Device creation failed")
    5.40 -
    5.41          return dev_uuid
    5.42  
    5.43      def has_device(self, dev_class, dev_uuid):