-
Notifications
You must be signed in to change notification settings - Fork 1
/
disk_subresource.go
130 lines (106 loc) · 3.19 KB
/
disk_subresource.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
Copyright (c) 2019 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Author: Sergey Shubin, <sergey.shubin@digitalenergy.online>, <svs1370@gmail.com>
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 decs
import (
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)
func makeDisksConfig(arg_list []interface{}) (disks []DiskConfig, count int) {
count = len(arg_list)
if count < 1 {
return nil, 0
}
// allocate DataDisks list and fill it
disks = make([]DiskConfig, count)
var subres_data map[string]interface{}
for index, value := range arg_list {
subres_data = value.(map[string]interface{})
disks[index].Label = subres_data["label"].(string)
disks[index].Size = subres_data["size"].(int)
disks[index].Pool = subres_data["pool"].(string)
disks[index].Provider = subres_data["provider"].(string)
}
return disks, count
}
func flattenDataDisks(disks []DataDiskRecord) []interface{} {
var length = 0
for _, value := range disks {
if value.DiskType == "D" {
length += 1
}
}
log.Printf("flattenDataDisks: found %d disks with D type", length)
result := make([]interface{}, length)
if length == 0 {
return result
}
elem := make(map[string]interface{})
var subindex = 0
for _, value := range disks {
if value.DiskType == "D" {
elem["label"] = value.Label
elem["size"] = value.SizeMax
elem["disk_id"] = value.ID
elem["pool"] = "default"
elem["provider"] = "default"
result[subindex] = elem
subindex += 1
}
}
return result
}
/*
func makeDataDisksArgString(disks []DiskConfig) string {
// Prepare a string with the sizes of data disks for the virtual machine.
// It is designed to be passed as "datadisks" argument of virtual machine create API call.
if len(disks) < 1 {
return ""
}
return ""
}
*/
func diskSubresourceSchema() map[string]*schema.Schema {
rets := map[string]*schema.Schema {
"label": {
Type: schema.TypeString,
Required: true,
Description: "Unique label to identify this disk among other disks connected to this VM.",
},
"size": {
Type: schema.TypeInt,
Required: true,
ValidateFunc: validation.IntAtLeast(1),
Description: "Size of the disk in GB.",
},
"pool": {
Type: schema.TypeString,
Optional: true,
Default: "default",
Description: "Pool from which this disk should be provisioned.",
},
"provider": {
Type: schema.TypeString,
Optional: true,
Default: "default",
Description: "Storage provider (storage technology type) by which this disk should be served.",
},
"disk_id": {
Type: schema.TypeInt,
Computed: true,
Description: "ID of this disk resource.",
},
}
return rets
}