Skip to content

Commit

Permalink
Merge pull request #19 from rundeck-plugins/add-tags-resource-model
Browse files Browse the repository at this point in the history
add tags from azure VMs
  • Loading branch information
ltamaster authored Jan 11, 2021
2 parents 82bb44c + 0d2ccc7 commit dbd2d49
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 4 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Java CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get Fetch Tags
run: git -c protocol.version=2 fetch --tags --progress --no-recurse-submodules origin
if: "!contains(github.ref, 'refs/tags')"
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Get Release Version
id: get_version
run: VERSION=$(./gradlew currentVersion -q -Prelease.quiet) && echo ::set-output name=VERSION::$VERSION
- name: Upload azure plugin jar
uses: actions/[email protected]
with:
# Artifact name
name: Grails-Plugin-${{ steps.get_version.outputs.VERSION }}
# Directory containing files to upload
path: build/libs/azure-plugin-${{ steps.get_version.outputs.VERSION }}.jar
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- '*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Upload Release Asset

jobs:
build:
name: Upload Release Asset
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Gradle
run: ./gradlew build
- name: Get Release Version
id: get_version
run: VERSION=$(./gradlew currentVersion -q -Prelease.quiet) && echo ::set-output name=VERSION::$VERSION
- name: Create Release
id: create_release
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ steps.get_version.outputs.VERSION }}
draft: false
prerelease: false
- name: Upload Release Asset (jar)
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: build/libs/azure-plugin-${{ steps.get_version.outputs.VERSION }}.jar
asset_name: azure-plugin-${{ steps.get_version.outputs.VERSION }}.jar
asset_content_type: application/octet-stream
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class AzureManager {
Region region
boolean onlyRunningInstances
boolean debug
boolean useAzureTags

Azure azure

Expand Down Expand Up @@ -91,7 +92,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)
AzureNode azureNode = new AzureNode(virtualMachine,size, useAzureTags)

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

boolean debug

Expand Down Expand Up @@ -99,6 +100,15 @@ class AzureManagerBuilder {
return this
}

/**
* @param onlyRunningInstances Only Running instances
* @return this builder
*/
AzureManagerBuilder useAzureTags(boolean useAzureTags){
this.useAzureTags = useAzureTags
return this
}

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

return azure
}
Expand Down
15 changes: 13 additions & 2 deletions src/main/groovy/com/rundeck/plugins/azure/azure/AzureNode.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ class AzureNode {
String osName
String osVersion

HashMap azureAttributes
Map azureAttributes

VirtualMachineSize size

Map<String, String> azureTags


AzureNode(){

}

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

this.size = size
//basic attributes
Expand Down Expand Up @@ -72,6 +74,15 @@ class AzureNode {
azureAttributes."${name}"=value
}

if(useAzureTags){
azureTags = [:]
vm.tags().findAll {key, value ->
if(key != "Rundeck-Tags"){
azureTags.put(key, value)
}
}
}

azureAttributes.id = vm.id()
azureAttributes.vmId = vm.vmId()
azureAttributes.region = vm.region()?.name()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ class AzureNodeMapper {
}
}

if(node.getAzureTags()){
node.getAzureTags().forEach{key, value ->
tagSet.add(key +":"+value)
}
}

return tagSet
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class AzureResourceModelSource implements ResourceModelSource {
String tagName=configuration.getProperty(AzureResourceModelSourceFactory.TAG_NAME)
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 debug=Boolean.parseBoolean(configuration.getProperty(AzureResourceModelSourceFactory.DEBUG))

Expand All @@ -61,6 +62,7 @@ class AzureResourceModelSource implements ResourceModelSource {
.tagName(tagName)
.tagValue(tagValue)
.debug(debug)
.useAzureTags(useAzureTags)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class AzureResourceModelSourceFactory implements ResourceModelSourceFactory,Desc
public static final String TAG_NAME = "tagName"
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 DEBUG = "debugVm"

Expand Down Expand Up @@ -87,6 +88,9 @@ class AzureResourceModelSourceFactory implements ResourceModelSourceFactory,Desc
.property(PropertyUtil.bool(DEBUG, "Debug VM info",
"Get the VM data on rundeck's log",
false, "false", null,renderingOptionsConfig))
.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))
.build()

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AzureVmListPluginSpec extends Specification{
AzureNode test = new AzureNode()
test.name="test"
test.hostname="test"
test.azureAttributes=[]
test.azureAttributes=[:]

def vmList = [test]

Expand Down

0 comments on commit dbd2d49

Please sign in to comment.