-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow fallback to IPv6 if private network is not available
Related: #77 Signed-off-by: Richard Kosegi <richard.kosegi@gmail.com>
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/DefaultV6ConnectionMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<AbstractConnectionMethod> { | ||
@NonNull | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.connection_method_defaultV6(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters