Beispiel #1
0
 def _copyHostProfile(self, hostProfile):
     """Helper function that makes a copy of the host profile document.
   """
     # TBD: Is there a better way than serializing/deserializing?
     serializedProf = SoapAdapter.Serialize(
         hostProfile, version=newestVersions.get('vim'))
     deserializedProf = SoapAdapter.Deserialize(serializedProf)
     return deserializedProf
Beispiel #2
0
 def WriteXml(self, obj, file=None):
     file = file or self.wfile
     self.send_header('Content-type', 'text/xml')
     self.end_headers()
     xmlStr = SoapAdapter.Serialize(obj)
     tag = "MobData"
     xmlDoc = '<?xml version="1.0" encoding="UTF-8"?>' \
         '<%s xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' \
         'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' \
         '%s</%s>' % (tag, xmlStr, tag)
     file.write(xmlDoc)
Beispiel #3
0
def serialize(obj):
    obj_cls = obj.__class__
    if obj_cls is dict:
        res = {k: serialize(v) for k, v in obj.items()}
    elif obj_cls is list:
        res = [serialize(val) for val in obj]
    elif issubclass(obj_cls, (VsphereObject, VsphereData)):
        res = {
            k: serialize(v)
            for k, v in obj.__dict__.items() if not k.startswith('_')
        }
    else:
        try:
            res = SoapAdapter.Serialize(obj)
        except UnicodeEncodeError:
            print("WARNING: Failed to serialize %s data" % type(obj))
            return None, None
        obj_cls = None
    return obj_cls, res
Beispiel #4
0
 def test_serialize_float(self):
     pc = vim.host.VsanInternalSystem.PolicyCost()
     pc.diskSpaceToAddressSpaceRatio = 1.0
     SoapAdapter.Serialize(pc, version='vim.version.version10')
Beispiel #5
0
 def test_serialize_integer(self):
     lp = vim.LongPolicy()
     lp.inherited = False
     lp.value = 100
     SoapAdapter.Serialize(lp, version='vim.version.version10')
Beispiel #6
0
 def test_serialize_object(self):
     val = vim.vm.device.VirtualDeviceSpec.FileOperation()
     # This line should not raise an exception, especially on Python 3.
     SoapAdapter.Serialize(val)