20
20
import static com .google .jenkins .plugins .computeengine .ComputeEngineCloud .checkPermissions ;
21
21
22
22
import com .google .api .services .compute .model .AcceleratorConfig ;
23
- import com .google .api .services .compute .model .AccessConfig ;
24
23
import com .google .api .services .compute .model .AttachedDisk ;
25
24
import com .google .api .services .compute .model .AttachedDiskInitializeParams ;
26
25
import com .google .api .services .compute .model .DiskType ;
46
45
import edu .umd .cs .findbugs .annotations .Nullable ;
47
46
import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
48
47
import hudson .Extension ;
48
+ import hudson .ExtensionList ;
49
49
import hudson .RelativePath ;
50
50
import hudson .Util ;
51
51
import hudson .model .Describable ;
@@ -98,8 +98,6 @@ public class InstanceConfiguration implements Describable<InstanceConfiguration>
98
98
public static final String DEFAULT_RUN_AS_USER = "jenkins" ;
99
99
public static final String METADATA_LINUX_STARTUP_SCRIPT_KEY = "startup-script" ;
100
100
public static final String METADATA_WINDOWS_STARTUP_SCRIPT_KEY = "windows-startup-script-ps1" ;
101
- public static final String NAT_TYPE = "ONE_TO_ONE_NAT" ;
102
- public static final String NAT_NAME = "External NAT" ;
103
101
public static final List <String > KNOWN_IMAGE_PROJECTS = Collections .unmodifiableList (new ArrayList <String >() {
104
102
{
105
103
add ("centos-cloud" );
@@ -131,7 +129,11 @@ public class InstanceConfiguration implements Describable<InstanceConfiguration>
131
129
private String bootDiskSourceImageName ;
132
130
private String bootDiskSourceImageProject ;
133
131
private NetworkConfiguration networkConfiguration ;
132
+ private NetworkInterfaceIpStackMode networkInterfaceIpStackMode ;
133
+
134
+ @ Deprecated
134
135
private boolean externalAddress ;
136
+
135
137
private boolean useInternalAddress ;
136
138
private boolean ignoreProxy ;
137
139
private String networkTags ;
@@ -351,6 +353,7 @@ public ComputeEngineInstance provision() throws IOException {
351
353
/** Initializes transient properties */
352
354
protected Object readResolve () {
353
355
labelSet = Label .parse (labels );
356
+ this .networkInterfaceIpStackMode = new NetworkInterfaceSingleStack (externalAddress );
354
357
return this ;
355
358
}
356
359
@@ -521,18 +524,15 @@ && notNullOrEmpty(acceleratorConfiguration.getGpuType())) {
521
524
522
525
private List <NetworkInterface > networkInterfaces () {
523
526
List <NetworkInterface > networkInterfaces = new ArrayList <>();
524
- List <AccessConfig > accessConfigs = new ArrayList <>();
525
- if (externalAddress ) {
526
- accessConfigs .add (new AccessConfig ().setType (NAT_TYPE ).setName (NAT_NAME ));
527
- }
528
- NetworkInterface nic = new NetworkInterface ().setAccessConfigs (accessConfigs );
527
+
528
+ NetworkInterface networkInterface = networkInterfaceIpStackMode .getNetworkInterface ();
529
529
530
530
// Don't include subnetwork name if using default
531
531
if (!networkConfiguration .getSubnetwork ().equals ("default" )) {
532
- nic .setSubnetwork (stripSelfLinkPrefix (networkConfiguration .getSubnetwork ()));
532
+ networkInterface .setSubnetwork (stripSelfLinkPrefix (networkConfiguration .getSubnetwork ()));
533
533
}
534
534
535
- networkInterfaces .add (nic );
535
+ networkInterfaces .add (networkInterface );
536
536
return networkInterfaces ;
537
537
}
538
538
@@ -939,6 +939,10 @@ public FormValidation doCheckNumExecutorsStr(
939
939
}
940
940
return FormValidation .ok ();
941
941
}
942
+
943
+ public List <NetworkInterfaceIpStackMode .Descriptor > getNetworkInterfaceIpStackModeDescriptors () {
944
+ return ExtensionList .lookup (NetworkInterfaceIpStackMode .Descriptor .class );
945
+ }
942
946
}
943
947
944
948
public static class Builder {
@@ -962,7 +966,7 @@ public InstanceConfiguration build() {
962
966
instanceConfiguration .setBootDiskSourceImageName (this .bootDiskSourceImageName );
963
967
instanceConfiguration .setBootDiskSourceImageProject (this .bootDiskSourceImageProject );
964
968
instanceConfiguration .setNetworkConfiguration (this .networkConfiguration );
965
- instanceConfiguration .setExternalAddress (this .externalAddress );
969
+ instanceConfiguration .setNetworkInterfaceIpStackMode (this .networkInterfaceIpStackMode );
966
970
instanceConfiguration .setUseInternalAddress (this .useInternalAddress );
967
971
instanceConfiguration .setIgnoreProxy (this .ignoreProxy );
968
972
instanceConfiguration .setNetworkTags (this .networkTags );
0 commit comments