This repository has been archived by the owner on Jun 16, 2023. It is now read-only.
forked from Mirantis/virtlet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain_interface.go
106 lines (93 loc) · 3.84 KB
/
domain_interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
Copyright 2017 Mirantis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package virt
import (
"errors"
libvirtxml "github.com/libvirt/libvirt-go-xml"
)
const (
// DOMAIN_NOSTATE means "no state", i.e. that the domain state is undefined
DOMAIN_NOSTATE DomainState = iota
// DOMAIN_RUNNING means that the domain is running
DOMAIN_RUNNING
// DOMAIN_BLOCKED means that the domain is blocked on resource
DOMAIN_BLOCKED
// DOMAIN_PAUSED means that the domain is paused by user
DOMAIN_PAUSED
// DOMAIN_SHUTDOWN means that the domain is being shut down
DOMAIN_SHUTDOWN
// DOMAIN_CRASHED means that the domain is crashed
DOMAIN_CRASHED
// DOMAIN_PMSUSPENDED means that the domain is suspended
DOMAIN_PMSUSPENDED
// DOMAIN_SHUTOFF means that the domain is shut off
DOMAIN_SHUTOFF
)
// DomainState represents a state of a domain
type DomainState int
// ErrDomainNotFound error is returned by VirtDomainConnection's
// Lookup*() methods when the domain in question cannot be found
var ErrDomainNotFound = errors.New("domain not found")
// ErrSecretNotFound error is returned by VirtDomainConnection's
// Lookup*() methods when the domain in question cannot be found
var ErrSecretNotFound = errors.New("secret not found")
// VirtDomainConnection provides operations on domains that correspond to VMs
type VirtDomainConnection interface {
// Define creates and returns a new domain based on the specified definition
DefineDomain(def *libvirtxml.Domain) (VirtDomain, error)
// ListAll lists all the domains available on the system
ListDomains() ([]VirtDomain, error)
// LookupByName tries to locate the domain by name. In case if the
// domain cannot be found but no other error occurred, it returns
// ErrDomainNotFound
LookupDomainByName(name string) (VirtDomain, error)
// LookupDomainByUUIDString tries to locate the domain by its UUID. In case if the
// domain cannot be found but no other error occurred, it returns
// ErrDomainNotFound
LookupDomainByUUIDString(uuid string) (VirtDomain, error)
// DefineSecret defines a Secret with the specified value
DefineSecret(def *libvirtxml.Secret) (VirtSecret, error)
// LookupSecretByUUIDString tries to locate the secret by its UUID. In case if the
// secret cannot be found but no other error occurred, it returns
// ErrSecretNotFound
LookupSecretByUUIDString(uuid string) (VirtSecret, error)
// LookupSecretByUsageName tries to locate the secret by its Usage name. In case if the
// secret cannot be found but no other error occurred, it returns
// ErrSecretNotFound
LookupSecretByUsageName(usageType string, usageName string) (VirtSecret, error)
}
// Secret represents a secret that's used by the domain
type VirtSecret interface {
// SetValue sets the value of the secret
SetValue(value []byte) error
// Remove removes the secret
Remove() error
}
// VirtDomain represents a domain which corresponds to a VM
type VirtDomain interface {
// Create boots the domain
Create() error
// Destroy destroys the domain
Destroy() error
// Undefine removes the domain so it will no longer be possible
// to locate it using LookupByName() or LookupByUUIDString()
Undefine() error
// Shutdown shuts down the domain
Shutdown() error
// State obtains the current state of the domain
State() (DomainState, error)
// UUIDString() returns UUID string for this domain
UUIDString() (string, error)
// Name() returns the name of this domain
Name() (string, error)
}