-
Notifications
You must be signed in to change notification settings - Fork 15
/
volume.go
105 lines (90 loc) · 3.24 KB
/
volume.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
/*
* Copyright 2018-2019, CS Systemes d'Information, http://www.c-s.fr
*
* 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 propertiesv1
import (
"time"
"github.com/CS-SI/SafeScale/lib/server/iaas/resources/enums/VolumeProperty"
"github.com/CS-SI/SafeScale/lib/utils/serialize"
)
// VolumeDescription contains additional information describing the volume, in V1
// !!!FROZEN!!!
// Note: if tagged as FROZEN, must not be changed ever.
// Create a new version instead with needed supplemental fields
type VolumeDescription struct {
// Purpose contains the reason of the existence of the volume
Purpose string
// Created contains the time of creation of the volume
Created time.Time
}
// NewVolumeDescription ...
func NewVolumeDescription() *VolumeDescription {
return &VolumeDescription{}
}
// Content ... (serialize.Property interface)
func (vd *VolumeDescription) Content() interface{} {
return vd
}
// Clone ... (serialize.Property interface)
func (vd *VolumeDescription) Clone() serialize.Property {
return NewVolumeDescription().Replace(vd)
}
// Replace ... (serialize.Property interface)
func (vd *VolumeDescription) Replace(p serialize.Property) serialize.Property {
*vd = *p.(*VolumeDescription)
return vd
}
// VolumeAttachments contains host ids where the volume is attached
// !!!FROZEN!!!
// Note: if tagged as FROZEN, must not be changed ever.
// Create a new version instead with needed supplemental fields
type VolumeAttachments struct {
Shareable bool `json:"shareable,omitempty"` // Tells if the volume can be shared with multiple host
Hosts map[string]string `json:"hosts,omitempty"` // Contains the name of the hosts mounting the volume, indexed by ID
}
// NewVolumeAttachments ...
func NewVolumeAttachments() *VolumeAttachments {
return &VolumeAttachments{
Hosts: map[string]string{},
}
}
// Reset resets the content of the property
func (va *VolumeAttachments) Reset() {
*va = VolumeAttachments{
Hosts: map[string]string{},
}
}
// Content ... (serialize.Property interface)
func (va *VolumeAttachments) Content() interface{} {
return va
}
// Clone ... (serialize.Property interface)
func (va *VolumeAttachments) Clone() serialize.Property {
return NewVolumeAttachments().Replace(va)
}
// Replace ... (serialize.Property interface)
func (va *VolumeAttachments) Replace(p serialize.Property) serialize.Property {
src := p.(*VolumeAttachments)
*va = *src
va.Hosts = make(map[string]string, len(src.Hosts))
for k, v := range src.Hosts {
va.Hosts[k] = v
}
return va
}
func init() {
serialize.PropertyTypeRegistry.Register("resources.volume", VolumeProperty.DescriptionV1, NewVolumeDescription())
serialize.PropertyTypeRegistry.Register("resources.volume", VolumeProperty.AttachedV1, NewVolumeAttachments())
}