Пример #1
0
        public Domain CreateDomain(string xml)
        {
            IntPtr result = Libvirt.virDomainCreateXML(_conn, xml);

            ThrowExceptionOnError(result);

            return(new Domain(_conn, result));
        }
Пример #2
0
        public void Close(bool ignoreErrors = false)
        {
            if (!IsOpen)
            {
                return;
            }

            int result = Libvirt.virConnectClose(_conn);

            if (!ignoreErrors)
            {
                ThrowExceptionOnError(result);
            }

            IsOpen = false;
        }
Пример #3
0
        public List <Domain> GetDomains(virConnectListAllDomainsFlags flags = default)
        {
            int result = Libvirt.virConnectListAllDomains(_conn, out IntPtr ptrDomains, flags);

            ThrowExceptionOnError(result);

            List <Domain> domains = new List <Domain>();

            for (int i = 0; i < result; i++)
            {
                IntPtr ptrDomain = Marshal.ReadIntPtr(ptrDomains, i * IntPtr.Size);
                domains.Add(new Domain(_conn, ptrDomain));
            }

            Libvirt.virFree(ptrDomains);

            return(domains);
        }
Пример #4
0
        public void Open(bool readOnly = false)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException("Connect", "Cannot open a disposed connection.");
            }

            if (readOnly)
            {
                _conn = Libvirt.virConnectOpenReadOnly(Uri);
            }
            else
            {
                _conn = Libvirt.virConnectOpen(Uri);
            }

            ThrowExceptionOnError(_conn);

            IsOpen = true;
        }
Пример #5
0
 public void CleanUpNativeData(IntPtr pNativeData)
 {
     Libvirt.virFree(pNativeData);
 }
Пример #6
0
 public void RestoreDomain(string file) => ThrowExceptionOnError(Libvirt.virDomainRestore(_conn, file));
Пример #7
0
 public void Save(string file) => ThrowExceptionOnError(Libvirt.virDomainSave(_ptrDomain, file));
Пример #8
0
 protected override void DisposeInternal()
 {
     Libvirt.virDomainFree(_ptrDomain);
 }
Пример #9
0
 public void Resume() => ThrowExceptionOnError(Libvirt.virDomainResume(_ptrDomain));
Пример #10
0
 public void Suspend() => ThrowExceptionOnError(Libvirt.virDomainSuspend(_ptrDomain));
Пример #11
0
 public void Shutdown() => ThrowExceptionOnError(Libvirt.virDomainShutdown(_ptrDomain));
Пример #12
0
 public void Destroy() => ThrowExceptionOnError(Libvirt.virDomainDestroy(_ptrDomain));
Пример #13
0
        private static virError GetLastError()
        {
            IntPtr errPtr = Libvirt.virGetLastError();

            return(Marshal.PtrToStructure <virError>(errPtr));
        }