/
profilesv3.go
187 lines (157 loc) · 8.08 KB
/
profilesv3.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
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
182
183
184
185
186
187
/*
(c) Copyright [2015] Hewlett Packard Enterprise Development LP
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 ov
import (
"fmt"
"github.com/HewlettPackard/oneview-golang/utils"
"github.com/docker/machine/libmachine/log"
)
type BootOptionV3 struct {
BootTargetLun string `json:"bootTargetLun,omitempty"` // "bootTargetLun": "0",
BootTargetName string `json:"bootTargetName,omitempty"` // "bootTargetName": "iqn.2015-02.com.hpe:iscsi.target",
BootVlanId int `json:"bootVlanId,omitempty"` //The virtual LAN ID of the boot connection.
BootVolumeSource string `json:"bootVolumeSource,omitempty"` // "bootVolumeSource": "",
ChapLevel string `json:"chapLevel,omitempty"` // "chapLevel": "None",
ChapName string `json:"chapName,omitempty"` // "chapName": "chap name",
ChapSecret string `json:"chapSecret,omitempty"` // "chapSecret": "super secret chap secret",
FirstBootTargetIp string `json:"firstBootTargetIp,omitempty"` // "firtBootTargetIp": "10.0.0.50",
FirstBootTargetPort string `json:"firstBootTargetPort,omitempty"` // "firstBootTargetPort": "8080",
InitiatorGateway string `json:"initiatorGateway,omitempty"` // "initiatorGateway": "3260",
InitiatorIp string `json:"initiatorIp,omitempty"` // "initiatorIp": "192.168.6.21",
InitiatorName string `json:"initiatorName,omitempty"` // "initiatorName": "iqn.2015-02.com.hpe:oneview-vcgs02t012",
InitiatorNameSource string `json:"initiatorNameSource,omitempty"` // "initiatorNameSource": "UserDefined"
InitiatorSubnetMask string `json:"initiatorSubnetMask,omitempty"` // "initiatorSubnetMask": "255.255.240.0",
InitiatorVlanId int `json:"initiatorVlanId,omitempty"` // "initiatorVlanId": 77,
MutualChapName string `json:"mutualChapName,omitempty"` // "mutualChapName": "name of mutual chap",
MutualChapSecret string `json:"mutualChapSecret,omitempty"` // "mutualChapSecret": "secret of mutual chap",
SecondBootTargetIp string `json:"secondBootTargetIp,omitempty"` // "secondBootTargetIp": "10.0.0.51",
SecondBootTargetPort string `json:"secondBootTargetPort,omitempty"` // "secondBootTargetPort": "78"
}
type ServerProfilev300 struct {
IscsiInitiatorName string `json:"iscsiInitiatorName,omitempty"` // "iscsiInitiatorName": "name of iscsi initiator name",
IscsiInitiatorNameType string `json:"iscsiInitiatorNameType,omitempty"` // "iscsiInitiatorNameType": "UserDefined",
OSDeploymentSettings *OSDeploymentSettings `json:"osDeploymentSettings,omitempty"` // "osDeploymentSettings": {...},
}
type OSDeploymentSettings struct {
ComplianceControl string `json:"complianceControl,omitempty"` // complianceControl
DeployMethod string `json:"deployMethod,omitempty"` //The deploy method option to be specified by the user
DeploymentMac string `json:"deploymentMac,omitempty"` //The MAC address that is currently programmed on the NIC to be used for deployment
DeploymentPortId string `json:"deploymentPortId,omitempty"` //The port/FlexNIC of an adapter to be specified for the OS deployment
ForceOsDeployment bool `json:"forceOsDeployment,omitempty"` //Identifies the custom attributes to be configured with the OS deployment plan.
OSCustomAttributes []OSCustomAttribute `json:"osCustomAttributes,omitempty"` // "osCustomAttributes": [],
OSDeploymentPlanUri utils.Nstring `json:"osDeploymentPlanUri,omitempty"` // "osDeploymentPlanUri": nil,
OSVolumeUri utils.Nstring `json:"osVolumeUri,omitempty"` // "osVolumeUri": nil,
ReapplyState string `json:"reapplyState,omitempty"` //Current reapply state of the OS Deployment Settings component
}
type OSCustomAttribute struct {
Constraints string `json:"constraints,omitempty"` //Constraints for the custom attribute.
Name string `json:"name,omitempty"` // "name": "custom attribute 1",
Type string `json:"type,omitempty"` //Identifies the type of the custom attribute.
Value string `json:"value,omitempty"` // "value": "custom attribute value"
}
// create profile from template
func (c *OVClient) CreateProfileFromTemplateWithI3S(name string, template ServerProfile, blade ServerHardware) error {
log.Debugf("TEMPLATE : %+v\n", template)
var (
new_template ServerProfile
err error
)
//GET on /rest/server-profile-templates/{id}new-profile
if c.IsProfileTemplates() {
log.Debugf("getting profile by URI %+v, v2", template.URI)
new_template, err = c.GetProfileByURI(template.URI)
if err != nil {
return err
}
new_template.Type = "ServerProfileV6"
new_template.ServerProfileTemplateURI = template.URI // create relationship
log.Debugf("new_template -> %+v", new_template)
} else {
return fmt.Errorf("Can't use v1 with image streamer.")
}
new_template.ServerHardwareURI = blade.URI
new_template.ServerHardwareTypeURI = blade.ServerHardwareTypeURI
new_template.Description += " " + name
new_template.Name = name
err = c.SubmitNewProfile(new_template)
return err
}
// CustomizeServer - use customizeserver when working with creating a new server
// server create if it's missing
// server apply deployment job
type CustomizeServer struct {
ProfileName string // name of server
OSDeploymentBuildPlan string // name of the OS build plan
OSDeploymentAttributes map[string]string // name value pairs for server custom attributes
EthernetNetworkName string // deployment network name
}
// CustomizeServer - Customize Server
func (c *OVClient) CustomizeServer(cs CustomizeServer) error {
s, err := c.GetProfileByName(cs.ProfileName)
if err != nil || s.URI.IsNil() {
return fmt.Errorf("Server not found\n %+v", err)
}
blade, err := c.GetServerHardwareByUri(s.ServerHardwareURI)
if err != nil {
return err
}
osDeploymentPlan, err := c.GetOSDeploymentPlanByName(cs.OSDeploymentBuildPlan)
if err != nil || osDeploymentPlan.URI.IsNil() {
return fmt.Errorf("osDeploymentPlan not found: %s\n %+v", cs.OSDeploymentBuildPlan, err)
}
serverDeploymentAttributes := make([]OSCustomAttribute, len(osDeploymentPlan.AdditionalParameters))
for i := 0; i < len(osDeploymentPlan.AdditionalParameters); i++ {
customAttribute := &osDeploymentPlan.AdditionalParameters[i]
if val, ok := cs.OSDeploymentAttributes[customAttribute.Name]; ok {
customAttribute.Value = val
}
serverDeploymentAttributes[i].Name = customAttribute.Name
serverDeploymentAttributes[i].Value = customAttribute.Value
}
s.OSDeploymentSettings.OSDeploymentPlanUri = osDeploymentPlan.URI
s.OSDeploymentSettings.OSCustomAttributes = serverDeploymentAttributes
s.ConnectionSettings.Connections, err = c.ManageI3SConnections(s.ConnectionSettings.Connections, cs.EthernetNetworkName)
if err != nil {
return err
}
err = c.UpdateServerProfile(s)
if err != nil {
return err
}
err = blade.PowerOn()
if err != nil {
return err
}
return nil
}
func (c *OVClient) DeleteOSBuildPlanFromServer(profileName string) error {
s, err := c.GetProfileByName(profileName)
if err != nil || s.URI.IsNil() {
return fmt.Errorf("Server not found\n %+v", err)
}
blade, err := c.GetServerHardwareByUri(s.ServerHardwareURI)
if err != nil {
return err
}
err = blade.PowerOff()
if err != nil {
return err
}
s.OSDeploymentSettings.OSDeploymentPlanUri = utils.NewNstring("")
//s.OSDeploymentSettings.OSCustomAttributes = nil
err = c.UpdateServerProfile(s)
if err != nil {
return err
}
return nil
}