Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to choose between public and private vm ip #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Mapping and filter settings
* **Mapping Params**: Custom mapping settings. Property mapping definitions. Specify multiple mappings in the form "attributeName.selector=selector" or "attributeName.default=value", separated by ";"
* **Resource Group**: Filter using resource group
* **Only Running Instances**: Filter for the "Running" instances. If false, all instances will be returned.
* **Use Private Ip**: If enabled, populate node hostname with private ip otherwise public ip is used.

### Mapping

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AzureManager {
boolean onlyRunningInstances
boolean debug
boolean useAzureTags
boolean usePrivateIp

Azure azure

Expand Down Expand Up @@ -92,7 +93,7 @@ class AzureManager {
VirtualMachineSize size = azure.virtualMachines().sizes().listByRegion(virtualMachine.region()).find{ size-> size.name().equals(virtualMachine.size().toString())}


AzureNode azureNode = new AzureNode(virtualMachine,size, useAzureTags)
AzureNode azureNode = new AzureNode(virtualMachine,size, useAzureTags, usePrivateIp)

if(debug){
println ("--------- VM Mapping result ---------------")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class AzureManagerBuilder {
boolean onlyRunningInstances
Region region
boolean useAzureTags
boolean usePrivateIp

boolean debug

Expand Down Expand Up @@ -109,6 +110,15 @@ class AzureManagerBuilder {
return this
}

/**
* @param usePrivateIp Use private ip
* @return this builder
*/
AzureManagerBuilder usePrivateIp(boolean usePrivateIp){
this.usePrivateIp = usePrivateIp
return this
}

/**
* @param region the region to filter machines
* @return this builder
Expand Down Expand Up @@ -161,6 +171,7 @@ class AzureManagerBuilder {
azure.setTagName(this.tagName)
azure.setTagValue(this.tagValue)
azure.setUseAzureTags(this.useAzureTags)
azure.setUsePrivatecIp(this.usePrivateIp)

return azure
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AzureNode {

}

AzureNode(VirtualMachine vm, VirtualMachineSize size, boolean useAzureTags) {
AzureNode(VirtualMachine vm, VirtualMachineSize size, boolean useAzureTags, boolean usePrivateIp) {

this.size = size
//basic attributes
Expand All @@ -38,7 +38,11 @@ class AzureNode {

this.username = vm.osProfile()?.adminUsername()

this.hostname = vm.getPrimaryPublicIPAddress()?.ipAddress()
if (usePrivateIp) {
this.hostname = vm.primaryNetworkInterface.primaryPrivateIP()
} else {
this.hostname = vm.getPrimaryPublicIPAddress()?.ipAddress()
}

if(this.hostname==null){
//the offline machines doesn't have a IP selected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class AzureResourceModelSource implements ResourceModelSource {
String tagValue=configuration.getProperty(AzureResourceModelSourceFactory.TAG_VALUE)
String extraMapping=configuration.getProperty(AzureResourceModelSourceFactory.EXTRA_MAPPING)
boolean useAzureTags=Boolean.parseBoolean(configuration.getProperty(AzureResourceModelSourceFactory.USE_AZURE_TAGS))
boolean usePrivateIp=Boolean.parseBoolean(configuration.getProperty(AzureResourceModelSourceFactory.USE_PRIVATE_IP))
String keyStoragePath=configuration.getProperty(AzureResourceModelSourceFactory.KEY_STORAGE_PATH)

if(keyStoragePath){
Expand Down Expand Up @@ -75,6 +76,7 @@ class AzureResourceModelSource implements ResourceModelSource {
.tagValue(tagValue)
.debug(debug)
.useAzureTags(useAzureTags)
.usePrivateIp(usePrivateIp)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AzureResourceModelSourceFactory implements ResourceModelSourceFactory,Desc
public static final String TAG_VALUE = "tagValue"
public static final String RUNNING_ONLY = "onlyRunningInstances"
public static final String USE_AZURE_TAGS = "useAzureTags"
public static final String USE_PRIVATE_IP = "usePrivateIp"

public static final String DEBUG = "debugVm"

Expand Down Expand Up @@ -99,6 +100,10 @@ class AzureResourceModelSourceFactory implements ResourceModelSourceFactory,Desc
.property(PropertyUtil.bool(USE_AZURE_TAGS, "Use Azure Tags",
"If this option is enabled, azure tags will be exporting as Rundeck node tags.",
false, "false", null,renderingOptionsConfig))
.property(PropertyUtil.bool(USE_PRIVATE_IP, "Use Private IP",
"If this option is enabled, hostname will be populated with private ip, " +
"otherwise public ip will be used.",
false, "false", null,renderingOptionsConfig))
.build()

@Override
Expand Down