-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource_controller_interface.go
More file actions
182 lines (159 loc) · 4.65 KB
/
Copy pathresource_controller_interface.go
File metadata and controls
182 lines (159 loc) · 4.65 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* lvcl is a simple program Clustering libvirt servers
* Copyright (C) 2020 Adam Prycki (email: adam.prycki@gmail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package main
import "encoding/json"
import "io/ioutil"
const(
resource_controller_id_libvirt=iota
resource_controller_id_docker
resource_controller_id_dummy
resource_controller_id_generic
resource_state_starting
resource_state_running
resource_state_stopping
resource_state_stopped
resource_state_paused
resource_state_migrating
resource_state_other
resource_state_nuked
resource_state_reboot
resource_state_undefine
utilization_hw_cores
utilization_hw_threads
utilization_hw_numaNodes
utilization_hw_core_pre_numa
utilization_hw_mem
utilization_vpcus
utilization_vmem
utilization_mem_total_kb
utilization_mem_free_kb
utilization_mem_cached_kb
utilization_mem_avalible_kb
utilization_mem_buffers_kb
utilization_swap_total_kb
utilization_swap_free_kb
utilization_swap_cached_kb
utilization_load_1_100 //load average 1 minutes * 100
utilization_load_5_100 //load average 5 minutes * 100
utilization_load_15_100 //load average 15 minutes * 100
utilization_cpu_time_kernel
utilization_cpu_time_user
utilization_cpu_time_io
utilization_cpu_time_idle
resouce_failure_unknown
event_migration
event_action_libvirt_migration
)
// generalized HARDWARE resource
// could be number of cores, RAM usage, cpu load etc
type Cluster_utilization struct {
ResourceController_name string
ResourceController_id int
Name string
Id int
Value uint64
}
// generalized Cluster resource deployed by balance system
type Cluster_resource struct {
ResourceController_name string
ResourceController_id int
Name string
Id int
State int
State_name string
Util []Cluster_utilization
Strs map[string]string
Ints map[string]int
Bools map[string]bool
Placement string
ConfFile string
}
type ResourceController interface {
Get_running_resources() *[]Cluster_resource
Get_utilization() *[]Cluster_utilization
Start_resource(name string) bool
Stop_resource(name string) bool
Nuke_resource(name string) bool
Migrate_resource(resource_name string, dest_node string) bool
Clean_resource(name string) bool
Kill_controller() bool
Get_controller_health() bool
Get_live_migration_support() bool
}
func _stateString(i int) string {
switch i {
case resource_state_starting:
return "starting"
case resource_state_running:
return "running"
case resource_state_stopping:
return "stopping"
case resource_state_stopped:
return "stopped"
case resource_state_paused:
return "paused "
case resource_state_migrating:
return "migrating"
case resource_state_other:
return "other "
default:
return "other "}}
func (c *Cluster_resource)_stateString() string {
return _stateString( c.State )}
func (c *Cluster_resource)GetStateString() string {
return _stateString(c.State)}
func (c *Cluster_resource)CtlString() string {
switch c.ResourceController_id {
case resource_controller_id_libvirt:
return "libvirt"
case resource_controller_id_docker:
return "docker"
case resource_controller_id_dummy:
return "dummy "
default:
return "other "}}
func (c *Cluster_utilization)NameString() string {
switch c.Id {
case utilization_vpcus:
return "vCPUs "
case utilization_hw_cores:
return "hwCPUs"
case utilization_hw_mem:
return "hwMEM "
case utilization_vmem:
return "vMEM "
default:
return "other "}}
func (u *Cluster_utilization)UtilAdd(arg *Cluster_utilization) bool {
// maybe this function shouldn't check for string name
// less error prone in config and it should be faster
//if u.Id != arg.Id || u.Name != arg.Name {
if u.Id != arg.Id { // TODO check for both
// resources of the wrong type
return false}
u.Value += arg.Value
return true}
func (c *Cluster_resource)SaveToFile(){
var confser []byte
var err error
c.Placement = ""
confser, err = json.MarshalIndent(c, "", " ")
if err != nil {
lg.err("Can't serislize resource", err)}
ioutil.WriteFile(c.ConfFile, confser, 0644)}