-
Notifications
You must be signed in to change notification settings - Fork 7
/
AzureTemplateOptions.java
276 lines (243 loc) · 10.2 KB
/
AzureTemplateOptions.java
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.jclouds.azurecompute.arm.compute.options;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.List;
import org.jclouds.azurecompute.arm.domain.AvailabilitySet;
import org.jclouds.azurecompute.arm.domain.DataDisk;
import org.jclouds.azurecompute.arm.domain.OSProfile.WindowsConfiguration;
import org.jclouds.azurecompute.arm.domain.Secrets;
import org.jclouds.compute.options.TemplateOptions;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
/**
* Azure ARM custom options
*/
public class AzureTemplateOptions extends TemplateOptions implements Cloneable {
private AvailabilitySet availabilitySet;
private String availabilitySetName;
private List<DataDisk> dataDisks = ImmutableList.of();
private String resourceGroup;
private List<IpOptions> ipOptions = ImmutableList.of();
private WindowsConfiguration windowsConfiguration;
private List<Secrets> secrets = ImmutableList.of();
/**
* Sets the availability set where the nodes will be configured. If it does
* not exist jclouds will create a new one with the given configuration.
*/
public AzureTemplateOptions availabilitySet(AvailabilitySet availabilitySet) {
this.availabilitySet = availabilitySet;
return this;
}
/**
* Sets the availability set where the nodes will be configured. The
* availability set must exist.
*/
public AzureTemplateOptions availabilitySet(String availabilitySetName) {
this.availabilitySetName = availabilitySetName;
return this;
}
/**
* The resource group where the new resources will be created.
*/
public AzureTemplateOptions resourceGroup(String resourceGroup) {
this.resourceGroup = resourceGroup;
return this;
}
public AzureTemplateOptions dataDisks(Iterable<DataDisk> dataDisks) {
for (DataDisk dataDisk : checkNotNull(dataDisks, "dataDisks"))
checkNotNull(dataDisk, "all dataDisks must be non-empty");
this.dataDisks = ImmutableList.copyOf(dataDisks);
return this;
}
public AzureTemplateOptions dataDisks(DataDisk... dataDisks) {
return dataDisks(ImmutableList.copyOf(checkNotNull(dataDisks, "dataDisks")));
}
/**
* Configure the NICs that will be attached to the created nodes.
* <p>
* Note that the number of NICs that can be attached depends on the size of
* the virtual machine, and that the guest operating system needs to be
* prepared to set up all the configured interfaces.
* <p>
* Depending on the image being used, a cloud-init or bootstrap script might
* be needed to make the interface setup.
*/
public AzureTemplateOptions ipOptions(Iterable<IpOptions> ipOptions) {
for (IpOptions ipOption : checkNotNull(ipOptions, "ipOptions"))
checkNotNull(ipOption, "all ipOptions must be non-empty");
this.ipOptions = ImmutableList.copyOf(ipOptions);
return this;
}
/**
* @see {@link AzureTemplateOptions#ipOptions(Iterable)
*/
public AzureTemplateOptions ipOptions(IpOptions... ipOptions) {
return ipOptions(ImmutableList.copyOf(checkNotNull(ipOptions, "ipOptions")));
}
/**
* Windows configuration parameters
*
* @see <a href="https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#bk_windowsconfig5">docs</a>
*/
public AzureTemplateOptions windowsConfiguration(WindowsConfiguration windowsConfiguration) {
this.windowsConfiguration = windowsConfiguration;
return this;
}
/**
* Import certificates in the Windows Certificate Store
*
* @see <a href="https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/virtualmachines-create-or-update#bk_srcvault">docs</a>
*/
public AzureTemplateOptions secrets(Iterable<? extends Secrets> secrets) {
for (Secrets secret : checkNotNull(secrets, "secrets"))
checkNotNull(secret, "secrets can not be empty");
this.secrets = ImmutableList.copyOf(secrets);
return this;
}
public AvailabilitySet getAvailabilitySet() { return availabilitySet; }
public String getAvailabilitySetName() { return availabilitySetName; }
public List<DataDisk> getDataDisks() { return dataDisks; }
public String getResourceGroup() { return resourceGroup; }
public List<IpOptions> getIpOptions() { return ipOptions; }
public WindowsConfiguration getWindowsConfiguration() { return windowsConfiguration; }
public List<Secrets> getSecrets() { return secrets; }
@Override
public AzureTemplateOptions clone() {
AzureTemplateOptions options = new AzureTemplateOptions();
copyTo(options);
return options;
}
@Override
public void copyTo(TemplateOptions to) {
super.copyTo(to);
if (to instanceof AzureTemplateOptions) {
AzureTemplateOptions eTo = AzureTemplateOptions.class.cast(to);
eTo.availabilitySet(availabilitySet);
eTo.availabilitySet(availabilitySetName);
eTo.dataDisks(dataDisks);
eTo.resourceGroup(resourceGroup);
eTo.ipOptions(ipOptions);
eTo.windowsConfiguration(windowsConfiguration);
eTo.secrets(secrets);
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof AzureTemplateOptions)) return false;
if (!super.equals(o)) return false;
AzureTemplateOptions that = (AzureTemplateOptions) o;
return Objects.equal(availabilitySetName, that.availabilitySetName) &&
Objects.equal(resourceGroup, that.resourceGroup) &&
Objects.equal(availabilitySet, that.availabilitySet) &&
Objects.equal(dataDisks, that.dataDisks) &&
Objects.equal(ipOptions, that.ipOptions) &&
Objects.equal(windowsConfiguration, that.windowsConfiguration) &&
Objects.equal(secrets, that.secrets);
}
@Override
public int hashCode() {
return Objects.hashCode(availabilitySet, availabilitySetName, dataDisks,
resourceGroup, ipOptions);
}
@Override
public MoreObjects.ToStringHelper string() {
MoreObjects.ToStringHelper toString = super.string();
if (availabilitySet != null)
toString.add("availabilitySet", availabilitySet);
if (availabilitySetName != null)
toString.add("availabilitySetName", availabilitySetName);
if (!dataDisks.isEmpty())
toString.add("dataDisks", dataDisks);
if (resourceGroup != null)
toString.add("resourceGroup", resourceGroup);
if (!ipOptions.isEmpty())
toString.add("ipOptions", ipOptions);
if (windowsConfiguration != null)
toString.add("windowsConfiguration", windowsConfiguration);
if (!secrets.isEmpty())
toString.add("secrets", secrets);
return toString;
}
public static class Builder {
/**
* @see AzureTemplateOptions#availabilitySet(AvailabilitySet)
*/
public static AzureTemplateOptions availabilitySet(AvailabilitySet availabilitySet) {
AzureTemplateOptions options = new AzureTemplateOptions();
return options.availabilitySet(availabilitySet);
}
/**
* @see AzureTemplateOptions#availabilitySet(String)
*/
public static AzureTemplateOptions availabilitySet(String availabilitySetName) {
AzureTemplateOptions options = new AzureTemplateOptions();
return options.availabilitySet(availabilitySetName);
}
/**
* @see AzureTemplateOptions#dataDisks(DataDisk...)
*/
public static AzureTemplateOptions dataDisks(DataDisk... dataDisks) {
AzureTemplateOptions options = new AzureTemplateOptions();
return options.dataDisks(dataDisks);
}
/**
* @see AzureTemplateOptions#dataDisks(Iterable)
*/
public static AzureTemplateOptions dataDisks(Iterable<DataDisk> dataDisks) {
AzureTemplateOptions options = new AzureTemplateOptions();
return options.dataDisks(dataDisks);
}
/**
* @see AzureTemplateOptions#resourceGroup(String)
*/
public static AzureTemplateOptions resourceGroup(String resourceGroup) {
AzureTemplateOptions options = new AzureTemplateOptions();
return options.resourceGroup(resourceGroup);
}
/**
* @see AzureTemplateOptions#ipOptions(IpOptions...)
*/
public static AzureTemplateOptions ipOptions(IpOptions... ipOptions) {
AzureTemplateOptions options = new AzureTemplateOptions();
return options.ipOptions(ipOptions);
}
/**
* @see AzureTemplateOptions#ipOptions(Iterable)
*/
public static AzureTemplateOptions ipOptions(Iterable<IpOptions> ipOptions) {
AzureTemplateOptions options = new AzureTemplateOptions();
return options.ipOptions(ipOptions);
}
/**
* @see AzureTemplateOptions#windowsConfiguration(WindowsConfiguration)
*/
public static AzureTemplateOptions windowsConfiguration(WindowsConfiguration windowsConfiguration) {
AzureTemplateOptions options = new AzureTemplateOptions();
return options.windowsConfiguration(windowsConfiguration);
}
/**
* @see AzureTemplateOptions#secrets(List)
*/
public static AzureTemplateOptions secrets(Iterable<? extends Secrets> secrets) {
AzureTemplateOptions options = new AzureTemplateOptions();
return options.secrets(secrets);
}
}
}