-
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.
Fixes: #77
- Loading branch information
Showing
12 changed files
with
310 additions
and
24 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
41 changes: 41 additions & 0 deletions
41
src/main/java/cloud/dnation/jenkins/plugins/hetzner/connect/BothV6.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,41 @@ | ||
/* | ||
* 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.connect; | ||
|
||
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 BothV6 extends AbstractConnectivity{ | ||
public ConnectivityType getType() { | ||
return ConnectivityType.BOTH_V6; | ||
} | ||
|
||
@Extension | ||
@Symbol("both-v6") | ||
public static final class DescriptorImpl extends Descriptor<AbstractConnectivity> { | ||
@NonNull | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.connectivity_bothV6(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,5 +18,7 @@ | |
public enum ConnectivityType { | ||
PRIVATE, | ||
PUBLIC, | ||
BOTH | ||
PUBLIC_V6, | ||
BOTH, | ||
BOTH_V6 | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/cloud/dnation/jenkins/plugins/hetzner/connect/PublicV6Only.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,41 @@ | ||
/* | ||
* 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.connect; | ||
|
||
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 PublicV6Only extends AbstractConnectivity { | ||
public ConnectivityType getType() { | ||
return ConnectivityType.PUBLIC_V6; | ||
} | ||
|
||
@Extension | ||
@Symbol("publicV6-only") | ||
public static final class DescriptorImpl extends Descriptor<AbstractConnectivity> { | ||
@NonNull | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.connectivity_publicV6_only(); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/cloud/dnation/jenkins/plugins/hetzner/launcher/PublicV6AddressOnly.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,48 @@ | ||
/* | ||
* 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 com.google.common.base.Strings; | ||
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 PublicV6AddressOnly extends AbstractConnectionMethod { | ||
@Override | ||
public String getAddress(ServerDetail server) { | ||
if (server.getPublicNet().getIpv6() == null || Strings.isNullOrEmpty(server.getPublicNet().getIpv6().getIp())) { | ||
throw new IllegalArgumentException("Connection method requires IPv6 address"); | ||
} | ||
// value returned by API ends with "::/64" so replace it with "1" | ||
return server.getPublicNet().getIpv6().getIp().replaceFirst("::/64$", "::1"); | ||
} | ||
|
||
@Extension | ||
@Symbol("publicV6") | ||
public static final class DescriptorImpl extends Descriptor<AbstractConnectionMethod> { | ||
@NonNull | ||
@Override | ||
public String getDisplayName() { | ||
return Messages.connection_method_publicV6(); | ||
} | ||
} | ||
} |
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
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
62 changes: 62 additions & 0 deletions
62
src/test/java/cloud/dnation/jenkins/plugins/hetzner/HetznerCloudResourceManagerTest.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,62 @@ | ||
/* | ||
* 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; | ||
|
||
import cloud.dnation.hetznerclient.CreateServerRequest; | ||
import cloud.dnation.jenkins.plugins.hetzner.connect.ConnectivityType; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static cloud.dnation.jenkins.plugins.hetzner.HetznerCloudResourceManager.customizeNetworking; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class HetznerCloudResourceManagerTest { | ||
@Test | ||
public void testCustomizeNetworking() throws IOException { | ||
CreateServerRequest req; | ||
|
||
req = new CreateServerRequest(); | ||
customizeNetworking(ConnectivityType.BOTH, req, "", (s1, s2) -> { | ||
}); | ||
assertEquals(true, req.getPublicNet().getEnableIpv4()); | ||
assertEquals(true, req.getPublicNet().getEnableIpv6()); | ||
|
||
req = new CreateServerRequest(); | ||
customizeNetworking(ConnectivityType.BOTH_V6, req, "", (s1, s2) -> { | ||
}); | ||
assertEquals(false, req.getPublicNet().getEnableIpv4()); | ||
assertEquals(true, req.getPublicNet().getEnableIpv6()); | ||
|
||
req = new CreateServerRequest(); | ||
customizeNetworking(ConnectivityType.PUBLIC, req, "", (s1, s2) -> { | ||
}); | ||
assertEquals(true, req.getPublicNet().getEnableIpv4()); | ||
assertEquals(true, req.getPublicNet().getEnableIpv6()); | ||
|
||
req = new CreateServerRequest(); | ||
customizeNetworking(ConnectivityType.PUBLIC_V6, req, "", (s1, s2) -> { | ||
}); | ||
assertEquals(false, req.getPublicNet().getEnableIpv4()); | ||
assertEquals(true, req.getPublicNet().getEnableIpv6()); | ||
|
||
req = new CreateServerRequest(); | ||
customizeNetworking(ConnectivityType.PRIVATE, req, "", (s1, s2) -> { | ||
}); | ||
assertEquals(false, req.getPublicNet().getEnableIpv4()); | ||
assertEquals(false, req.getPublicNet().getEnableIpv6()); | ||
} | ||
} |
Oops, something went wrong.