Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Commit

Permalink
(CLOUD-1525) new features for subnet vnet and community fixes (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregohardy authored and MWilsonPuppet committed Dec 13, 2017
1 parent 7ca9af1 commit 7dc5f0e
Show file tree
Hide file tree
Showing 41 changed files with 2,062 additions and 876 deletions.
13 changes: 12 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ Style/EmptyLiteral:
Metrics/LineLength:
Enabled: false

Style/MethodCallParentheses:
Style/MethodCallWithoutArgsParentheses:
Enabled: false

Style/MethodDefParentheses:
Expand Down Expand Up @@ -477,3 +477,14 @@ Style/TrailingCommaInArguments:
# hitting https://github.com/bbatsov/rubocop/issues/3283
Lint/ShadowedException:
Enabled: false

# disabled for the moment due to rubocop gem changes

Metrics/BlockLength:
Enabled: false

Style/SymbolArray:
Enabled: false

Style/MultilineIfModifier:
Enabled: false
44 changes: 22 additions & 22 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,50 @@ source ENV['GEM_SOURCE'] || "https://rubygems.org"

gem 'azure', '~> 0.7.0'

gem 'azure_mgmt_storage', '~> 0.11.0'
gem 'azure_mgmt_compute', '~> 0.11.0'
gem 'azure_mgmt_resources', '~> 0.11.0'
gem 'azure_mgmt_network', '~> 0.11.0'
gem 'azure_mgmt_compute', '~> 0.14.0'
gem 'azure_mgmt_network', '~> 0.14.0'
gem 'azure_mgmt_resources', '~> 0.14.0'
gem 'azure_mgmt_storage', '~> 0.14.0'

gem 'hocon'
gem 'retries'

group :test do
gem 'rake'
gem 'puppet', ENV['PUPPET_GEM_VERSION'] || '~> 4'
gem 'facter', '>= 2.0'
gem 'rspec-puppet', :git => 'https://github.com/rodjek/rspec-puppet.git'
gem 'puppetlabs_spec_helper'
gem 'metadata-json-lint'
gem 'puppet', ENV['PUPPET_GEM_VERSION'] || '~> 4'
gem 'puppetlabs_spec_helper'
# json_pure 2.0.2 added a requirement on ruby >= 2. We pin to json_pure 2.0.1
# if using ruby 1.x
gem 'json_pure', '<=2.0.1', :require => false if RUBY_VERSION =~ /^1\./
gem 'rubocop', '~> 0.41.0'
gem 'simplecov', '>= 0.11.0'
gem 'simplecov-console'
gem 'parallel_tests', '< 2.10.0' if RUBY_VERSION < '2.0.0'
gem 'parallel_tests' if RUBY_VERSION >= '2.0.0'
gem 'listen', '~> 3.0.0'
gem 'parallel_tests', '< 2.10.0' if RUBY_VERSION < '2.0.0'
gem 'public_suffix', '~> 1.4.0' #used for azure, 1.5.0 dropped ruby 1.9
gem 'rake'
gem 'rspec-puppet', :git => 'https://github.com/rodjek/rspec-puppet.git'
gem 'rubocop', '~> 0.49.0'
gem 'simplecov', '>= 0.11.0'
gem 'simplecov-console'
end

group :development do
gem 'pry-byebug'
gem 'guard-rake'
gem 'puppet-blacksmith'
# required by puppet-blacksmith
gem 'rest-client', '~> 1.8.0' # for ruby 1.9 compatibility
gem 'guard-rake'
gem 'pry-byebug'
gem 'pry-rescue'
gem 'pry-stack_explorer'
gem 'rest-client', '~> 1.8.0' # for ruby 1.9 compatibility

end

group :acceptance do
gem 'winrm', '~> 1.3'
gem 'mustache'
gem 'ssh-exec'
gem "beaker-puppet_install_helper", :require => false
gem "beaker-testmode_switcher"
gem 'beaker', ENV['BEAKER_VERSION'] || '~> 2.0'
gem 'master_manipulator', '~> 1.0'
gem 'beaker-puppet_install_helper', :require => false
gem 'beaker-rspec'
gem 'beaker-testmode_switcher'
gem 'master_manipulator', '~> 1.0'
gem 'mustache'
gem 'ssh-exec'
gem 'winrm', '~> 1.3'
end
101 changes: 97 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Microsoft Azure exposes a powerful API for creating and managing its Infrastruct

* Ruby Gems as follows (see [Installing the Azure module](#installing-the-azure-module), below).
* [azure](https://rubygems.org/gems/azure) 0.7.x
* [azure_mgmt_storage](https://rubygems.org/gems/azure_mgmt_storage) 0.3.x
* [azure_mgmt_compute](https://rubygems.org/gems/azure_mgmt_compute) 0.3.x
* [azure_mgmt_resources](https://rubygems.org/gems/azure_mgmt_resources) 0.3.x
* [azure_mgmt_storage](https://rubygems.org/gems/azure_mgmt_storage) 0.14.x
* [azure_mgmt_compute](https://rubygems.org/gems/azure_mgmt_compute) 0.14.x
* [azure_mgmt_resources](https://rubygems.org/gems/azure_mgmt_resources) 0.14.x
* [azure_mgmt_network](https://rubygems.org/gems/azure_mgmt_network) 0.14.x
* [hocon](https://rubygems.org/gems/hocon) 1.1.x
* Azure credentials (as detailed below).
Expand Down Expand Up @@ -673,7 +673,7 @@ The link to the underlying disk image for the virtual machine.

##### `ensure`

Specifies the basic state of the virtual machine.
Specifies the basic state of the virtual network.

Values: 'present', 'running', stopped', 'absent'.

Expand Down Expand Up @@ -1225,6 +1225,99 @@ The URI of a file containing the params in Azure Resource Model standard format.

The format of this file differs from the format accepted by the `params` attribute. Must not be specified when `params` is specified.


#### Type: azure_vnet

##### `ensure`

Specifies the basic state of the virtual network.

Values: present, absent.

Default: present.

##### `name`

**Required**.

The name of the vnet.

Values: A string no longer than 80 characters long, containing only alphanumeric characters, dash, underscore, opening parenthesis, closing parenthesis, and period. The name cannot end with a period.

##### `location`

**Required**.

The location where the vnet is created.

Values: See [Azure regions documentation](http://azure.microsoft.com/en-gb/regions/).

##### `resource_group`

**Required**.

The resource group with which to associate the vnet.

Values: See [Resource Groups](https://azure.microsoft.com/en-gb/documentation/articles/resource-group-overview/)..

##### `tags`
A hash of tags to label with.

Example:

```puppet
tags => {'department' => 'devops', 'foo' => 'bar'}
```

#### Type: azure_subnet

##### `ensure`

Specifies the basic state of the subnet.

Values: present, absent.

Default: present.

##### `name`

**Required**.

The name of the subnet.

Values: A string no longer than 80 characters long, containing only alphanumeric characters, dash, underscore, opening parenthesis, closing parenthesis, and period. The name cannot end with a period.

##### `location`

**Required**.

The location where the subnet is created.

Values: See [Azure regions documentation](http://azure.microsoft.com/en-gb/regions/).

##### `resource_group`

**Required**.

The resource group with which to associate the subnet.

Values: See [Resource Groups](https://azure.microsoft.com/en-gb/documentation/articles/resource-group-overview/)..

##### `virtual_network`

**Required**.

The virtual network with which to associate the subnet.

##### `tags`
A hash of tags to label with.

Example:

```puppet
tags => {'department' => 'devops', 'foo' => 'bar'}
```

## Known issues

For the azure module to work, all [azure gems](#installing-the-azure-module) must be installed successfully. There is a known issue where these gems fail to install if [nokogiri](http://www.nokogiri.org/tutorials/installing_nokogiri.html) failed to install.
Expand Down
86 changes: 86 additions & 0 deletions lib/puppet/provider/azure_network_security_group/arm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
require 'puppet_x/puppetlabs/azure/prefetch_error'
require 'puppet_x/puppetlabs/azure/provider_arm'

Puppet::Type.type(:azure_network_security_group).provide(:arm, :parent => PuppetX::Puppetlabs::Azure::ProviderArm) do
confine feature: :azure
confine feature: :azure_hocon
confine feature: :azure_retries

mk_resource_methods

read_only(:location, :resource_group, :etag, :default_security_rules, :security_rules, :network_interfaces, :subnets, :tags)

def self.instances
begin
PuppetX::Puppetlabs::Azure::ProviderArm.new.get_all_network_security_groups.collect do |nsg|
hash = nsg_to_hash(nsg)
Puppet.debug("Ignoring #{name} due to invalid or incomplete response from Azure") unless hash
new(hash) if hash
end.compact
rescue Timeout::Error, StandardError => e
raise PuppetX::Puppetlabs::Azure::PrefetchError.new(self.resource_type.name.to_s, e)
end
end

# Allow differing case
def self.prefetch(resources)
instances.each do |prov|
if resource = (resources.find { |k,v| k.casecmp(prov.name).zero? } || [])[1] # rubocop:disable Lint/AssignmentInCondition
resource.provider = prov
end
end
end

def self.nsg_to_hash(nsg)
{
ensure: :present,
id: nsg.id,
name: nsg.name,
resource_group: nsg.id.split('/')[4].downcase,
guid: nsg.resource_guid,
location: nsg.location,
default_security_rules: nsg.default_security_rules,
security_rules: nsg.security_rules,
network_interfaces: nsg.network_interfaces,
subnets: nsg.subnets,
tags: nsg.tags,
object: nsg,
}
end

def create
Puppet.info("Creating network security group #{resource[:name]}")
create_network_security_group(create_hash)
@property_hash[:ensure] = :present
end

def create_hash
{
name: resource[:name],
resource_group: resource[:resource_group],
location: resource[:location],
tags: resource[:tags],
}
end

def flush
if @property_hash[:ensure] != :absent
Puppet.info("Updating network security group #{resource[:name]}")
create_network_security_group(create_hash)
end
end

def dns_servers=(value)
Puppet.debug("Updating dns servers to be #{value.join(', ')} on network_security_group #{resource[:name]}")
@property_hash[:dns_servers] = value
end

def destroy
Puppet.info("Deleting network security group #{name}")
delete_network_security_group({
resource_group: resource[:resource_group],
name: resource[:name],
})
@property_hash[:ensure] = :absent
end
end
3 changes: 1 addition & 2 deletions lib/puppet/provider/azure_resource_template/arm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
def self.instances # rubocop:disable Metrics/AbcSize
begin
PuppetX::Puppetlabs::Azure::ProviderArm.new.get_all_deployments.collect do |dep|
iterator = dep.properties.parameters || {}
params = iterator.each_with_object({}) do |(k,v),memo|
params = dep.properties.parameters.each_with_object({}) do |(k,v),memo|
memo[k] = v['value']
end

Expand Down
19 changes: 15 additions & 4 deletions lib/puppet/provider/azure_storage_account/arm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

mk_resource_methods

read_only(:location, :resource_group, :account_kind, :account_type, :tags)
read_only(:location, :resource_group, :account_kind, :account_type, :sku_name, :sku_tier, :access_tier, :https_traffic_only, :tags)

def self.instances # rubocop:disable Metrics/AbcSize
begin
Expand All @@ -19,7 +19,11 @@ def self.instances # rubocop:disable Metrics/AbcSize
location: sa.location,
tags: sa.tags,
account_type: sa.sku.name,
sku_name: sa.sku.name,
sku_tier: sa.sku.tier,
account_kind: sa.kind,
access_tier: sa.access_tier,
https_traffic_only: sa.enable_https_traffic_only,
resource_group: sa.id.split('/')[4],
object: sa,
}
Expand All @@ -44,19 +48,26 @@ def create # rubocop:disable Metrics/AbcSize
# storage_account_type and storage_account_kind are enumerated and puppet
# will automatically convert them to symbols - we need them as strings or we
# will get an error during serialization
Puppet.info("Creating storage_account #{resource[:name]} in resource group #{resource[:resource_group]}")
create_storage_account({
storage_account: resource[:name],
name: resource[:name],
resource_group: resource[:resource_group],
storage_account_type: resource[:account_type].to_s,
sku_name: resource[:sku_name].to_s || :resource[:account_type].to_s,
storage_account_kind: resource[:account_kind].to_s,
access_tier: resource[:access_tier].to_s,
enable_https_traffic_only: resource[:https_traffic_only],
location: resource[:location],
tags: resource[:tags],
})
@property_hash[:ensure] = :present
end

def destroy
delete_storage_account(storage_account)
Puppet.info("Deleting storage_account #{resource[:name]} from resource group #{resource[:resource_group]}")
delete_storage_account({
name: resource[:name],
resource_group: resource[:resource_group],
})
@property_hash[:ensure] = :absent
end
end
Loading

0 comments on commit 7dc5f0e

Please sign in to comment.