diff --git a/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/DefaultV6ConnectionMethod.java b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/DefaultV6ConnectionMethod.java new file mode 100644 index 0000000..44f50a7 --- /dev/null +++ b/src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/DefaultV6ConnectionMethod.java @@ -0,0 +1,47 @@ +/* + * Copyright 2024 https://dnation.cloud + * + * 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 cloud.dnation.jenkins.plugins.hetzner.launcher; + +import cloud.dnation.hetznerclient.ServerDetail; +import cloud.dnation.jenkins.plugins.hetzner.Messages; +import edu.umd.cs.findbugs.annotations.NonNull; +import hudson.Extension; +import hudson.model.Descriptor; +import lombok.NoArgsConstructor; +import org.jenkinsci.Symbol; +import org.kohsuke.stapler.DataBoundConstructor; + +@NoArgsConstructor(onConstructor = @__({@DataBoundConstructor})) +public class DefaultV6ConnectionMethod extends AbstractConnectionMethod { + @Override + public String getAddress(ServerDetail server) { + if (server.getPrivateNet() != null && !server.getPrivateNet().isEmpty()) { + return server.getPrivateNet().get(0).getIp(); + } else { + return server.getPublicNet().getIpv6().getIp(); + } + } + + @Extension + @Symbol("defaultV6") + public static final class DescriptorImpl extends Descriptor { + @NonNull + @Override + public String getDisplayName() { + return Messages.connection_method_defaultV6(); + } + } +} diff --git a/src/main/resources/cloud/dnation/jenkins/plugins/hetzner/Messages.properties b/src/main/resources/cloud/dnation/jenkins/plugins/hetzner/Messages.properties index dc2d05d..1cb74d4 100644 --- a/src/main/resources/cloud/dnation/jenkins/plugins/hetzner/Messages.properties +++ b/src/main/resources/cloud/dnation/jenkins/plugins/hetzner/Messages.properties @@ -25,6 +25,7 @@ primaryip.default=Use default behavior primaryip.bylabelselector.failing=Allocate primary IPv4 using label selector, fail if none is available primaryip.bylabelselector.ignoring=Allocate primary IPv4 using label selector, ignore any error connection.method.default=Connect using private IPv4 address if available, otherwise using public IPv4 address +connection.method.defaultV6=Connect using private IPv4 address if available, otherwise using public IPv6 address connection.method.public=Connect using public IPv4 address only connection.method.publicV6=Connect using public IPv6 address only connectivity.private-only=Only private networking will be used. Network ID or label expression must be provided as well.