Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ltamaster committed Dec 15, 2017
0 parents commit 91c6686
Show file tree
Hide file tree
Showing 40 changed files with 4,140 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.iws
*.ipr
*.iml
build
out
.gradle
/.idea
206 changes: 206 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
## Rundeck Azure Plugin
Azure Plugin integrates Rundeck with Azure Virtual Machines and Azure Storage. The plugin contains a Resource Model plugin, an Execution Log Storage plugin, and others plugin steps like Create/Start/Stop Azure VMs.


## Install

Build with `./gradlew build` and copy the `build/lib/azure-plugin-X.X.X.jar` to `$RDECK_BASE/libext` folder


## Resource Model Plugin

The resource model plugin provides the Azure VMs as nodes on a Rundeck Server.

### Credentials Settings
Settings related to the Azure connection

* **Client ID**: Azure Client ID.
* **Tenant ID**: Azure Tenant ID.
* **Subscription ID**: Azure Subscription ID.
* **Azure Access Key**: Azure Access Key.
* **Certificate Path**: (Optional) Azure certificate file path (if the access key is not defined).
* **Certificate Password**: (Optional) Azure certificate Password (if the access key is not defined).


### Other Settings:
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.

### Mapping

Map the Azure VM properties to Rundeck Node definition

#### Default Mapping
```
nodename.selector = name
hostname.selector = hostname
description.selector = short_description
osName.selector = osName
osVersion.selector = osVersion
osFamily.selector = osFamily
username.selector = username
region.selector = azure_region
resourceGroup.selector = azure_resourceGroup
status.selector = azure_status
id.selector = azure_id
node-executor.selector = node_executor
file-copier.selector = file_copier
vmId.selector = azure_vmId
tags.selector = tags
image:type.selector = azure_image_type
image:offer.selector = azure_image_offer
image:sku.selector = azure_image_sku
image:version.selector = azure_image_version
osDisk:osType.selector = azure_osDisk_osType
osDisk:name.selector = azure_osDisk_name
osDisk:createOption.selector = azure_osDisk_createOption
osDisk:diskSizeGB.selector = azure_osDisk_diskSizeGB
plan:name.selector = azure_plan_name
plan:product.selector = azure_plan_product
plan:publisher.selector = azure_plan_publisher
size:name.selector = azure_size_name
size:numberOfCores.selector = azure_size_numberOfCores
size:memoryInMB.selector = azure_size_memoryInMB
size:maxDataDiskCount.selector = azure_size_maxDataDiskCount
size:azure_size_resourceDiskSizeInMB.selector = azure_size_azure_size_resourceDiskSizeInMB
provisioningState:code.selector = azure_provisioningState_code
provisioningState:displayStatus.selector = azure_provisioningState_displayStatus
provisioningState:message.selector = azure_provisioningState_message
provisioningState:time.selector = azure_provisioningState_time
```
### Adding Tags from Azure VM Tags

You can add Rundeck's node tags using Azure VM tags.

For example, create an Azure VM tags like:

* Rundeck-Tags=sometag1,sometag2

`sometag1` and `sometag2` will be added as tags on Rundeck nodes


### Adding custom tags from Azure VM files

You can add extra tags using the azure fields available (right column on the default mapping).

For example, adding extra tags based on the VM resource group and status:

```
tags.selector=azure_resourceGroup,azure_status;
```

### Adding custom attribute based on Azure VM Tags

Also, you can add extra nodes attributes using Azure VM tags.

For example, creating the following tags on the Azure VM, you can map those tags to a rundeck node attribute:

* Rundeck-node-executor=winrm-exe
* Rundeck-file-copier=winrm-filecopier
* Rundeck-winrm-password-storage-path=keys/node/windows.password

As you see, the Azure VM tags must start with **Rundeck-**

Then to map those tags to nodes attribute use:

```
node-executor.selector=node-executor;
file-copier.selector=node-executor;
winrm-password-storage-path.selector=winrm-password-storage-path
```



## Execution Log Storage

The Execution Log Storage plugin uses Azure Storage to store execution log files, for backup or for a cluster environment behavior.

### Enable the plugin

Enable the ExecutionFileStorage provider named azure-storage in your `rundeck-config.properties` file:

`rundeck.execution.logs.fileStoragePlugin=azure-storage`

### Configuration
To configure the Azure Storage Account credentials you can set these property values:

* **storageAccount**: Azure Storage Account
* **accessKey**: Azure Storage Access Key
* **path**: The path in the bucket to store a log file.

You can use these expansion variables:

* `${job.execid}` = execution ID
* `${job.project}` = project name
* `${job.id}` = job UUID (or blank).
* `${job.group}` = job group (or blank).
* `${job.name}` = job name (or blank)

You can define the configuration values in `framework.properties` by prefixing the property name with the stem: `framework.plugin.ExecutionFileStorage.azure-storage`. Or in a project's `project.properties` file with the stem `project.plugin.ExecutionFileStorage.azure-storage`.

For example:

```
#storage.storageAccount and storage.accessKey
framework.plugin.ExecutionFileStorage.azure-storage.storageAccount=<ACCOUNT-NAME>
framework.plugin.ExecutionFileStorage.azure-storage.accessKey=<ACCESS-KEY>
#path to store the logs
framework.plugin.ExecutionFileStorage.azure-storage.path=logs/${job.project}/${job.execid}.log
```


## Managing Azure VM

This plugin contains basic operation for Azure VMs like list, create, start and stop Azure VMs. All the following workflow steps needs an authentication account like the one explained on the Resource Model Plugin


### List Azure VM
List the Azure VM on a Resource Group and/or Region

### Create an Azure VM
Create a new Azure VM. For selecting the image that the VM will be based on, you have the following options:

* Select the image form a *Known List*
* Find an image selecting the attributes: Publisher, Offer, SKU, version (for example, take a look at the following docs: [https://docs.microsoft.com/en-us/azure/virtual-machines/windows/cli-ps-findimage](https://docs.microsoft.com/en-us/azure/virtual-machines/windows/cli-ps-findimage))
* Passing the Image URL

### Start an Azure VM

Start an Azure VM using the VM name and Resource Group

### Stop an Azure VM
Stop an Azure VM using the VM name and Resource Group


## Azure Storage Operations

This plugin contains basic operation for Azure Storage, like list the blob files located on a container (within an Azure Storage Account), and copy/remove blobs files from/to the Rundeck Server.

### List blobs of a container
List the blobs files of a container inside an Azure Account

### Copy blobs from Azure Container to Rundek Server (or vice-versa)
Copy files from the Rundeck Server to an Azure Storage Container or from an Azure Storage Container to the Rundeck server.

To define if the source or destination is the local server or Azure, you must define a URI pattern like:

* file://path/file for local files
* Azure://container/path/file for blob files on Azure

### Removing blobs for a container

Delete blob files located on an Azure Storage Account Container



8 changes: 8 additions & 0 deletions azure_api_call.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


curl -v -X POST -H "Content-Type: application/x-www-form-urlencoded" https://login.microsoftonline.com/f1f67c7a-cd5c-4c12-aa90-7346420eb48a/oauth2/token -d "grant_type=client_credentials&client_id=3fd69f2a-0099-4a2c-a132-15586a881fab&client_secret=m1ttXHzuy4LR8kkLsdrzGPkY7B7I5uz7IPI6OSBj6Bo=&resource=https://management.core.windows.net/"



curl -v -H "Authorization: Bearer $AZURE_TOKEN" https://management.azure.com/subscriptions/81d06019-11b8-4f01-9616-f79ee1648ffe/resourceGroups/rundecktest/providers/Microsoft.Compute/virtualmachines?api-version=2016-04-30-preview

93 changes: 93 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
plugins {
id 'pl.allegro.tech.build.axion-release' version '1.3.2'
}

group 'com.rundeck'
version '1.0-SNAPSHOT'


ext.rundeckPluginVersion = '1.2'
ext.pluginClassNames=
'com.rundeck.plugins.azure.plugin.AzureResourceModelSourceFactory,com.rundeck.plugins.azure.plugin.AzureFileStoragePlugin,com.rundeck.plugins.azure.plugin.AzureStorageCopyStepPlugin,com.rundeck.plugins.azure.plugin.AzureStorageListStepPlugin,com.rundeck.plugins.azure.plugin.AzureStorageDeleteStepPlugin,com.rundeck.plugins.azure.plugin.AzureVMCreatePlugin,com.rundeck.plugins.azure.plugin.AzureVmStartPlugin,com.rundeck.plugins.azure.plugin.AzureVmStopPlugin,com.rundeck.plugins.azure.plugin.AzureVmListPlugin'
ext.pluginName = 'Azure Rundeck Plugin'
ext.pluginDescription = 'Azure Rundeck Plugin'

apply plugin: 'groovy'
apply plugin: 'java'

sourceCompatibility = 1.8

scmVersion {
tag {
prefix = 'v'
versionSeparator = ''
def origDeserialize=deserialize
//apend .0 to satisfy semver if the tag version is only X.Y
deserialize = { config, position, tagName ->
def orig = origDeserialize(config, position, tagName)
if (orig.split('\\.').length < 3) {
orig += ".0"
}
orig
}
}
}
project.version = scmVersion.version

repositories {
mavenCentral()
mavenLocal()
}



configurations {
pluginLibs

compile {
extendsFrom pluginLibs
}
}

dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.rundeck', name: 'rundeck-core', version: '2.10.0'
pluginLibs group: 'com.microsoft.azure', name: 'azure', version: '1.3.0'
pluginLibs group: 'com.microsoft.azure', name: 'azure-storage', version: '6.1.0'
pluginLibs group: 'commons-net', name: 'commons-net', version: '3.5'
pluginLibs group: 'commons-io', name: 'commons-io', version: '2.5'

// https://mvnrepository.com/artifact/com.microsoft.azure/azure-keyvault-core
pluginLibs group: 'com.microsoft.azure', name: 'azure-keyvault-core', version: '1.0.0'


testCompile "org.codehaus.groovy:groovy-all:2.3.7"
testCompile "org.spockframework:spock-core:0.7-groovy-2.0"
testCompile "cglib:cglib-nodep:2.2.2"
testCompile 'org.objenesis:objenesis:1.4'

}

task copyToLib(type: Copy) {
into "$buildDir/output/lib"
from configurations.pluginLibs
}

jar {
from "$buildDir/output"
manifest {
def libList = configurations.pluginLibs.collect{'lib/' + it.name}.join(' ')
attributes 'Rundeck-Plugin-Classnames': pluginClassNames
attributes 'Rundeck-Plugin-File-Version': version
attributes 'Rundeck-Plugin-Version': rundeckPluginVersion
attributes 'Rundeck-Plugin-Archive': 'true'
attributes 'Rundeck-Plugin-Libs': "${libList}"
}
dependsOn(copyToLib)
}

task wrapper(type: Wrapper) {
gradleVersion = '3.3'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Fri Nov 03 11:32:16 CLST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Loading

0 comments on commit 91c6686

Please sign in to comment.