~ubuntu-branches/ubuntu/maverick/libvirt/maverick

« back to all changes in this revision

Viewing changes to python/libvirt.py

Tags: upstream-0.6.4
Import upstream version 0.6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
# On cygwin, the DLL is called cygvirtmod.dll
9
9
try:
10
10
    import libvirtmod
11
 
except:
12
 
    import cygvirtmod as libvirtmod
 
11
except ImportError, lib_e:
 
12
    try:
 
13
        import cygvirtmod as libvirtmod
 
14
    except ImportError, cyg_e:
 
15
        if str(cyg_e).count("No module named"):
 
16
            raise lib_e
13
17
 
14
18
import types
15
19
 
684
688
        __tmp = virNetwork(self, _obj=ret)
685
689
        return __tmp
686
690
 
 
691
class virInterface:
 
692
    def __init__(self, conn, _obj=None):
 
693
        self._conn = conn
 
694
        if _obj != None:self._o = _obj;return
 
695
        self._o = None
 
696
 
 
697
    def __del__(self):
 
698
        if self._o != None:
 
699
            libvirtmod.virInterfaceFree(self._o)
 
700
        self._o = None
 
701
 
 
702
    #
 
703
    # virInterface functions from module libvirt
 
704
    #
 
705
 
 
706
    def ceCreate(self, flags):
 
707
        """Activate an interface (ie call "ifup") """
 
708
        ret = libvirtmod.virInterfaceCreate(self._o, flags)
 
709
        if ret == -1: raise libvirtError ('virInterfaceCreate() failed', net=self)
 
710
        return ret
 
711
 
 
712
    def ceDestroy(self, flags):
 
713
        """deactivate an interface (ie call "ifdown") This does not
 
714
          remove the interface from the config, and does not free the
 
715
           associated virInterfacePtr object. """
 
716
        ret = libvirtmod.virInterfaceDestroy(self._o, flags)
 
717
        if ret == -1: raise libvirtError ('virInterfaceDestroy() failed', net=self)
 
718
        return ret
 
719
 
 
720
    def ceRef(self):
 
721
        """Increment the reference count on the interface. For each
 
722
          additional call to this method, there shall be a
 
723
          corresponding call to virInterfaceFree to release the
 
724
          reference count, once the caller no longer needs the
 
725
          reference to this object.  This method is typically useful
 
726
          for applications where multiple threads are using a
 
727
          connection, and it is required that the connection remain
 
728
          open until all threads have finished using it. ie, each new
 
729
          thread using a interface would increment the reference
 
730
           count. """
 
731
        ret = libvirtmod.virInterfaceRef(self._o)
 
732
        if ret == -1: raise libvirtError ('virInterfaceRef() failed', net=self)
 
733
        return ret
 
734
 
 
735
    def ceUndefine(self):
 
736
        """Undefine an interface, ie remove it from the config. This
 
737
           does not free the associated virInterfacePtr object. """
 
738
        ret = libvirtmod.virInterfaceUndefine(self._o)
 
739
        if ret == -1: raise libvirtError ('virInterfaceUndefine() failed', net=self)
 
740
        return ret
 
741
 
 
742
    def etConnect(self):
 
743
        """Provides the connection pointer associated with an
 
744
          interface.  The reference counter on the connection is not
 
745
          increased by this call.  WARNING: When writing libvirt
 
746
          bindings in other languages, do not use this function. 
 
747
          Instead, store the connection and the interface object
 
748
           together. """
 
749
        ret = libvirtmod.virInterfaceGetConnect(self._o)
 
750
        if ret is None:raise libvirtError('virInterfaceGetConnect() failed', net=self)
 
751
        __tmp = virConnect(_obj=ret)
 
752
        return __tmp
 
753
 
 
754
    def etMACString(self):
 
755
        """Get the MAC for a interface as string. For more information
 
756
           about MAC see RFC4122. """
 
757
        ret = libvirtmod.virInterfaceGetMACString(self._o)
 
758
        if ret is None: raise libvirtError ('virInterfaceGetMACString() failed', net=self)
 
759
        return ret
 
760
 
 
761
    def etName(self):
 
762
        """Get the public name for that interface """
 
763
        ret = libvirtmod.virInterfaceGetName(self._o)
 
764
        return ret
 
765
 
 
766
    def etXMLDesc(self, flags):
 
767
        """Provide an XML description of the interface. The
 
768
          description may be reused later to recreate the interface
 
769
           with virInterfaceCreateXML(). """
 
770
        ret = libvirtmod.virInterfaceGetXMLDesc(self._o, flags)
 
771
        if ret is None: raise libvirtError ('virInterfaceGetXMLDesc() failed', net=self)
 
772
        return ret
 
773
 
687
774
class virStoragePool:
688
775
    def __init__(self, conn, _obj=None):
689
776
        self._conn = conn
740
827
        __tmp = virStorageVol(self, _obj=ret)
741
828
        return __tmp
742
829
 
 
830
    def createXMLFrom(self, xmldesc, clonevol, flags):
 
831
        """Create a storage volume in the parent pool, using the
 
832
          'clonevol' volume as input. Information for the new volume
 
833
          (name, perms)  are passed via a typical volume XML
 
834
           description. """
 
835
        if clonevol is None: clonevol__o = None
 
836
        else: clonevol__o = clonevol._o
 
837
        ret = libvirtmod.virStorageVolCreateXMLFrom(self._o, xmldesc, clonevol__o, flags)
 
838
        if ret is None:raise libvirtError('virStorageVolCreateXMLFrom() failed', pool=self)
 
839
        __tmp = virStorageVol(self, _obj=ret)
 
840
        return __tmp
 
841
 
743
842
    def delete(self, flags):
744
843
        """Delete the underlying pool resources. This is a
745
844
          non-recoverable operation. The virStoragePoolPtr object
976
1075
        return __tmp
977
1076
 
978
1077
    def createXML(self, xmlDesc, flags):
 
1078
        """Create a new device on the VM host machine, for example,
 
1079
           virtual HBAs created using vport_create. """
 
1080
        ret = libvirtmod.virNodeDeviceCreateXML(self._o, xmlDesc, flags)
 
1081
        if ret is None:raise libvirtError('virNodeDeviceCreateXML() failed', conn=self)
 
1082
        __tmp = virNodeDevice(self, _obj=ret)
 
1083
        return __tmp
 
1084
 
 
1085
    def createXML(self, xmlDesc, flags):
979
1086
        """Launch a new guest domain, based on an XML description
980
1087
          similar to the one returned by virDomainGetXMLDesc() This
981
1088
          function may requires privileged access to the hypervisor.
990
1097
    def defineXML(self, xml):
991
1098
        """Define a domain, but does not start it. This definition is
992
1099
          persistent, until explicitly undefined with
993
 
           virDomainUndefine(). """
 
1100
          virDomainUndefine(). A previous definition for this domain
 
1101
           would be overriden if it already exists. """
994
1102
        ret = libvirtmod.virDomainDefineXML(self._o, xml)
995
1103
        if ret is None:raise libvirtError('virDomainDefineXML() failed', conn=self)
996
1104
        __tmp = virDomain(self,_obj=ret)
997
1105
        return __tmp
998
1106
 
 
1107
    def domainXMLFromNative(self, nativeFormat, nativeConfig, flags):
 
1108
        """Reads native configuration data  describing a domain, and
 
1109
          generates libvirt domain XML. The format of the native data
 
1110
           is hypervisor dependant. """
 
1111
        ret = libvirtmod.virConnectDomainXMLFromNative(self._o, nativeFormat, nativeConfig, flags)
 
1112
        if ret is None: raise libvirtError ('virConnectDomainXMLFromNative() failed', conn=self)
 
1113
        return ret
 
1114
 
 
1115
    def domainXMLToNative(self, nativeFormat, domainXml, flags):
 
1116
        """Reads a domain XML configuration document, and generates
 
1117
          generates a native configuration file describing the
 
1118
          domain. The format of the native data is hypervisor
 
1119
           dependant. """
 
1120
        ret = libvirtmod.virConnectDomainXMLToNative(self._o, nativeFormat, domainXml, flags)
 
1121
        if ret is None: raise libvirtError ('virConnectDomainXMLToNative() failed', conn=self)
 
1122
        return ret
 
1123
 
999
1124
    def findStoragePoolSources(self, type, srcSpec, flags):
1000
1125
        """Talks to a storage backend and attempts to auto-discover
1001
1126
          the set of available storage pool sources. e.g. For iSCSI
1016
1141
        return ret
1017
1142
 
1018
1143
    def getFreeMemory(self):
1019
 
        """provides the free memory available on the Node """
 
1144
        """provides the free memory available on the Node Note: most
 
1145
          libvirt APIs provide memory sizes in kilobytes, but in this
 
1146
          function the returned value is in bytes. Divide by 1024 as
 
1147
           necessary. """
1020
1148
        ret = libvirtmod.virNodeGetFreeMemory(self._o)
1021
1149
        return ret
1022
1150
 
1056
1184
        if ret is None: raise libvirtError ('virConnectGetURI() failed', conn=self)
1057
1185
        return ret
1058
1186
 
 
1187
    def interfaceDefineXML(self, xml, flags):
 
1188
        """Define an interface (or modify existing interface
 
1189
           configuration) """
 
1190
        ret = libvirtmod.virInterfaceDefineXML(self._o, xml, flags)
 
1191
        if ret is None:raise libvirtError('virInterfaceDefineXML() failed', conn=self)
 
1192
        __tmp = virInterface(self, _obj=ret)
 
1193
        return __tmp
 
1194
 
 
1195
    def interfaceLookupByMACString(self, macstr):
 
1196
        """Try to lookup an interface on the given hypervisor based on
 
1197
           its MAC. """
 
1198
        ret = libvirtmod.virInterfaceLookupByMACString(self._o, macstr)
 
1199
        if ret is None:raise libvirtError('virInterfaceLookupByMACString() failed', conn=self)
 
1200
        __tmp = virInterface(self, _obj=ret)
 
1201
        return __tmp
 
1202
 
 
1203
    def interfaceLookupByName(self, name):
 
1204
        """Try to lookup an interface on the given hypervisor based on
 
1205
           its name. """
 
1206
        ret = libvirtmod.virInterfaceLookupByName(self._o, name)
 
1207
        if ret is None:raise libvirtError('virInterfaceLookupByName() failed', conn=self)
 
1208
        __tmp = virInterface(self, _obj=ret)
 
1209
        return __tmp
 
1210
 
 
1211
    def listInterfaces(self, names, maxnames):
 
1212
        """Collect the list of physical host interfaces, and store
 
1213
           their names in @names """
 
1214
        ret = libvirtmod.virConnectListInterfaces(self._o, names, maxnames)
 
1215
        if ret == -1: raise libvirtError ('virConnectListInterfaces() failed', conn=self)
 
1216
        return ret
 
1217
 
1059
1218
    def lookupByID(self, id):
1060
1219
        """Try to find a domain based on the hypervisor ID number Note
1061
1220
          that this won't work for inactive domains which have an ID
1190
1349
        if ret == -1: raise libvirtError ('virConnectNumOfDomains() failed', conn=self)
1191
1350
        return ret
1192
1351
 
 
1352
    def numOfInterfaces(self):
 
1353
        """Provides the number of interfaces on the physical host. """
 
1354
        ret = libvirtmod.virConnectNumOfInterfaces(self._o)
 
1355
        if ret == -1: raise libvirtError ('virConnectNumOfInterfaces() failed', conn=self)
 
1356
        return ret
 
1357
 
1193
1358
    def numOfNetworks(self):
1194
1359
        """Provides the number of active networks. """
1195
1360
        ret = libvirtmod.virConnectNumOfNetworks(self._o)
1442
1607
        if ret is None: raise libvirtError ('virNodeDeviceGetXMLDesc() failed')
1443
1608
        return ret
1444
1609
 
 
1610
    def destroy(self):
 
1611
        """Destroy the device object. The virtual device is removed
 
1612
          from the host operating system. This function may require
 
1613
           privileged access """
 
1614
        ret = libvirtmod.virNodeDeviceDestroy(self._o)
 
1615
        if ret == -1: raise libvirtError ('virNodeDeviceDestroy() failed')
 
1616
        return ret
 
1617
 
1445
1618
    def dettach(self):
 
1619
        """Dettach the node device from the node itself so that it may
 
1620
          be assigned to a guest domain.  Depending on the
 
1621
          hypervisor, this may involve operations such as unbinding
 
1622
          any device drivers from the device, binding the device to a
 
1623
          dummy device driver and resetting the device.  If the
 
1624
          device is currently in use by the node, this method may
 
1625
          fail.  Once the device is not assigned to any guest, it may
 
1626
          be re-attached to the node using the
 
1627
           virNodeDeviceReattach() method. """
1446
1628
        ret = libvirtmod.virNodeDeviceDettach(self._o)
1447
1629
        if ret == -1: raise libvirtError ('virNodeDeviceDettach() failed')
1448
1630
        return ret
1549
1731
VIR_FROM_NODEDEV = 22
1550
1732
VIR_FROM_XEN_INOTIFY = 23
1551
1733
VIR_FROM_SECURITY = 24
 
1734
VIR_FROM_VBOX = 25
 
1735
VIR_FROM_INTERFACE = 26
 
1736
VIR_FROM_ONE = 27
1552
1737
 
1553
1738
# virDomainEventStartedDetailType
1554
1739
VIR_DOMAIN_EVENT_STARTED_BOOTED = 0
1659
1844
VIR_ERR_INVALID_NODE_DEVICE = 52
1660
1845
VIR_ERR_NO_NODE_DEVICE = 53
1661
1846
VIR_ERR_NO_SECURITY_MODEL = 54
 
1847
VIR_ERR_OPERATION_INVALID = 55
 
1848
VIR_WAR_NO_INTERFACE = 56
 
1849
VIR_ERR_NO_INTERFACE = 57
 
1850
VIR_ERR_INVALID_INTERFACE = 58
1662
1851
 
1663
1852
# virDomainMemoryFlags
1664
1853
VIR_MEMORY_VIRTUAL = 1