├── .gitignore ├── CHANGELOG ├── LICENSE.txt ├── Modulefile ├── README.markdown ├── cli_tools.md ├── lib └── puppet │ ├── affinity_group.rb │ ├── application │ ├── azure_affinitygroup.rb │ ├── azure_cloudservice.rb │ ├── azure_queue.rb │ ├── azure_servicebus.rb │ ├── azure_sqldb.rb │ ├── azure_storage.rb │ ├── azure_vm.rb │ └── azure_vnet.rb │ ├── application_config.rb │ ├── azurepack │ ├── bootstrap.rb │ ├── installer.rb │ └── scripts │ │ └── puppet-agent-bootstrap.erb │ ├── cloud_service.rb │ ├── core │ ├── remote_connection.rb │ └── utility.rb │ ├── face │ ├── azure_affinitygroup.rb │ ├── azure_affinitygroup │ │ ├── create.rb │ │ ├── delete.rb │ │ ├── list.rb │ │ ├── update.rb │ │ └── views │ │ │ └── affinity_groups.erb │ ├── azure_cloudservice.rb │ ├── azure_cloudservice │ │ ├── create.rb │ │ ├── delete.rb │ │ ├── delete_deployment.rb │ │ ├── list.rb │ │ ├── upload_certificate.rb │ │ └── views │ │ │ └── cloud_services.erb │ ├── azure_queue.rb │ ├── azure_queue │ │ ├── create.rb │ │ └── create_message.rb │ ├── azure_servicebus.rb │ ├── azure_servicebus │ │ ├── create_queue.rb │ │ ├── create_topic.rb │ │ ├── delete_queue.rb │ │ ├── delete_topic.rb │ │ ├── list_queues.rb │ │ ├── list_topics.rb │ │ └── views │ │ │ ├── queues.erb │ │ │ └── topics.erb │ ├── azure_sqldb.rb │ ├── azure_sqldb │ │ ├── create.rb │ │ ├── create_firewall.rb │ │ ├── delete.rb │ │ ├── delete_firewall.rb │ │ ├── list.rb │ │ ├── list_firewall.rb │ │ ├── reset_password.rb │ │ └── views │ │ │ ├── server_firewalls.erb │ │ │ └── servers.erb │ ├── azure_storage.rb │ ├── azure_storage │ │ ├── create.rb │ │ ├── delete.rb │ │ ├── list.rb │ │ ├── update.rb │ │ └── views │ │ │ └── storage_accounts.erb │ ├── azure_vm.rb │ ├── azure_vm │ │ ├── add_disk.rb │ │ ├── add_role.rb │ │ ├── bootstrap.rb │ │ ├── create.rb │ │ ├── delete.rb │ │ ├── delete_endpoint.rb │ │ ├── images.rb │ │ ├── locations.rb │ │ ├── restart.rb │ │ ├── servers.rb │ │ ├── shutdown.rb │ │ ├── start.rb │ │ ├── update_endpoint.rb │ │ └── views │ │ │ ├── images.erb │ │ │ ├── locations.erb │ │ │ └── servers.erb │ ├── azure_vnet.rb │ └── azure_vnet │ │ ├── list.rb │ │ ├── set_virtual_network.rb │ │ ├── set_xml_schema.rb │ │ └── views │ │ └── virtual_networks.erb │ ├── option_validation.rb │ ├── service_bus.rb │ ├── sql_database.rb │ ├── storage_account.rb │ ├── virtual_machine.rb │ └── virtual_network.rb ├── manifest.md ├── manifests ├── bootstrap.pp ├── cloudservice.pp ├── db.pp ├── provisioner.pp ├── storage.pp ├── vm.pp └── vnet.pp └── spec ├── fixtures ├── certificate.pem ├── invalid_file.txt ├── management_certificate.pem ├── private_key.key └── vnet_schema.xml ├── spec_helper.rb ├── support └── credential_validation.rb └── unit └── puppet └── face ├── azure_affinitygroup ├── create_spec.rb ├── delete_spec.rb ├── list_spec.rb └── update_spec.rb ├── azure_cloudservice ├── create_spec.rb ├── delete_deployment_spec.rb ├── delete_spec.rb └── list_spec.rb ├── azure_queue └── create_spec.rb ├── azure_servicebus ├── create_queue_spec.rb ├── create_topic_spec.rb ├── delete_queue_spec.rb └── delete_topic_spec.rb ├── azure_sqldb ├── create_firewall_spec.rb ├── create_spec.rb ├── delete_firewall_spec.rb ├── delete_spec.rb ├── list_firewall_spec.rb ├── list_spec.rb └── reset_password_spec.rb ├── azure_storage ├── create_spec.rb ├── delete_spec.rb ├── list_spec.rb └── update_spec.rb ├── azure_vm ├── add_disk_spec.rb ├── add_role_spec.rb ├── bootstrap_spec.rb ├── create_spec.rb ├── delete_endpoint_spec.rb ├── delete_spec.rb ├── images_spec.rb ├── locations_spec.rb ├── restart_spec.rb ├── servers_spec.rb ├── shutdown_spec.rb ├── start_spec.rb └── update_endpoint_spec.rb └── azure_vnet ├── list_spec.rb ├── set_virtual_network_spec.rb └── set_xml_schema_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | tmp/ 2 | .DS_Store 3 | metadata.json 4 | pkg/ 5 | -------------------------------------------------------------------------------- /CHANGELOG: -------------------------------------------------------------------------------- 1 | Fri June 6 2014 MSOpenTech 1.2.3 2 | * Implemented azure_servicebus action. 3 | Fri May 30 2014 MSOpenTech 1.2.2 4 | * Text changes from 'Windows Azure' to 'Microsoft Azure' 5 | Fri May 16 2014 MSOpenTech 1.2.1 6 | * Text changes from windowsazure to microsoftazure 7 | * Added License text 8 | Fri May 2 2014 MSOpenTech 1.2.0 9 | * Implemented azure_cloudservice action to manage cloud services 10 | * Implemented azure_storage action to manage storage accounts. 11 | * Implemented add_disk action for virtual machine. 12 | * Implemented add_role action for virtual machine. 13 | Fri Dec 20 2013 MSOpenTech 1.1.1 14 | * updated example for puppet command 15 | * Updated reporting issues url in readme 16 | * updated readme for SQL database server 17 | * Implement bootstrapping of nodes without subscription_id and management_certificate 18 | Wed Dec 11 2013 MSOpenTech 1.1.0 19 | * added manifests 20 | * updated readme 21 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. 2 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in 3 | compliance with the License. You may obtain a copy of the License at 4 | http://www.apache.org/licenses/LICENSE-2.0 5 | Unless required by applicable law or agreed to in writing, software distributed under the License is 6 | distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 7 | See the License for the specific language governing permissions and limitations under the License. 8 | -------------------------------------------------------------------------------- /Modulefile: -------------------------------------------------------------------------------- 1 | name 'msopentech-microsoftazure' 2 | version '1.2.3' 3 | source 'https://github.com/MSOpenTech/azure-puppet.git' 4 | author 'msopentech' 5 | summary 'Microsoft Azure cloud provisioning module' 6 | description 'Microsoft Azure cloud provisioning module' 7 | project_page 'https://github.com/MSOpenTech/azure-puppet' 8 | -------------------------------------------------------------------------------- /lib/puppet/affinity_group.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/application_config' 7 | include Puppet::ApplicationConfig 8 | 9 | module Puppet::AffinityGroup 10 | class << self 11 | def views(name) 12 | File.join(File.dirname(__FILE__), 'face/azure_affinitygroup/views', name) 13 | end 14 | 15 | def add_create_options(action) 16 | add_default_options(action) 17 | add_affinity_group_name_option(action) 18 | add_location_option(action) 19 | add_description_option(action) 20 | add_label_option(action) 21 | end 22 | 23 | def add_delete_options(action) 24 | add_default_options(action) 25 | add_affinity_group_name_option(action) 26 | end 27 | 28 | def add_update_options(action) 29 | add_default_options(action) 30 | add_affinity_group_name_option(action) 31 | add_label_option(action) 32 | add_description_option(action) 33 | end 34 | 35 | def add_description_option(action) 36 | action.option '--description=' do 37 | summary 'Description of affinity group' 38 | description 'Description of affinity group.' 39 | end 40 | end 41 | 42 | def add_label_option(action) 43 | action.option '--label=' do 44 | summary 'Label of affinity group' 45 | description 'Label of affinity group.' 46 | required 47 | before_action do |act, args, options| 48 | fail ArgumentError, 'Label is required' if options[:label].empty? 49 | end 50 | end 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /lib/puppet/application/azure_affinitygroup.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/face' 7 | require 'puppet/application/face_base' 8 | 9 | class Puppet::Application::AzureAffinitygroup < Puppet::Application::FaceBase 10 | end 11 | -------------------------------------------------------------------------------- /lib/puppet/application/azure_cloudservice.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/application/face_base' 7 | 8 | class Puppet::Application::AzureCloudservice < Puppet::Application::FaceBase 9 | end 10 | -------------------------------------------------------------------------------- /lib/puppet/application/azure_queue.rb: -------------------------------------------------------------------------------- 1 | require 'puppet/application/face_base' 2 | 3 | class Puppet::Application::AzureQueue < Puppet::Application::FaceBase 4 | end 5 | -------------------------------------------------------------------------------- /lib/puppet/application/azure_servicebus.rb: -------------------------------------------------------------------------------- 1 | require 'puppet/application/face_base' 2 | 3 | class Puppet::Application::AzureServicebus < Puppet::Application::FaceBase 4 | end 5 | -------------------------------------------------------------------------------- /lib/puppet/application/azure_sqldb.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/application/face_base' 7 | 8 | class Puppet::Application::AzureSqldb < Puppet::Application::FaceBase 9 | end 10 | -------------------------------------------------------------------------------- /lib/puppet/application/azure_storage.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/application/face_base' 7 | 8 | class Puppet::Application::AzureStorage < Puppet::Application::FaceBase 9 | end 10 | -------------------------------------------------------------------------------- /lib/puppet/application/azure_vm.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/application/face_base' 7 | 8 | class Puppet::Application::AzureVm < Puppet::Application::FaceBase 9 | end 10 | -------------------------------------------------------------------------------- /lib/puppet/application/azure_vnet.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/application/face_base' 7 | 8 | class Puppet::Application::AzureVnet < Puppet::Application::FaceBase 9 | end 10 | -------------------------------------------------------------------------------- /lib/puppet/application_config.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/core/utility' 7 | include Puppet::Core::Utility 8 | 9 | module Puppet 10 | module ApplicationConfig 11 | def initialize_env_variable(options) 12 | ENV['azure_management_certificate'.upcase] = options[:management_certificate] 13 | ENV['azure_subscription_id'.upcase] = options[:azure_subscription_id] 14 | ENV['azure_management_endpoint'.upcase] = options[:management_endpoint] 15 | gem "azure", '=0.6.4' 16 | require 'azure' 17 | end 18 | 19 | def add_default_options(action) 20 | add_management_certificate_option(action) 21 | add_subscription_id_option(action) 22 | add_management_endpoint_option(action) 23 | end 24 | 25 | def add_management_certificate_option(action) 26 | action.option '--management-certificate=' do 27 | summary 'The subscription identifier for the Microsoft Azure portal.' 28 | description 'The subscription identifier for the Microsoft Azure portal.' 29 | required 30 | before_action do |act, args, options| 31 | file = options[:management_certificate] 32 | validate_file(file, 'Management certificate', %w(pem pfx)) 33 | end 34 | end 35 | end 36 | 37 | def add_subscription_id_option(action) 38 | action.option '--azure-subscription-id=' do 39 | summary 'The subscription identifier for the Microsoft Azure portal.' 40 | description 'The subscription identifier for the Microsoft Azure portal.' 41 | required 42 | before_action do |act, args, options| 43 | if options[:azure_subscription_id].empty? 44 | fail ArgumentError, 'Subscription id is required.' 45 | end 46 | end 47 | end 48 | end 49 | 50 | def add_management_endpoint_option(action) 51 | action.option '--management-endpoint=' do 52 | summary 'The management endpoint for the Microsoft Azure portal.' 53 | description 'The management endpoint for the Microsoft Azure portal.' 54 | 55 | end 56 | end 57 | 58 | def add_location_option(action, optional = false) 59 | action.option '--location=' do 60 | summary 'The location identifier for the Microsoft Azure portal.' 61 | description <<-EOT 62 | The location identifier for the Microsoft Azure portal. 63 | valid choices are ('West US', 'East US', 'Southeast Asia', 64 | 'North Europe', 'West Europe', 'East Asia' ...). 65 | EOT 66 | required unless optional 67 | before_action do |act, args, options| 68 | if options[:location].empty? 69 | fail ArgumentError, 'Location is required' 70 | end 71 | end 72 | end 73 | end 74 | 75 | def add_affinity_group_name_option(action, optional = false) 76 | action.option '--affinity-group-name=' do 77 | summary 'The affinity group name.' 78 | description 'The affinity group name.' 79 | required unless optional 80 | before_action do |act, args, options| 81 | if options[:affinity_group_name].empty? 82 | fail ArgumentError, 'Affinity group name is required' 83 | end 84 | end 85 | end 86 | end 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /lib/puppet/azurepack/installer.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'erb' 7 | 8 | module Puppet 9 | module AzurePack 10 | module Installer 11 | class << self 12 | def build_installer_template(name, options = {}) 13 | # binding is a kernel method 14 | ERB.new(File.read(find_template(name))).result(binding) 15 | end 16 | 17 | def lib_script_dir 18 | File.join(File.dirname(__FILE__), 'scripts') 19 | end 20 | 21 | def find_template(name) 22 | user_script = File.expand_path("../#{name}.erb", __FILE__) 23 | puts user_script 24 | return user_script if File.exists?(user_script) 25 | lib_script = File.join(lib_script_dir, "#{name}.erb") 26 | if File.exists?(lib_script) 27 | lib_script 28 | else 29 | fail "Could not find installation template for #{name}" 30 | end 31 | end 32 | end 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/puppet/azurepack/scripts/puppet-agent-bootstrap.erb: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -u 4 | #set -e 5 | 6 | function redhat_setup(){ 7 | # Setup the yum Puppet repository 8 | cat >/etc/yum.repos.d/puppet.repo <<'EOFYUMREPO' 9 | [puppetlabs] 10 | name = Puppetlbas 11 | baseurl = http://yum.puppetlabs.com/el/$releasever/products/$basearch/ 12 | gpgcheck = 1 13 | enabled = 1 14 | gpgkey = http://yum.puppetlabs.com/RPM-GPG-KEY-puppetlabs 15 | EOFYUMREPO 16 | 17 | # Install Puppet from yum.puppetlabs.com 18 | rpm -Uvh http://yum.puppetlabs.com/el/6/products/x86_64/puppetlabs-release-6-6.noarch.rpm 19 | yum install -y puppet 20 | } 21 | 22 | function suse_setup(){ 23 | zypper ar --refresh http://download.opensuse.org/repositories/home:/eclipseagent:/puppet/SLE_11/ repo-puppet 24 | zypper --non-interactive --gpg-auto-import-keys ref 25 | zypper install -y puppet 26 | } 27 | 28 | function ubuntu_setup() { 29 | 30 | apt-key adv --recv-key --keyserver pool.sks-keyservers.net 4BD6EC30 31 | apt-get update 32 | apt-get -y install lsb-release 33 | release=$(lsb_release -c | cut -f 2) 34 | 35 | # Setup the apt Puppet repository 36 | cat > /etc/apt/sources.list.d/puppetlabs.list </etc/puppet/puppet.conf <<'EOFPUPPETCONF' 57 | [main] 58 | logdir = /var/log/puppet 59 | rundir = /var/run/puppet 60 | vardir = /var/lib/puppet 61 | ssldir = $vardir/ssl 62 | pluginsync = true 63 | report = true 64 | runinterval = 120 65 | server = puppet 66 | environment = <%= options[:agent_environment] %> 67 | 68 | EOFPUPPETCONF 69 | 70 | if [ -f /etc/default/puppet ]; then 71 | cat > /etc/default/puppet < 90 | if ( echo "$host" | egrep -q "[a-zA-Z]" ); then 91 | IP=$(host "$host" | grep "has address" | head -1 | awk '{print $NF}') 92 | else 93 | IP="$host" 94 | fi 95 | echo "$IP puppet" >> /etc/hosts 96 | echo 'DNS or host is added in /etc/hosts' 97 | } 98 | 99 | function install_puppet_agent() { 100 | if [ -f /etc/redhat-release ]; then 101 | export breed='redhat' 102 | elif [ -f /etc/debian_version ]; then 103 | export breed='debian' 104 | elif [ -f /etc/SuSE-release ]; then 105 | export breed='suse' 106 | else 107 | echo "This distro is not supported." 108 | exit 1 109 | fi 110 | 111 | bootstrap_puppet 112 | configure_puppet 113 | update_hosts 114 | start_puppet 115 | echo "Puppet installation finished!" 116 | exit 0 117 | } 118 | 119 | install_puppet_agent -------------------------------------------------------------------------------- /lib/puppet/cloud_service.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/core/utility' 7 | require 'puppet/application_config' 8 | include Puppet::ApplicationConfig 9 | 10 | module Puppet::CloudService 11 | class << self 12 | def views(name) 13 | File.join(File.dirname(__FILE__), 'face/azure_cloudservice/views', name) 14 | end 15 | 16 | def add_create_options(action) 17 | add_default_options(action) 18 | add_affinity_group_name_option(action, true) 19 | add_location_option(action, true) 20 | add_cloud_service_name_option(action) 21 | add_description_option(action) 22 | add_label_option(action) 23 | end 24 | 25 | def add_delete_options(action) 26 | add_default_options(action) 27 | add_cloud_service_name_option(action) 28 | end 29 | 30 | def add_certificate_options(action) 31 | add_default_options(action) 32 | add_cloud_service_name_option(action) 33 | add_certificate_file_option(action) 34 | add_private_key_file_option(action) 35 | end 36 | 37 | def add_delete_deployment_options(action) 38 | add_default_options(action) 39 | add_cloud_service_name_option(action) 40 | end 41 | 42 | def add_description_option(action) 43 | action.option '--description=' do 44 | summary 'Description of cloud service' 45 | description 'Description of cloud service.' 46 | end 47 | end 48 | 49 | def add_label_option(action) 50 | action.option '--label=' do 51 | summary 'Label of cloud service' 52 | description 'Label of cloud service.' 53 | end 54 | end 55 | 56 | def add_cloud_service_name_option(action) 57 | action.option '--cloud-service-name=' do 58 | summary 'The name of the cloud service.' 59 | description 'The name of the cloud service.' 60 | required 61 | before_action do |act, args, options| 62 | if act.name == :create && options[:location].nil? && options[:affinity_group_name].nil? 63 | fail ArgumentError, 'affinity group name or location is required.' 64 | end 65 | if options[:cloud_service_name].empty? 66 | fail ArgumentError, 'Cloud service name is required.' 67 | end 68 | end 69 | end 70 | end 71 | 72 | def add_certificate_file_option(action) 73 | action.option '--certificate-file=' do 74 | summary 'Specify certificate file.' 75 | description 'Path of certificate file.' 76 | required 77 | before_action do |act, args, options| 78 | file_path = options[:certificate_file] 79 | unless test 'f', file_path 80 | fail ArgumentError, "Could not find file '#{file_path}'" 81 | end 82 | unless test 'r', file_path 83 | fail ArgumentError, "Could not read from file '#{file_path}'" 84 | end 85 | end 86 | end 87 | end 88 | 89 | def add_private_key_file_option(action) 90 | action.option '--private-key-file=' do 91 | summary 'Specify private key file.' 92 | description 'Path of private key file.' 93 | required 94 | before_action do |act, args, options| 95 | file_path = options[:private_key_file] 96 | unless test 'f', file_path 97 | fail ArgumentError, "Could not find file '#{file_path}'" 98 | end 99 | unless test 'r', file_path 100 | fail ArgumentError, "Could not read from file '#{file_path}'" 101 | end 102 | end 103 | end 104 | end 105 | end 106 | end 107 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_affinitygroup.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/affinity_group' 7 | 8 | Puppet::Face.define(:azure_affinitygroup, '1.0.0') do 9 | 10 | summary 'View and manage Window Azure affinity groups.' 11 | description <<-'EOT' 12 | This subcommand provides a command line interface to work with Microsoft Azure 13 | affinity groups. The goal of these actions are to easily create new or update 14 | affinity group. 15 | EOT 16 | 17 | end 18 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_affinitygroup/create.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_affinitygroup, '1.0.0' do 9 | action :create do 10 | 11 | summary 'Create affinity group.' 12 | 13 | description 'The create action create a affinity group.' 14 | 15 | Puppet::AffinityGroup.add_create_options(self) 16 | 17 | when_invoked do |options| 18 | Puppet::AffinityGroup.initialize_env_variable(options) 19 | affinity_group_service = Azure::BaseManagementService.new 20 | others = { description: options[:description] } 21 | begin 22 | affinity_group_service.create_affinity_group( 23 | options[:affinity_group_name], 24 | options[:location], 25 | options[:label], 26 | others 27 | ) 28 | rescue => e 29 | puts e.message 30 | end 31 | end 32 | 33 | examples <<-'EOT' 34 | $ puppet azure_affinitygroup create --label aglabel \ 35 | --azure-subscription-id YOUR-SUBSCRIPTION-ID --location 'West Us' \ 36 | --affinity-group-name agname --description 'Some Description' \ 37 | --management-certificate path-to-azure-certificate 38 | EOT 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_affinitygroup/delete.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_affinitygroup, '1.0.0' do 9 | action :delete do 10 | 11 | summary 'Delete affinity group.' 12 | 13 | description <<-'EOT' 14 | The delete action delete a affinity group. 15 | EOT 16 | 17 | Puppet::AffinityGroup.add_delete_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::AffinityGroup.initialize_env_variable(options) 21 | affinity_group_service = Azure::BaseManagementService.new 22 | begin 23 | affinity_group_service.delete_affinity_group( 24 | options[:affinity_group_name] 25 | ) 26 | rescue => e 27 | puts e.message 28 | end 29 | end 30 | 31 | examples <<-'EOT' 32 | $ puppet azure_affinitygroup delete --affinity-group-name ag-name \ 33 | --management-certificate path-to-azure-certificate \ 34 | --azure-subscription-id YOUR-SUBSCRIPTION-ID 35 | EOT 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_affinitygroup/list.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'tilt' 8 | 9 | Puppet::Face.define :azure_affinitygroup, '1.0.0' do 10 | action :list do 11 | 12 | summary 'List affinity groups.' 13 | arguments 'list' 14 | description <<-'EOT' 15 | The list action obtains a list of affinity groups and 16 | displays them on the console output. 17 | EOT 18 | 19 | Puppet::AffinityGroup.add_default_options(self) 20 | 21 | when_invoked do |options| 22 | Puppet::AffinityGroup.initialize_env_variable(options) 23 | affinity_group_service = Azure::BaseManagementService.new 24 | affinity_groups = affinity_group_service.list_affinity_groups 25 | template = Tilt.new(Puppet::AffinityGroup.views('affinity_groups.erb')) 26 | template.render(nil, affinity_groups: affinity_groups) 27 | end 28 | 29 | returns 'Array of affinity group objets.' 30 | 31 | examples <<-'EOT' 32 | $ puppet affinity_group list \ 33 | --management-certificate path-to-azure-certificate \ 34 | --azure-subscription-id YOUR-SUBSCRIPTION-ID \ 35 | --management-endpoint=https://management.core.windows.net 36 | 37 | Listing affinity groups 38 | 39 | Affinity Group: 1 40 | Name : integration-test-affinity-group 41 | Label : Label 42 | Locaton : East Asia 43 | Description : Description 44 | Capability : PersistentVMRole, HighMemory 45 | 46 | Affinity Group: 2 47 | Name : Test 48 | Label : this is update operation 49 | Locaton : West US 50 | Description : My Description 51 | Capability : PersistentVMRole, HighMemory 52 | 53 | EOT 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_affinitygroup/update.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_affinitygroup, '1.0.0' do 9 | action :update do 10 | 11 | summary 'Update affinity group.' 12 | 13 | description <<-'EOT' 14 | The update action updates a affinity group. 15 | EOT 16 | 17 | Puppet::AffinityGroup.add_update_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::AffinityGroup.initialize_env_variable(options) 21 | affinity_group_service = Azure::BaseManagementService.new 22 | others = { description: options[:description] } 23 | begin 24 | affinity_group_service.update_affinity_group( 25 | options[:affinity_group_name], 26 | options[:label], 27 | others 28 | ) 29 | rescue => e 30 | puts e.message 31 | end 32 | end 33 | 34 | examples <<-'EOT' 35 | $ puppet azure_affinitygroup update --description 'Some Description' 36 | --management-certificate path-to-azure-certificate \ 37 | --azure-subscription-id YOUR-SUBSCRIPTION-ID --label aglabel \ 38 | --affinity-group-name agname 39 | EOT 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_affinitygroup/views/affinity_groups.erb: -------------------------------------------------------------------------------- 1 | <%="Listing affinity groups".bold%> 2 | <%index=1%> 3 | 4 | <%affinity_groups.each do |ag|%> 5 | <%="Affinity Group: #{index}".bold%> 6 | <%="Name".fix(20)%>: <%=ag.name %> 7 | <%="Label".fix(20)%>: <%=ag.label%> 8 | <%="Locaton".fix(20)%>: <%=ag.location%> 9 | <%="Description".fix(20)%>: <%=ag.description%> 10 | <%="Capability".fix(20)%>: <%=ag.capability.join(", ")%><%index+=1%> 11 | <%end%> -------------------------------------------------------------------------------- /lib/puppet/face/azure_cloudservice.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/cloud_service' 7 | 8 | Puppet::Face.define(:azure_cloudservice, '1.0.0') do 9 | 10 | summary 'View and manage Window Azure cloud service.' 11 | description <<-'EOT' 12 | This subcommand provides a command line interface to work with Microsoft Azure 13 | cloud services. The goal of these actions are to easily manage cloud service. 14 | EOT 15 | 16 | end 17 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_cloudservice/create.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_cloudservice, '1.0.0' do 9 | action :create do 10 | 11 | summary 'Create cloud service.' 12 | 13 | description 'The create action create a cloud service.' 14 | 15 | Puppet::CloudService.add_create_options(self) 16 | 17 | when_invoked do |options| 18 | Puppet::CloudService.initialize_env_variable(options) 19 | cloud_service = Azure::CloudServiceManagementService.new 20 | others = { 21 | description: options[:description], 22 | label: options[:label], 23 | affinity_group_name: options[:affinity_group_name], 24 | location: options[:location], 25 | extended_properties: options[:extended_properties] 26 | } 27 | 28 | cloud_service.create_cloud_service( 29 | options[:cloud_service_name], 30 | others 31 | ) 32 | nil 33 | end 34 | 35 | examples <<-'EOT' 36 | $ puppet azure_cloudservice create --label aglabel \ 37 | --azure-subscription-id YOUR-SUBSCRIPTION-ID --location 'West Us' \ 38 | --affinity-group-name agname --description 'Some Description' \ 39 | --management-certificate path-to-azure-certificate \ 40 | --cloud-service-name cloudservice1 41 | EOT 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_cloudservice/delete.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_cloudservice, '1.0.0' do 9 | action :delete do 10 | 11 | summary 'Delete cloud service.' 12 | 13 | description 'The delete action delete a cloud service.' 14 | 15 | Puppet::CloudService.add_delete_options(self) 16 | 17 | when_invoked do |options| 18 | Puppet::CloudService.initialize_env_variable(options) 19 | cloud_service = Azure::CloudServiceManagementService.new 20 | begin 21 | cloud_service.delete_cloud_service(options[:cloud_service_name]) 22 | rescue 23 | end 24 | nil 25 | end 26 | 27 | examples <<-'EOT' 28 | $ puppet azure_cloudservice delete --cloud-service-name cloudservice1 \ 29 | --azure-subscription-id YOUR-SUBSCRIPTION-ID \ 30 | --management-certificate path-to-azure-certificate 31 | EOT 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_cloudservice/delete_deployment.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_cloudservice, '1.0.0' do 9 | action :delete_deployment do 10 | 11 | summary 'deletes the specified deployment of hosted service.' 12 | description <<-'EOT' 13 | The delete_deployment action deletes the specified deployment of a 14 | hosted service. 15 | EOT 16 | 17 | Puppet::CloudService.add_delete_deployment_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::CloudService.initialize_env_variable(options) 21 | cloud_service = Azure::CloudServiceManagementService.new 22 | csn = options[:cloud_service_name] 23 | cloud_service.delete_cloud_service_deployment(csn) rescue nil 24 | nil 25 | end 26 | 27 | examples <<-'EOT' 28 | $ puppet azure_cloudservice upload_certificate \ 29 | --cloud-service-name cloudservice1 \ 30 | --azure-subscription-id YOUR-SUBSCRIPTION-ID \ 31 | --management-certificate path-to-azure-certificate 32 | EOT 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_cloudservice/list.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'tilt' 8 | 9 | Puppet::Face.define :azure_cloudservice, '1.0.0' do 10 | action :list do 11 | 12 | summary 'List cloud services.' 13 | 14 | description <<-'EOT' 15 | The list action obtains a list of cloud services and 16 | displays them on the console output. 17 | EOT 18 | 19 | Puppet::CloudService.add_default_options(self) 20 | 21 | when_invoked do |options| 22 | Puppet::CloudService.initialize_env_variable(options) 23 | cloud_service = Azure::CloudServiceManagementService.new 24 | 25 | cloud_services = cloud_service.list_cloud_services 26 | template = Tilt.new(Puppet::CloudService.views('cloud_services.erb')) 27 | template.render(nil, cloud_services: cloud_services) 28 | end 29 | 30 | returns 'Array of cloud service objets.' 31 | 32 | examples <<-'EOT' 33 | $ puppet azure_cloudservice list \ 34 | --management-certificate path-to-azure-certificate \ 35 | --azure-subscription-id=YOUR-SUBSCRIPTION-ID 36 | 37 | Listing cloud services 38 | Cloud Service: 1 39 | Name : azure-puppet 40 | Locaton : West US 41 | Status : Created 42 | Winrm Thumbprint : 43 | Cloud Service: 2 44 | Name : puppet-dashboard-service-oiurf 45 | Locaton : West US 46 | Status : Created 47 | Winrm Thumbprint : 48 | Cloud Service: 3 49 | Name : puppet-master 50 | Locaton : West US 51 | Status : Created 52 | Winrm Thumbprint : 53 | EOT 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_cloudservice/upload_certificate.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_cloudservice, '1.0.0' do 9 | action :upload_certificate do 10 | 11 | summary 'adds a certificate to a hosted service.' 12 | 13 | description <<-'EOT' 14 | The upload_certificate action adds a certificate to a hosted service. 15 | EOT 16 | 17 | Puppet::CloudService.add_certificate_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::CloudService.initialize_env_variable(options) 21 | cloud_service = Azure::CloudServiceManagementService.new 22 | certificate = {} 23 | cert_file = File.read(options[:certificate_file]) 24 | key_file = File.read(options[:private_key_file]) 25 | csn = options[:cloud_service_name] 26 | certificate[:key] = OpenSSL::PKey.read key_file 27 | certificate[:cert] = OpenSSL::X509::Certificate.new cert_file 28 | cloud_service.upload_certificate(csn, certificate) 29 | nil 30 | end 31 | 32 | examples <<-'EOT' 33 | $ puppet azure_cloudservice upload_certificate \ 34 | --cloud-service-name cloudservice1 --certificate-file cert_file_path \ 35 | --azure-subscription-id YOUR-SUBSCRIPTION-ID \ 36 | --management-certificate path-to-azure-certificate \ 37 | --private-key-file private_key_file_path 38 | EOT 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_cloudservice/views/cloud_services.erb: -------------------------------------------------------------------------------- 1 | <%="Listing cloud services".bold%> 2 | <%index=1%> 3 | 4 | <%cloud_services.each do |cs|%> 5 | <%="Cloud Service: #{index}".bold%> 6 | <%="Name".fix(20)%>: <%=cs.name %> 7 | <%="Locaton".fix(20)%>: <%=cs.location%> 8 | <%="Status".fix(20)%>: <%=cs.status%> 9 | <%="Extended Properties".fix(20)%>: <%=cs.extended_properties%> 10 | <%="Winrm Thumbprint".fix(20)%>: <%=cs.default_winrm_certificate_thumbprint%><%index+=1%> 11 | <%end%> -------------------------------------------------------------------------------- /lib/puppet/face/azure_queue.rb: -------------------------------------------------------------------------------- 1 | require 'puppet/service_bus' 2 | 3 | Puppet::Face.define(:azure_queue, '1.0.0') do 4 | 5 | summary 'View and manage Window Azure database servers.' 6 | description <<-'EOT' 7 | This subcommand provides a command line interface to work with Windows Azure 8 | machine instances. The goal of these actions are to easily create new 9 | database servers. 10 | EOT 11 | 12 | end 13 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_queue/create.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | Puppet::Face.define :azure_queue, '1.0.0' do 8 | action :create do 9 | 10 | summary 'Creates a queue with a valid name.' 11 | arguments 'list' 12 | description <<-'EOT' 13 | The create action creates a queue under the given account. 14 | EOT 15 | 16 | Puppet::ServiceBus.add_create_queue_options(self) 17 | 18 | when_invoked do |options| 19 | Puppet::ServiceBus.initialize_env_variable(options) 20 | azure_queue_service = Azure::QueueService.new 21 | azure_queue_service.create_queue(options[:queue_name]) 22 | end 23 | 24 | returns 'NONE' 25 | 26 | examples <<-'EOT' 27 | $ puppet azure_queue create --storage-account-name mystorageacc \ 28 | --storage-access-key 'hLlPCq751UBzcfn9AR3YWHXJu4m+A==' 29 | --queue-name queuename 30 | EOT 31 | 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_queue/create_message.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | Puppet::Face.define :azure_queue, '1.0.0' do 8 | action :create_message do 9 | 10 | summary 'Creates a message in the specified queue.' 11 | arguments 'list' 12 | description <<-'EOT' 13 | Creates a message in the specified queue. 14 | EOT 15 | 16 | Puppet::ServiceBus.add_create_message_options(self) 17 | when_invoked do |options| 18 | Puppet::ServiceBus.initialize_env_variable(options) 19 | azure_queue_service = Azure::QueueService.new 20 | azure_queue_service.create_queue(options[:queue_name]) 21 | azure_queue_service.create_message(options[:queue_name], options[:queue_message]) 22 | end 23 | 24 | returns 'NONE' 25 | 26 | examples <<-'EOT' 27 | $ puppet azure_queue create_message --storage-account-name mystorageacc \ 28 | --storage-access-key 'hLlPCq751UBzcfn9AR3YWHXJu4m+A==' 29 | --queue-name queuename --queue-message 'Text Message' 30 | 31 | EOT 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_servicebus.rb: -------------------------------------------------------------------------------- 1 | require 'puppet/service_bus' 2 | 3 | Puppet::Face.define(:azure_servicebus, '1.0.0') do 4 | 5 | summary 'View and manage Window Azure database servers.' 6 | description <<-'EOT' 7 | This subcommand provides a command line interface to work with Windows Azure 8 | machine instances. The goal of these actions are to easily create new 9 | database servers. 10 | EOT 11 | 12 | end 13 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_servicebus/create_queue.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_servicebus, '1.0.0' do 9 | action :create_queue do 10 | 11 | summary 'Creates queue with service bus object.' 12 | 13 | description <<-'EOT' 14 | Creates queue with service bus object. 15 | EOT 16 | 17 | Puppet::ServiceBus.add_servicebus_queue_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::ServiceBus.initialize_env_variable(options) 21 | azure_service_bus = Azure::ServiceBusService.new 22 | azure_service_bus.create_queue(options[:queue_name]).inspect 23 | end 24 | 25 | returns 'NONE' 26 | 27 | examples <<-'EOT' 28 | $ puppet azure_servicebus create_queue --sb-namespace busname \ 29 | --queue-name queuename --sb-access-key dnD/E49P4SJG8UVEpABOeZRc= 30 | 31 | EOT 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_servicebus/create_topic.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | Puppet::Face.define :azure_servicebus, '1.0.0' do 8 | action :create_topic do 9 | 10 | summary 'Create topic with service bus object.' 11 | 12 | description <<-'EOT' 13 | Create topic with service bus object. 14 | EOT 15 | 16 | Puppet::ServiceBus.add_servicebus_topic_options(self) 17 | 18 | when_invoked do |options| 19 | Puppet::ServiceBus.initialize_env_variable(options) 20 | azure_service_bus = Azure::ServiceBusService.new 21 | azure_service_bus.create_topic(options[:topic_name]).inspect 22 | end 23 | 24 | returns 'NONE' 25 | 26 | examples <<-'EOT' 27 | $ puppet azure_servicebus create_topic --sb-namespace busname \ 28 | --topic-name topicname --sb-access-key 4XJib8UcKEu8VG8UVEpABOeZRc= 29 | 30 | EOT 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_servicebus/delete_queue.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_servicebus, '1.0.0' do 9 | action :delete_queue do 10 | 11 | summary 'Delete a queue using service bus object.' 12 | 13 | description <<-'EOT' 14 | Delete a queue using service bus object. 15 | EOT 16 | 17 | Puppet::ServiceBus.add_servicebus_queue_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::ServiceBus.initialize_env_variable(options) 21 | azure_service_bus = Azure::ServiceBusService.new 22 | azure_service_bus.delete_queue(options[:queue_name]) 23 | end 24 | 25 | returns 'NONE' 26 | 27 | examples <<-'EOT' 28 | $ puppet azure_servicebus delete_queue --sb-namespace busname \ 29 | --queue-name queuename --sb-access-key dnD/E49P4SJG8UVEpABOeZRc= 30 | 31 | EOT 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_servicebus/delete_topic.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | Puppet::Face.define :azure_servicebus, '1.0.0' do 8 | action :delete_topic do 9 | 10 | summary 'Delete a topic using service bus object.' 11 | 12 | description <<-'EOT' 13 | Delete a topic using service bus object. 14 | EOT 15 | 16 | Puppet::ServiceBus.add_servicebus_topic_options(self) 17 | 18 | when_invoked do |options| 19 | Puppet::ServiceBus.initialize_env_variable(options) 20 | azure_service_bus = Azure::ServiceBusService.new 21 | azure_service_bus.delete_topic(options[:topic_name]) 22 | end 23 | 24 | returns 'NONE' 25 | 26 | examples <<-'EOT' 27 | $ puppet azure_servicebus delete_topic --sb-namespace busname \ 28 | --topic-name topic-name --sb-access-key 4XJib8UcKEu8VG8UVEpABOeZRc= 29 | 30 | EOT 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_servicebus/list_queues.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'tilt' 7 | require 'puppet/core/utility' 8 | 9 | Puppet::Face.define :azure_servicebus, '1.0.0' do 10 | action :list_queues do 11 | 12 | summary 'List queues' 13 | 14 | description 'List queues' 15 | 16 | Puppet::ServiceBus.add_default_options(self) 17 | 18 | when_invoked do |options| 19 | Puppet::ServiceBus.initialize_env_variable(options) 20 | azure_service_bus = Azure::ServiceBusService.new 21 | queues = azure_service_bus.list_queues 22 | template = Tilt.new(Puppet::ServiceBus.views('queues.erb')) 23 | template.render(nil, queues: queues) 24 | end 25 | 26 | returns 'NONE' 27 | 28 | examples <<-'EOT' 29 | $ puppet azure_servicebus list_queues --sb-namespace busname \ 30 | --sb-access-key GHdnD/E49P4SJG8UVEeABOeZRc= 31 | 32 | EOT 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_servicebus/list_topics.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'tilt' 7 | require 'puppet/core/utility' 8 | 9 | Puppet::Face.define :azure_servicebus, '1.0.0' do 10 | action :list_topics do 11 | 12 | summary 'List topics' 13 | 14 | description 'List topics' 15 | 16 | Puppet::ServiceBus.add_default_options(self) 17 | 18 | when_invoked do |options| 19 | Puppet::ServiceBus.initialize_env_variable(options) 20 | azure_service_bus = Azure::ServiceBusService.new 21 | topics = azure_service_bus.list_topics 22 | template = Tilt.new(Puppet::ServiceBus.views('topics.erb')) 23 | template.render(nil, topics: topics) 24 | end 25 | 26 | returns 'NONE' 27 | 28 | examples <<-'EOT' 29 | $ puppet azure_servicebus list_topics --sb-namespace busname \ 30 | --sb-access-key GHdnD/E49P4SJG8UVEeABOeZRc= 31 | 32 | EOT 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_servicebus/views/queues.erb: -------------------------------------------------------------------------------- 1 | 2 | <%="Listing queues".bold%><%index=1%> 3 | <%queues.each do |cs|%> 4 | <%="Queues: #{index}".bold%> 5 | <%="Name".fix(20)%>: <%=cs.name %> 6 | <%="URL".fix(20)%>: <%=cs.id%> 7 | <%="Author Name".fix(20)%>: <%=cs.author_name%><%index+=1%> 8 | <%end%> -------------------------------------------------------------------------------- /lib/puppet/face/azure_servicebus/views/topics.erb: -------------------------------------------------------------------------------- 1 | 2 | <%="Listing topics".bold%><%index=1%> 3 | <%topics.each do |tp|%> 4 | <%="Queues: #{index}".bold%> 5 | <%="Name".fix(20)%>: <%=tp.name %> 6 | <%="URL".fix(20)%>: <%=tp.id%> 7 | <%="Author Name".fix(20)%>: <%=tp.author_name%><%index+=1%> 8 | <%end%> -------------------------------------------------------------------------------- /lib/puppet/face/azure_sqldb.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/sql_database' 7 | 8 | Puppet::Face.define(:azure_sqldb, '1.0.0') do 9 | 10 | summary 'View and manage Window Azure database servers.' 11 | description <<-'EOT' 12 | This subcommand provides a command line interface to work with Microsoft Azure 13 | machine instances. The goal of these actions are to easily create new 14 | database servers. 15 | EOT 16 | 17 | end 18 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_sqldb/create.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_sqldb, '1.0.0' do 9 | action :create do 10 | 11 | summary 'Create SQL database server.' 12 | description 'The create action create a SQL database server.' 13 | 14 | Puppet::SqlDatabase.add_create_options(self) 15 | 16 | when_invoked do |options| 17 | Puppet::SqlDatabase.initialize_env_variable(options) 18 | db = Azure::SqlDatabaseManagementService.new 19 | sql_server = db.create_server( 20 | options[:login], 21 | options[:password], 22 | options[:location] 23 | ) 24 | template = Tilt.new(Puppet::SqlDatabase.views('servers.erb')) 25 | template.render(nil, db_servers: sql_server) if sql_server 26 | end 27 | 28 | examples <<-'EOT' 29 | $ puppet azure_sqldb create --login puppet --location 'West Us' \ 30 | --azure-subscription-id=YOUR-SUBSCRIPTION-ID --password Ranjan@123 \ 31 | --management-endpoint=https://management.database.windows.net:8443/ \ 32 | --management-certificate path-to-azure-certificate 33 | EOT 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_sqldb/create_firewall.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_sqldb, '1.0.0' do 9 | action :create_firewall do 10 | 11 | summary 'Create SQL database firewall rule on a server.' 12 | 13 | description <<-'EOT' 14 | The create action create a SQL database firewall rule on a server. 15 | EOT 16 | 17 | Puppet::SqlDatabase.add_create_firewall_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::SqlDatabase.initialize_env_variable(options) 21 | db_server = Azure::SqlDatabaseManagementService.new 22 | ip_range = { 23 | start_ip_address: options[:start_ip_address], 24 | end_ip_address: options[:end_ip_address] 25 | } 26 | db_server.set_sql_server_firewall_rule( 27 | options[:server_name], 28 | options[:rule_name], 29 | ip_range 30 | ) 31 | end 32 | 33 | examples <<-'EOT' 34 | $ puppet azure_sqldb create_firewall --end-ip-address 10.10.0.255 \ 35 | --management-certificate path-to-azure-certificate \ 36 | --azure-subscription-id YOUR-SUBSCRIPTION-ID --rule-name ranjan \ 37 | --management-endpoint=https://management.database.windows.net:8443/\ 38 | --server-name=g2jxhsbk0w --start-ip-address 10.10.0.0 39 | 40 | $ puppet azure_sqldb create_firewall --server-name=g2jxhsbk0w\ 41 | --management-certificate path-to-azure-certificate \ 42 | --azure-subscription-id YOUR-SUBSCRIPTION-ID --rule-name ranjan 43 | EOT 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_sqldb/delete.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_sqldb, '1.0.0' do 9 | action :delete do 10 | 11 | summary 'Delete Microsoft Azure sql database server' 12 | 13 | description <<-'EOT' 14 | The delete action delete windows azure sql server. 15 | EOT 16 | 17 | Puppet::SqlDatabase.add_delete_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::SqlDatabase.initialize_env_variable(options) 21 | db = Azure::SqlDatabaseManagementService.new 22 | db.delete_server(options[:server_name]) 23 | nil 24 | end 25 | 26 | returns 'NONE' 27 | 28 | examples <<-'EOT' 29 | $ puppet azure_sqldb delete --server-name=ezprthvj9w \ 30 | --management-certificate path-to-azure-certificate \ 31 | --azure-subscription-id OUR-SUBSCRIPTION-ID \ 32 | --management-endpoint=https://management.database.windows.net:8443/ 33 | EOT 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_sqldb/delete_firewall.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_sqldb, '1.0.0' do 9 | action :delete_firewall do 10 | 11 | summary 'Delete Microsoft Azure sql database firewall rule on server' 12 | 13 | description <<-'EOT' 14 | The delete action delete windows azure sql database firewall on server. 15 | EOT 16 | 17 | Puppet::SqlDatabase.add_delete_firewall_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::SqlDatabase.initialize_env_variable(options) 21 | db = Azure::SqlDatabaseManagementService.new 22 | db.delete_sql_server_firewall_rule( 23 | options[:server_name], 24 | options[:rule_name] 25 | ) 26 | nil 27 | end 28 | 29 | returns 'NONE' 30 | 31 | examples <<-'EOT' 32 | $ puppet azure_sqldb delete_firewall --server-name=xlykw0su08 \ 33 | --management-certificate path-to-azure-certificate \ 34 | --azure-subscription-id=YOUR-SUBSCRIPTION-ID --rule-name rule1 \ 35 | --management-endpoint=https://management.database.windows.net:8443/ \ 36 | 37 | EOT 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_sqldb/list.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'tilt' 8 | 9 | Puppet::Face.define :azure_sqldb, '1.0.0' do 10 | action :list do 11 | 12 | summary 'List SQL database servers.' 13 | arguments 'list' 14 | description <<-'EOT' 15 | The list action obtains a list of sql database servers and 16 | displays them on the console output. 17 | EOT 18 | 19 | Puppet::SqlDatabase.add_default_options(self) 20 | 21 | when_invoked do |options| 22 | Puppet::SqlDatabase.initialize_env_variable(options) 23 | sql_service = Azure::SqlDatabaseManagementService.new 24 | servers = sql_service.list_servers 25 | template = Tilt.new(Puppet::SqlDatabase.views('servers.erb')) 26 | template.render(nil, db_servers: servers) 27 | end 28 | 29 | returns 'Array of database server objets.' 30 | 31 | examples <<-'EOT' 32 | $ puppet azure_sqldb list --azure-subscription-id=YOUR-SUBSCRIPTION-ID \ 33 | --management-certificate azure-certificate-path \ 34 | --management-endpoint=https://management.database.windows.net:8443/ 35 | 36 | Listing Servers 37 | 38 | Server: 1 39 | Server Name : esinlp9bav 40 | Administrator login : puppet3 41 | Location : West US 42 | 43 | Server: 2 44 | Server Name : estkonosnv 45 | Administrator login : puppet 46 | Location : West US 47 | 48 | Server: 3 49 | Server Name : ezprthvj9w 50 | Administrator login : puppet 51 | Location : West US 52 | 53 | EOT 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_sqldb/list_firewall.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_sqldb, '1.0.0' do 9 | action :list_firewall do 10 | 11 | summary 'List firewall of SQL database servers.' 12 | arguments 'list' 13 | description <<-'EOT' 14 | The list_firewall action retrieves a list of all the server-level 15 | firewall rules for a SQL Database server that belongs to a subscription. 16 | EOT 17 | 18 | Puppet::SqlDatabase.add_delete_options(self) 19 | 20 | when_invoked do |options| 21 | Puppet::SqlDatabase.initialize_env_variable(options) 22 | db_server = Azure::SqlDatabaseManagementService.new 23 | 24 | firewalls = db_server.list_sql_server_firewall_rules( 25 | options[:server_name] 26 | ) 27 | template = Tilt.new(Puppet::SqlDatabase.views('server_firewalls.erb')) 28 | template.render(nil, firewalls: firewalls) 29 | end 30 | 31 | examples <<-'EOT' 32 | $ puppet azure_sqldb list_firewall --server-name=g2jxhsbk0w \ 33 | --management-certificate path-to-azure-certificate \ 34 | --azure-subscription-id=YOUR-SUBSCRIPTION-ID \ 35 | --management-endpoint=https://management.database.windows.net:8443/ \ 36 | 37 | Listing Firewall 38 | 39 | Firewall: 1 40 | Rule name : ClientIPAddress_2013-08-20_15:37:41 41 | Start IP address : 207.46.55.27 42 | End Ip Address : 207.46.55.27 43 | 44 | Firewall: 2 45 | Rule name : ranjan 46 | Start IP address : 10.10.0.0 47 | End Ip Address : 10.10.0.0 48 | 49 | Firewall: 3 50 | Rule name : rule2 51 | Start IP address : 192.168.1.1 52 | End Ip Address : 192.168.1.1 53 | 54 | EOT 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_sqldb/reset_password.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_sqldb, '1.0.0' do 9 | action :reset_password do 10 | 11 | summary 'Reset password of sql database server.' 12 | 13 | description <<-'EOT' 14 | The reset_passowrd action reset password of sql database server. 15 | EOT 16 | 17 | Puppet::SqlDatabase.add_reset_password_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::SqlDatabase.initialize_env_variable(options) 21 | db = Azure::SqlDatabaseManagementService.new 22 | db.reset_password(options[:server_name], options[:password]) 23 | nil 24 | end 25 | 26 | examples <<-'EOT' 27 | $ puppet azure_sqldb reset_password --password ComplexPassword$# \ 28 | --management-certificate path-to-azure-certificate \ 29 | --azure-subscription-id=YOUR-SUBSCRIPTION-ID --server-name hc786mm0l8 \ 30 | --management-endpoint=https://management.database.windows.net:8443/\ 31 | 32 | EOT 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_sqldb/views/server_firewalls.erb: -------------------------------------------------------------------------------- 1 | <%="Listing Firewall".bold%> 2 | <%index=1%> 3 | 4 | <%firewalls.each do |firewall|%> 5 | <%="Firewall: #{index}".bold%> 6 | <%="Rule Name".fix(20)%>: <%=firewall[:rule] %> 7 | <%="Start IP Address".fix(20)%>: <%=firewall[:start_ip_address]%> 8 | <%="End IP Address".fix(20)%>: <%=firewall[:end_ip_address] %> <%index+=1%> 9 | <%end%> 10 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_sqldb/views/servers.erb: -------------------------------------------------------------------------------- 1 | <%if db_servers.class == Azure::SqlDatabaseManagement::SqlDatabase%> 2 | 3 | <%="Server Name".fix(20)%>: <%=db_servers.name %> 4 | <%="Administrator login".fix(20)%>: <%=db_servers.administrator_login%> 5 | <%="Location".fix(20)%>: <%=db_servers.location %> 6 | <%else%> 7 | <%="Listing Servers".bold%> 8 | <%index=1%> 9 | 10 | <%db_servers.each do |server|%> 11 | <%="Server: #{index}".bold%> 12 | <%="Server Name".fix(20)%>: <%=server.name %> 13 | <%="Administrator login".fix(20)%>: <%=server.administrator_login%> 14 | <%="Location".fix(20)%>: <%=server.location %> <%index+=1%> 15 | <%end%> 16 | <%end%> 17 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_storage.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/storage_account' 7 | 8 | Puppet::Face.define(:azure_storage, '1.0.0') do 9 | 10 | summary 'View and manage Window Azure storage account.' 11 | description <<-'EOT' 12 | This subcommand provides a command line interface to work with Microsoft Azure 13 | storage account. The goal of these actions are to easily manage storage account. 14 | EOT 15 | 16 | end 17 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_storage/create.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | Puppet::Face.define :azure_storage, '1.0.0' do 8 | action :create do 9 | 10 | summary 'Create storage service.' 11 | 12 | description 'The create action create a storage account.' 13 | 14 | Puppet::StorageAccount.add_create_options(self) 15 | 16 | when_invoked do |options| 17 | Puppet::StorageAccount.initialize_env_variable(options) 18 | storage_account = Azure::StorageManagementService.new 19 | others = { 20 | description: options[:description], 21 | label: options[:label], 22 | affinity_group_name: options[:affinity_group_name], 23 | location: options[:location], 24 | extended_properties: options[:extended_properties] 25 | } 26 | storage_account.create_storage_account( 27 | options[:storage_account_name], 28 | others 29 | ) 30 | nil 31 | end 32 | 33 | examples <<-'EOT' 34 | $ puppet azure_storage create --label aglabel \ 35 | --azure-subscription-id YOUR-SUBSCRIPTION-ID --location 'West Us' \ 36 | --affinity-group-name agname --description 'Some Description' \ 37 | --management-certificate path-to-azure-certificate 38 | EOT 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_storage/delete.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_storage, '1.0.0' do 9 | action :delete do 10 | 11 | summary 'Delete storage account.' 12 | 13 | description 'The delete action delete a storage account.' 14 | 15 | Puppet::StorageAccount.add_delete_options(self) 16 | 17 | when_invoked do |options| 18 | Puppet::StorageAccount.initialize_env_variable(options) 19 | storage_service = Azure::StorageManagementService.new 20 | begin 21 | storage_service.delete_storage_account(options[:storage_account_name]) 22 | rescue 23 | end 24 | nil 25 | end 26 | 27 | examples <<-'EOT' 28 | $ puppet azure_storage delete --storage-account-name storagename \ 29 | --azure-subscription-id YOUR-SUBSCRIPTION-ID \ 30 | --management-certificate path-to-azure-certificate 31 | EOT 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_storage/list.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'tilt' 8 | 9 | Puppet::Face.define :azure_storage, '1.0.0' do 10 | action :list do 11 | 12 | summary 'List storage accounts.' 13 | 14 | description <<-'EOT' 15 | The list action obtains a list of storage accounts and 16 | displays them on the console output. 17 | EOT 18 | 19 | Puppet::StorageAccount.add_default_options(self) 20 | 21 | when_invoked do |options| 22 | Puppet::StorageAccount.initialize_env_variable(options) 23 | strage_service = Azure::StorageManagementService.new 24 | 25 | storage_accounts = strage_service.list_storage_accounts 26 | template = Tilt.new(Puppet::StorageAccount.views('storage_accounts.erb')) 27 | template.render(nil, storage_accounts: storage_accounts) 28 | end 29 | 30 | returns 'Array of storage account objets.' 31 | 32 | examples <<-'EOT' 33 | $ puppet azure_storage list \ 34 | --management-certificate path-to-azure-certificate \ 35 | --azure-subscription-id=YOUR-SUBSCRIPTION-ID 36 | 37 | Listing storage accounts 38 | Storage Account: 1 39 | Name : azure-puppet 40 | Locaton : West US 41 | Status : Created 42 | Winrm Thumbprint : 43 | Storage Account: 2 44 | Name : puppet-dashboard-service-oiurf 45 | Locaton : West US 46 | Status : Created 47 | Winrm Thumbprint : 48 | Storage Account: 3 49 | Name : puppet-master 50 | Locaton : West US 51 | Status : Created 52 | Winrm Thumbprint : 53 | EOT 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_storage/update.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_storage, '1.0.0' do 9 | action :update do 10 | 11 | summary 'Update storage service.' 12 | 13 | description 'The update action updates a storage account.' 14 | 15 | Puppet::StorageAccount.add_create_options(self) 16 | 17 | when_invoked do |options| 18 | Puppet::StorageAccount.initialize_env_variable(options) 19 | storage_account = Azure::StorageManagementService.new 20 | others = { 21 | description: options[:description], 22 | label: options[:label], 23 | affinity_group_name: options[:affinity_group_name], 24 | location: options[:location], 25 | extended_properties: options[:extended_properties] 26 | } 27 | storage_account.update_storage_account( 28 | options[:storage_account_name], 29 | others 30 | ) 31 | nil 32 | end 33 | 34 | examples <<-'EOT' 35 | $ puppet azure_storage update --label aglabel \ 36 | --azure-subscription-id YOUR-SUBSCRIPTION-ID --location 'West Us' \ 37 | --affinity-group-name agname --description 'Some Description' \ 38 | --management-certificate path-to-azure-certificate 39 | EOT 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_storage/views/storage_accounts.erb: -------------------------------------------------------------------------------- 1 | 2 | <%="Listing storage accounts".bold%> 3 | 4 | <%index=1%> 5 | 6 | <%storage_accounts.each do |sa|%> 7 | <%="Storage Account: #{index}".bold%> 8 | <%="Name".fix(20)%>: <%=sa.name %> 9 | <%="Locaton".fix(20)%>: <%=sa.location%> 10 | <%="Status".fix(20)%>: <%=sa.status%> 11 | <%="Extended Properties".fix(20)%>: <%=sa.extended_properties%><%index+=1%> 12 | <%end%> -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/virtual_machine' 7 | 8 | Puppet::Face.define(:azure_vm, '1.0.0') do 9 | 10 | summary 'View and manage Window Azure nodes.' 11 | description <<-'EOT' 12 | This subcommand provides a command line interface to work with Microsoft Azure 13 | machine instances. The goal of these actions are to easily create new 14 | machines, install Puppet onto them, and tear them down when they're no longer 15 | required. 16 | EOT 17 | 18 | end 19 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/add_disk.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :add_disk do 10 | 11 | summary 'adds a data disk to a virtual machine.' 12 | 13 | description <<-'EOT' 14 | The add_disk action adds a data disk to a windows azure node instances. 15 | EOT 16 | 17 | Puppet::VirtualMachine.add_data_disk_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::VirtualMachine.initialize_env_variable(options) 21 | virtual_machine_service = Azure::VirtualMachineManagementService.new 22 | others = { 23 | import: options[:import], 24 | disk_label: options[:disk_label], 25 | disk_size: options[:disk_size], 26 | disk_name: options[:disk_name] 27 | } 28 | virtual_machine_service.add_data_disk( 29 | options[:vm_name], 30 | options[:cloud_service_name], 31 | others 32 | ) 33 | nil 34 | end 35 | 36 | returns 'NONE' 37 | 38 | examples <<-'EOT' 39 | $ puppet azure_vm add_disk --vm-name vmname --import true \ 40 | --cloud-service-name cloudname --disk-name disk_name \ 41 | --management-certificate path-to-azure-certificate \ 42 | --subscription-id YOUR-SUBSCRIPTION-ID \ 43 | 44 | $ puppet azure_vm add_disk --cloud-service-name cloud_name \ 45 | --management-certificate path-to-azure-certificate --vm-name vmname \ 46 | --subscription-id YOUR-SUBSCRIPTION-ID 47 | 48 | EOT 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/add_role.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :add_role do 10 | 11 | summary 'Create multiple roles under the same cloud service' 12 | 13 | description <<-'EOT' 14 | The add_role action create multiple roles under the same cloud service. 15 | Atleast a single deployment should be created under a hosted service. 16 | EOT 17 | 18 | Puppet::VirtualMachine.add_create_options(self, true) 19 | 20 | when_invoked do |options| 21 | options = ask_for_password(options, @os_type) 22 | virtual_machine_service = Azure::VirtualMachineManagementService.new 23 | params = { 24 | vm_name: options[:vm_name], 25 | vm_user: options[:vm_user], 26 | image: options[:image], 27 | password: options[:password], 28 | cloud_service_name: options[:cloud_service_name], 29 | } 30 | 31 | others = { 32 | storage_account_name: options[:storage_account_name], 33 | tcp_endpoints: options[:tcp_endpoints], 34 | private_key_file: options[:private_key_file] , 35 | certificate_file: options[:certificate_file], 36 | ssh_port: options[:ssh_port], 37 | vm_size: options[:vm_size], 38 | virtual_network_name: options[:virtual_network_name], 39 | subnet_name: options[:virtual_network_subnet], 40 | affinity_group_name: options[:affinity_group_name], 41 | availability_set_name: options[:availability_set_name], 42 | winrm_http_port: options[:winrm_http_port], 43 | winrm_https_port: options[:winrm_https_port], 44 | } 45 | winrm_tp = options[:winrm_transport] 46 | others.merge!(winrm_transport: winrm_tp) unless winrm_tp.nil? 47 | server = virtual_machine_service.add_role(params, others) 48 | unless server.class == String 49 | if options[:puppet_master_ip] && server 50 | if server.os_type == 'Linux' 51 | options[:node_ipaddress] = server.ipaddress 52 | options[:ssh_user] = params[:vm_user] 53 | Puppet::AzurePack::BootStrap.start(options) 54 | else 55 | puts 56 | msg = <<-'EOT' 57 | To Bootstrap windows node log into the VM and run these commands: 58 | winrm set winrm/config/service @{AllowUnencrypted="true"} 59 | winrm set winrm/config/service/auth @{Basic="true"} 60 | And then run puppet bootstrap command on master. 61 | EOT 62 | puts msg 63 | end 64 | end 65 | end 66 | end 67 | 68 | examples <<-'EOT' 69 | $ puppet azure_vm add_role --vm-name vmname --location "Southeast Asia" \ 70 | --management-certificate path-to-azure-certificate --vm-user ranjan \ 71 | --password Password!@12 --storage-account-name storageaccount1'\ 72 | --image b446e5424aa335e__SUSE-Linux-Enterprise-Server-11-SP2-Agent13 \ 73 | --cloud-service-name cloudname --subscription-id YOUR-SUBSCRIPTION-ID \ 74 | --tcp-endpoints "80,3889:3889" 75 | EOT 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/bootstrap.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'puppet/azurepack/bootstrap' 8 | 9 | Puppet::Face.define :azure_vm, '1.0.0' do 10 | action :bootstrap do 11 | 12 | summary 'Install puppet node on Microsoft Azure VM' 13 | description 'Install puppet node on Microsoft Azure Virtual Machine.' 14 | 15 | Puppet::VirtualMachine.add_bootstrap_options(self) 16 | 17 | when_invoked do |options| 18 | Puppet::AzurePack::BootStrap.start(options) 19 | nil 20 | end 21 | 22 | examples <<-'EOT' 23 | $ puppet azure_vm bootstrap --node-ip-address=domain.cloudapp.net \ 24 | --vm-user username --puppet-master-ip 152.56.161.48 --password Abcd123 \ 25 | --agent-environment development 26 | EOT 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/create.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :create do 10 | 11 | summary 'Create Microsoft Azure VM' 12 | 13 | description <<-'EOT' 14 | The create action create a storage account, cloud service and virtula machine. 15 | EOT 16 | 17 | Puppet::VirtualMachine.add_create_options(self) 18 | 19 | when_invoked do |options| 20 | options = ask_for_password(options, @os_type) 21 | virtual_machine_service = Azure::VirtualMachineManagementService.new 22 | params = { 23 | vm_name: options[:vm_name], 24 | vm_user: options[:vm_user], 25 | image: options[:image], 26 | password: options[:password], 27 | location: options[:location] 28 | } 29 | others = { 30 | storage_account_name: options[:storage_account_name], 31 | cloud_service_name: options[:cloud_service_name], 32 | deployment_name: options[:deployment_name], 33 | tcp_endpoints: options[:tcp_endpoints], 34 | private_key_file: options[:private_key_file] , 35 | certificate_file: options[:certificate_file], 36 | ssh_port: options[:ssh_port], 37 | vm_size: options[:vm_size], 38 | virtual_network_name: options[:virtual_network_name], 39 | subnet_name: options[:virtual_network_subnet], 40 | affinity_group_name: options[:affinity_group_name], 41 | availability_set_name: options[:availability_set_name], 42 | winrm_http_port: options[:winrm_http_port], 43 | winrm_https_port: options[:winrm_https_port], 44 | } 45 | others.merge!(winrm_transport: options[:winrm_transport]) unless options[:winrm_transport].nil? 46 | server = virtual_machine_service.create_virtual_machine(params, others) 47 | unless server.class == String 48 | if options[:puppet_master_ip] && server 49 | if server.os_type == 'Linux' 50 | options[:node_ipaddress] = server.ipaddress 51 | options[:ssh_user] = params[:vm_user] 52 | Puppet::AzurePack::BootStrap.start(options) 53 | else 54 | puts 55 | msg = <<-'EOT' 56 | To Bootstrap windows node log into the VM and run these commands: 57 | winrm set winrm/config/service @{AllowUnencrypted="true"} 58 | winrm set winrm/config/service/auth @{Basic="true"} 59 | And then run puppet bootstrap command on master. 60 | EOT 61 | puts msg 62 | end 63 | end 64 | end 65 | end 66 | 67 | examples <<-'EOT' 68 | $ puppet azure_vm create --vm-name vmname --location "Southeast Asia" \ 69 | --management-certificate path-to-azure-certificate --vm-user ranjan \ 70 | --password Password!@12 --storage-account-name storageaccount1'\ 71 | --image b446e5424aa335e__SUSE-Linux-Enterprise-Server-11-SP2-Agent13 \ 72 | --cloud-service-name cloudname --subscription-id YOUR-SUBSCRIPTION-ID \ 73 | --tcp-endpoints "80,3889:3889" 74 | EOT 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/delete.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :delete do 10 | 11 | summary 'Delete Microsoft Azure node instances' 12 | description 'The delete action delete windows azure node instances.' 13 | 14 | Puppet::VirtualMachine.add_delete_options(self) 15 | 16 | when_invoked do |options| 17 | Puppet::VirtualMachine.initialize_env_variable(options) 18 | virtual_machine_service = Azure::VirtualMachineManagementService.new 19 | virtual_machine_service.delete_virtual_machine( 20 | options[:vm_name], 21 | options[:cloud_service_name] 22 | ) 23 | nil 24 | end 25 | 26 | returns 'NONE' 27 | 28 | examples <<-'EOT' 29 | $ puppet azure_vm delete --cloud-service-name service_name \ 30 | --publish-settings-file azure-certificate-path --vm-name name \ 31 | --management-certificate path-to-azure-certificate 32 | EOT 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/delete_endpoint.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :delete_endpoint do 10 | 11 | summary 'Delete endpoint of virtual machine.' 12 | 13 | description <<-'EOT' 14 | Delete endpoint of windows azure node instances. 15 | EOT 16 | 17 | Puppet::VirtualMachine.delete_endpoint_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::VirtualMachine.initialize_env_variable(options) 21 | virtual_machine_service = Azure::VirtualMachineManagementService.new 22 | 23 | virtual_machine_service.delete_endpoint( 24 | options[:vm_name], 25 | options[:cloud_service_name], 26 | options[:endpoint_name] 27 | ) 28 | nil 29 | end 30 | 31 | returns 'NONE' 32 | 33 | examples <<-'EOT' 34 | $ puppet azure_vm delete_endpoint --endpoint-name endpointname \ 35 | --management-certificate path-to-azure-certificate --vm-name vmname \ 36 | --cloud-service-name cloudname 37 | EOT 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/images.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :images do 10 | 11 | summary 'List Microsoft Azure images' 12 | 13 | description <<-'EOT' 14 | The images action obtains a list of images from the cloud provider and 15 | displays them on the console output. 16 | EOT 17 | 18 | Puppet::VirtualMachine.add_list_images_options(self) 19 | 20 | when_invoked do |options| 21 | Puppet::VirtualMachine.initialize_env_variable(options) 22 | image_service = Azure::VirtualMachineImageManagementService.new 23 | images = image_service.list_virtual_machine_images 24 | location = options[:location] 25 | images = images.select { |x| x.locations =~ /#{location}/i } if location 26 | template = Tilt.new(Puppet::VirtualMachine.views('images.erb')) 27 | template.render(nil, images: images) 28 | end 29 | 30 | returns 'List containing information about each Azure images.' 31 | 32 | examples <<-'EOT' 33 | $ puppet azure_vm images --azure-subscription-id YOUR-SUBSCRIPTION-ID \ 34 | --management-certificate path-to-azure-certificate 35 | 36 | Listing Virtual Machine Images 37 | 38 | OS Type Category Name 39 | Linux RightScale with Linu RightImage-CentOS-6.2-x64-v5.8.8.1 40 | Linux RightScale with Linu RightImage-CentOS-6.3-x64-v5.8.8 41 | EOT 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/locations.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :locations do 10 | 11 | summary 'List Microsoft Azure locations' 12 | 13 | description <<-'EOT' 14 | The locations action obtains a list of locatons from the cloud provider 15 | and displays them on the console output. 16 | EOT 17 | 18 | Puppet::VirtualMachine.add_default_options(self) 19 | 20 | when_invoked do |options| 21 | Puppet::VirtualMachine.initialize_env_variable(options) 22 | base_management = Azure::BaseManagementService.new 23 | locations = base_management.list_locations 24 | template = Tilt.new(Puppet::VirtualMachine.views('locations.erb')) 25 | template.render(nil, locations: locations) 26 | end 27 | 28 | returns <<-'EOT' 29 | Array of attribute hashes containing information about 30 | Microsoft Azure locations.' 31 | EOT 32 | 33 | examples <<-'EOT' 34 | $ puppet azure_vm locations --azure-subscription-id YOUR-SUBSCRIPTION-ID\ 35 | --management-certificate path-to-azure-certificate 36 | Location Name Available Service 37 | 38 | West US : Compute, Storage, PersistentVMRole 39 | East US : Compute, Storage, PersistentVMRole 40 | East Asia : Compute, Storage, PersistentVMRole 41 | Southeast Asia : Compute, Storage, PersistentVMRole 42 | North Europe : Compute, Storage, PersistentVMRole 43 | West Europe : Compute, Storage, PersistentVMRole 44 | EOT 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/restart.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :restart do 10 | 11 | summary 'Restarts Microsoft Azure node instance' 12 | 13 | description <<-'EOT' 14 | The restart action restarts windows azure node instance. 15 | EOT 16 | 17 | Puppet::VirtualMachine.add_shutdown_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::VirtualMachine.initialize_env_variable(options) 21 | virtual_machine_service = Azure::VirtualMachineManagementService.new 22 | virtual_machine_service.restart_virtual_machine( 23 | options[:vm_name], 24 | options[:cloud_service_name] 25 | ) 26 | nil 27 | end 28 | 29 | returns 'NONE' 30 | 31 | examples <<-'EOT' 32 | $ puppet azure_vm restart --cloud-service-name service_name \ 33 | --management-certificate path-to-azure-certificate \ 34 | --azure-subscription-id YOUR-SUBSCRIPTION-ID --vm-name name 35 | 36 | EOT 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/servers.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'tilt' 8 | 9 | Puppet::Face.define :azure_vm, '1.0.0' do 10 | action :servers do 11 | 12 | summary 'List Microsoft Azure node instances' 13 | arguments 'list' 14 | description <<-'EOT' 15 | The list action obtains a list of instances from the cloud provider and 16 | displays them on the console output. For Azure instances, only the 17 | instances in a specific region are provided. 18 | EOT 19 | 20 | Puppet::VirtualMachine.add_default_options(self) 21 | 22 | when_invoked do |options| 23 | Puppet::VirtualMachine.initialize_env_variable(options) 24 | virtual_machine_service = Azure::VirtualMachineManagementService.new 25 | servers = virtual_machine_service.list_virtual_machines 26 | template = Tilt.new(Puppet::VirtualMachine.views('servers.erb')) 27 | template.render(nil, roles: servers) 28 | end 29 | 30 | returns 'Array of attribute hashes containing information about each Azure instance.' 31 | 32 | examples <<-'EOT' 33 | $ puppet azure_vm servers --publish-settings-file azure-certificate-path 34 | --azure-subscription-id YOUR-SUBSCRIPTION-ID 35 | Server: 1 36 | Service: cloudserver1 37 | Deployment: deployment1 38 | Role: windows 39 | Host: akwindows 40 | Deployment Status: Running 41 | Role Status: ReadyRole 42 | IP Address: 168.61.8.83 43 | EOT 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/shutdown.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :shutdown do 10 | 11 | summary 'Shutdown Microsoft Azure node instances' 12 | description 'The shutdown action stops windows azure node instances.' 13 | 14 | Puppet::VirtualMachine.add_shutdown_options(self) 15 | 16 | when_invoked do |options| 17 | Puppet::VirtualMachine.initialize_env_variable(options) 18 | virtual_machine_service = Azure::VirtualMachineManagementService.new 19 | virtual_machine_service.shutdown_virtual_machine( 20 | options[:vm_name], 21 | options[:cloud_service_name] 22 | ) 23 | nil 24 | end 25 | 26 | returns 'NONE' 27 | 28 | examples <<-'EOT' 29 | $ puppet azure_vm shutdown --cloud-service-name service_name \ 30 | --publish-settings-file azure-certificate-path --vm-name name \ 31 | --management-certificate path-to-azure-certificate 32 | 33 | EOT 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/start.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :start do 10 | 11 | summary 'starts Microsoft Azure node instances' 12 | 13 | description <<-'EOT' 14 | The start action starts windows azure node instances. 15 | EOT 16 | 17 | Puppet::VirtualMachine.add_shutdown_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::VirtualMachine.initialize_env_variable(options) 21 | virtual_machine_service = Azure::VirtualMachineManagementService.new 22 | virtual_machine_service.start_virtual_machine( 23 | options[:vm_name], 24 | options[:cloud_service_name] 25 | ) 26 | nil 27 | end 28 | 29 | returns 'NONE' 30 | 31 | examples <<-'EOT' 32 | $ puppet azure_vm start --cloud-service-name service_name \ 33 | --management-certificate path-to-azure-certificate \ 34 | --azure-subscription-id YOUR-SUBSCRIPTION-ID --vm-name name 35 | 36 | EOT 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/update_endpoint.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | Puppet::Face.define :azure_vm, '1.0.0' do 9 | action :update_endpoint do 10 | 11 | summary 'update existing endpoint of a virtual machine.' 12 | 13 | description <<-'EOT' 14 | The update_endpoint action update existing endpoint of a virtual machine. 15 | EOT 16 | 17 | Puppet::VirtualMachine.update_endpoint_options(self) 18 | 19 | when_invoked do |options| 20 | Puppet::VirtualMachine.initialize_env_variable(options) 21 | virtual_machine_service = Azure::VirtualMachineManagementService.new 22 | options[:protocol] ||= 'TCP' 23 | options[:direct_server_return] ||= 'false' 24 | ep = { 25 | name: options[:endpoint_name], 26 | public_port: options[:public_port], 27 | local_port: options[:local_port], 28 | protocol: options[:protocol], 29 | load_balancer_name: options[:load_balancer_name], 30 | direct_server_return: options[:direct_server_return], 31 | load_balancer: { 32 | port: options[:load_balancer_port], 33 | protocol: options[:load_balancer_protocol], 34 | path: options[:load_balancer_path] 35 | } 36 | } 37 | virtual_machine_service.update_endpoints( 38 | options[:vm_name], 39 | options[:cloud_service_name], 40 | ep 41 | ) 42 | nil 43 | end 44 | 45 | returns 'NONE' 46 | 47 | examples <<-'EOT' 48 | $ puppet azure_vm update_endpoint --subscription-id YOUR-SUBSCRIPTION-ID \ 49 | --cloud-service-name cloudname --vm-name vmname --endpoint-name epname \ 50 | --local-port 90 --public-port 91 --direct-server-return true \ 51 | --load-balancer-name lbname --protocol udp 52 | 53 | $ puppet azure_vm update_endpoint --subscription-id YOUR-SUBSCRIPTION-ID \ 54 | --cloud-service-name cloudname --vm-name vmname --endpoint-name epname 55 | --local-port 90 --public-port 91 56 | 57 | EOT 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/views/images.erb: -------------------------------------------------------------------------------- 1 | 2 | <%="Listing Virtual Machine Images".bold %> 3 | 4 | <%="OS Type".bold%> <%="Category".bold%> <%="Name".bold%> 5 | <%images.each do |image|%> 6 | <%=image.os_type.fix%> <%=image.category.fix(20)%> <%=image.name%> 7 | <%end%> -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/views/locations.erb: -------------------------------------------------------------------------------- 1 | 2 | <%="Listing Locations".bold%> 3 | 4 | <%="Location Name".bold%> <%="Available Service".bold%> 5 | <%locations.each do |location|%> 6 | <%=location.name.fix%> <%=location.available_services%> 7 | <%end%> -------------------------------------------------------------------------------- /lib/puppet/face/azure_vm/views/servers.erb: -------------------------------------------------------------------------------- 1 | <%index=1%> 2 | <%="Listing Servers".bold%> 3 | <%roles.each do |role|%> 4 | 5 | <%="Server: #{index}".bold%> 6 | <%="Service".fix%>: <%=role.cloud_service_name %> 7 | <%="Deployment".fix%>: <%=role.deployment_name%> 8 | <%="Role".fix%>: <%=role.vm_name %> 9 | <%="Host".fix%>: <%=role.hostname%> 10 | <%="Deployment Status".fix%>: <%=role.deployment_status == "Running" ? role.deployment_status.green : role.deployment_status%> 11 | <%="Role Status".fix%>: <%=role.status%> 12 | <%="IP Address".fix%>: <%=role.ipaddress%> 13 | <%index+=1%><%end%> 14 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vnet.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/virtual_network' 7 | 8 | Puppet::Face.define(:azure_vnet, '1.0.0') do 9 | 10 | summary 'View and manage Window Azure virtual networks.' 11 | description <<-'EOT' 12 | This subcommand provides a command line interface to work with Microsoft Azure 13 | virtual networks. The goal of these actions are to easily create new or update 14 | virtual network. 15 | EOT 16 | 17 | end 18 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vnet/list.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'tilt' 8 | 9 | Puppet::Face.define :azure_vnet, '1.0.0' do 10 | action :list do 11 | 12 | summary 'List virtual networks.' 13 | arguments 'list' 14 | description <<-'EOT' 15 | The list action obtains a list of virtual networks and 16 | displays them on the console output. 17 | EOT 18 | 19 | Puppet::VirtualNetwork.add_default_options(self) 20 | 21 | when_invoked do |options| 22 | Puppet::VirtualNetwork.initialize_env_variable(options) 23 | virtual_network_service = Azure::VirtualNetworkManagementService.new 24 | 25 | virtual_networks = virtual_network_service.list_virtual_networks 26 | template = Tilt.new(Puppet::VirtualNetwork.views('virtual_networks.erb')) 27 | template.render(nil, vnets: virtual_networks) 28 | end 29 | 30 | returns 'Array of virtual network objets.' 31 | 32 | examples <<-'EOT' 33 | $ puppet azure_vnet list --management-certificate path-to-azure-certificate \ 34 | --azure-subscription-id=YOUR-SUBSCRIPTION-ID 35 | Listing virtual networks 36 | 37 | Virtual Network: 1 38 | Server Name : vnet-AG 39 | Address Space : 172.16.0.0/12, 10.0.0.0/8, 192.168.0.0/24 40 | 41 | Subnets: Name Address Prefix 42 | Subnet-1 172.16.0.0/12 43 | Subnet-2 10.0.0.0/8 44 | Subnet-4 192.168.0.0/26 45 | 46 | Dns Servers: Name Ip Address 47 | google 8.8.8.8 48 | google-2 8.8.4.4 49 | 50 | EOT 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vnet/set_virtual_network.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | Puppet::Face.define :azure_vnet, '1.0.0' do 8 | action :set do 9 | 10 | summary 'Set Network configures the virtual network' 11 | description <<-'EOT' 12 | The Set Network Configuration operation asynchronously configures the virtual network. 13 | EOT 14 | 15 | Puppet::VirtualNetwork.add_set_virtual_network_options(self) 16 | 17 | when_invoked do |options| 18 | Puppet::VirtualNetwork.initialize_env_variable(options) 19 | virtual_network_service = Azure::VirtualNetworkManagementService.new 20 | address_space = options[:address_space].split(',') 21 | optional = {} 22 | if options[:subnets] 23 | subnets = [] 24 | options[:subnets].split(',').each do |subnet| 25 | values = subnet.split(':') 26 | fail 'Missing argument subnet name or ip_address or cidr in subnet' if values.size != 3 27 | subnets << { name: values[0], ip_address: values[1], cidr: values[2] } 28 | end 29 | optional[:subnet] = subnets 30 | end 31 | if options[:dns_servers] 32 | dns = [] 33 | options[:dns_servers].split(',').each do |ds| 34 | values = ds.split(':') 35 | fail 'Missing argument dns name or ip_address in dns' if values.size != 2 36 | dns << { name: values[0], ip_address: values[1] } 37 | end 38 | optional[:dns] = dns 39 | end 40 | virtual_network_service.set_network_configuration( 41 | options[:virtual_network_name], 42 | options[:location], 43 | address_space, 44 | optional 45 | ) 46 | nil 47 | end 48 | 49 | returns 'None ' 50 | 51 | examples <<-'EOT' 52 | $ puppet azure_vnet set --management-certificate path-to-certificate \ 53 | --azure-subscription-id=YOUR-SUBSCRIPTION-ID \ 54 | --dns-servers 'google-1:8.8.8.8,google-2:8.8.4.4' \ 55 | --subnets 'subnet-1:172.16.0.0:12,subnet-2:192.168.0.0:29' \ 56 | --virtual-network-name v-net --location 'West US' \ 57 | --address-space '172.16.0.0/12,192.168.0.0/16' 58 | 59 | EOT 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vnet/set_xml_schema.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | Puppet::Face.define :azure_vnet, '1.0.0' do 7 | action :set_xml_schema do 8 | 9 | summary 'set_xml_schema Network configures the virtual network using xml schema' 10 | description <<-'EOT' 11 | The set_xml_schema Network Configuration operation asynchronously configures the virtual network. 12 | EOT 13 | 14 | Puppet::VirtualNetwork.add_set_xml_schema_options(self) 15 | 16 | when_invoked do |options| 17 | Puppet::VirtualNetwork.initialize_env_variable(options) 18 | virtual_network_service = Azure::VirtualNetworkManagementService.new 19 | virtual_network_service.set_network_configuration(options[:xml_schema_file]) 20 | nil 21 | end 22 | 23 | returns 'None ' 24 | 25 | examples <<-'EOT' 26 | $ puppet azure_vnet set --management-certificate path-to-azure-certificate \ 27 | --azure-subscription-id=YOUR-SUBSCRIPTION-ID --management-endpoint=https://management.database.windows.net:8443/ 28 | 29 | EOT 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/puppet/face/azure_vnet/views/virtual_networks.erb: -------------------------------------------------------------------------------- 1 | <%="Listing virtual networks".bold%> 2 | <%index=1%> 3 | <%vnets.each do |vnet|%> 4 | 5 | <%="Virtual Network: #{index}".bold%> 6 | <%="Server Name".fix(20)%>: <%=vnet.name %> 7 | <%="Address Space".fix(20)%>: <%=vnet.address_space.join(", ")%> 8 | 9 | <%="Subnets"%>: <%="Name".fix.bold%><%="Address Prefix".fix.bold%> 10 | <%vnet.subnets.each do |endpoint|%><%=endpoint[:name].fix%><%=endpoint[:address_prefix].to_s.fix%> 11 | <%end%> 12 | <%="Dns Servers"%>: <%="Name".fix.bold%><%="Ip Address".fix.bold%> 13 | <%vnet.dns_servers.each do |endpoint|%><%=endpoint[:name].fix%><%=endpoint[:ip_address].to_s.fix%> 14 | <%end%> <%index+=1%><%end%> 15 | -------------------------------------------------------------------------------- /lib/puppet/option_validation.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | module Puppet 8 | module OptionValidation 9 | def validate_bootstrap_options(options) 10 | if options[:ssh_user] && options[:winrm_user] 11 | os = nil 12 | elsif options[:ssh_user] 13 | os = 'Linux' 14 | elsif options[:winrm_user] 15 | os = 'Windows' 16 | end 17 | 18 | case os 19 | when 'Linux' 20 | case 21 | when options[:private_key_file].nil? && options[:password].nil? 22 | fail ArgumentError, 'Password or Private key is require for bootstrap.' 23 | end 24 | when 'Windows' 25 | case 26 | when options[:password].nil? 27 | fail ArgumentError, 'Password is require for windows vm bootstrap.' 28 | end 29 | else 30 | fail ArgumentError, 'Either winrm_user or ssh_user is required' 31 | end 32 | end 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/puppet/service_bus.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | module Puppet::ServiceBus 7 | 8 | class << self 9 | def initialize_env_variable(options) 10 | ENV['AZURE_SERVICEBUS_NAMESPACE'] = options[:sb_namespace] 11 | ENV['AZURE_SERVICEBUS_ACCESS_KEY'] = options[:sb_access_key] 12 | ENV["AZURE_STORAGE_ACCOUNT"] = options[:storage_account_name] 13 | ENV["AZURE_STORAGE_ACCESS_KEY"] = options[:storage_access_key] 14 | gem "azure", '=0.6.4' 15 | require 'azure' 16 | end 17 | 18 | def views(name) 19 | File.join(File.dirname(__FILE__), 'face/azure_servicebus/views', name) 20 | end 21 | 22 | def add_default_options(action) 23 | add_sb_namespace_option(action) 24 | add_sb_access_key_option(action) 25 | end 26 | 27 | def add_queue_default_options(action) 28 | add_storage_account_name_option(action) 29 | add_storage_access_key_option(action) 30 | end 31 | 32 | def add_servicebus_queue_options(action) 33 | add_default_options(action) 34 | add_queue_name_option(action) 35 | end 36 | 37 | def add_servicebus_topic_options(action) 38 | add_default_options(action) 39 | add_topic_name_option(action) 40 | end 41 | 42 | def add_create_queue_options(action) 43 | add_queue_default_options(action) 44 | add_queue_name_option(action) 45 | end 46 | 47 | def add_create_message_options(action) 48 | add_queue_default_options(action) 49 | add_queue_name_option(action) 50 | add_queue_message_option(action) 51 | end 52 | 53 | def add_sb_namespace_option(action) 54 | action.option '--sb-namespace=' do 55 | summary 'The azure service bus namespace.' 56 | description 'azure service bus namespace.' 57 | required 58 | end 59 | end 60 | 61 | def add_sb_access_key_option(action) 62 | action.option '--sb-access-key=' do 63 | summary 'The azure service bus access key.' 64 | description 'The azure service bus access key.' 65 | required 66 | end 67 | end 68 | 69 | def add_queue_name_option(action) 70 | action.option '--queue-name=' do 71 | summary 'Name of azure queue.' 72 | description 'Name of azure queue.' 73 | required 74 | end 75 | end 76 | 77 | def add_topic_name_option(action) 78 | action.option '--topic-name=' do 79 | summary 'Name of azure topic.' 80 | description 'Name of azure topic.' 81 | required 82 | end 83 | end 84 | 85 | def add_queue_message_option(action) 86 | action.option '--queue-message=' do 87 | summary 'Queue message' 88 | required 89 | end 90 | end 91 | 92 | def add_storage_account_name_option(action) 93 | action.option '--storage-account-name=' do 94 | summary 'The storage account name of Windows Azure portal.' 95 | description 'The storage account name of Windows Azure portal.' 96 | required 97 | end 98 | end 99 | 100 | def add_storage_access_key_option(action) 101 | action.option '--storage-access-key=' do 102 | summary 'The access key of storage account.' 103 | description 'The access key of storage account.' 104 | required 105 | end 106 | end 107 | 108 | end 109 | end 110 | -------------------------------------------------------------------------------- /lib/puppet/storage_account.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/core/utility' 7 | require 'puppet/application_config' 8 | include Puppet::ApplicationConfig 9 | 10 | module Puppet::StorageAccount 11 | class << self 12 | def views(name) 13 | File.join(File.dirname(__FILE__), 'face/azure_storage/views', name) 14 | end 15 | 16 | def add_create_options(action) 17 | add_default_options(action) 18 | add_affinity_group_name_option(action, true) 19 | add_location_option(action, true) 20 | add_storage_account_name_option(action) 21 | add_description_option(action) 22 | add_label_option(action) 23 | add_extended_properties_option(action) 24 | end 25 | 26 | def add_delete_options(action) 27 | add_default_options(action) 28 | add_storage_account_name_option(action) 29 | end 30 | 31 | def add_description_option(action) 32 | action.option '--description=' do 33 | summary 'Description of storage account' 34 | description 'Description of storage account' 35 | end 36 | end 37 | 38 | def add_label_option(action) 39 | action.option '--label=' do 40 | summary 'Label of storage account' 41 | description 'Label of storage account' 42 | end 43 | end 44 | 45 | def add_storage_account_name_option(action) 46 | action.option '--storage-account-name=' do 47 | summary 'The name of the storae account.' 48 | description 'The name of the storage account.' 49 | required 50 | before_action do |act, args, options| 51 | if act.name == :create && options[:location].nil? && options[:affinity_group_name].nil? 52 | fail ArgumentError, 'affinity group name or location is required.' 53 | end 54 | if options[:storage_account_name].empty? 55 | fail ArgumentError, 'Storage Account name is required.' 56 | end 57 | end 58 | end 59 | end 60 | 61 | def add_extended_properties_option(action) 62 | action.option '--extended-properties=' do 63 | summary 'Extended properties of storage account' 64 | description 'Extended properties of storage account' 65 | properties = {} 66 | before_action do |act, args, options| 67 | options[:extended_properties].split(',').each do |prop| 68 | values = prop.split(':') 69 | properties[values[0].to_sym] = values[1] if values.size == 2 70 | end 71 | options[:extended_properties] = properties 72 | end 73 | end 74 | end 75 | 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /lib/puppet/virtual_network.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'puppet/application_config' 7 | require 'puppet/core/utility' 8 | include Puppet::ApplicationConfig 9 | 10 | module Puppet::VirtualNetwork 11 | class << self 12 | def views(name) 13 | File.join(File.dirname(__FILE__), 'face/azure_vnet/views', name) 14 | end 15 | 16 | def add_set_virtual_network_options(action) 17 | add_default_options(action) 18 | add_virtual_network_name_option(action) 19 | add_location_option(action) 20 | add_address_space_option(action) 21 | add_subnet_option(action) 22 | add_dns_server_option(action) 23 | end 24 | 25 | def add_set_xml_schema_options(action) 26 | add_default_options(action) 27 | add_xml_schema_file_option(action) 28 | end 29 | 30 | def add_xml_schema_file_option(action) 31 | action.option '--xml-schema-file=' do 32 | summary 'Xml schema file path' 33 | description 'Xml schema file path of virtual network.' 34 | required 35 | before_action do |act, args, options| 36 | filepath = options[:xml_schema_file] 37 | validate_file(filepath, 'Network schema', ['xml']) 38 | end 39 | end 40 | end 41 | 42 | def add_virtual_network_name_option(action) 43 | action.option '--virtual-network-name=' do 44 | summary 'The virtual network name.' 45 | description 'Name of virtual network.' 46 | required 47 | before_action do |act, args, options| 48 | if options[:virtual_network_name].empty? 49 | fail ArgumentError, 'Virtual network name is required' 50 | end 51 | end 52 | end 53 | end 54 | 55 | def add_address_space_option(action) 56 | action.option '--address-space=' do 57 | summary 'The address space for virtual network.' 58 | description 'Address space for virtual network.' 59 | required 60 | before_action do |act, args, options| 61 | if options[:address_space].empty? 62 | fail ArgumentError, 'Virtual network address space is required' 63 | end 64 | end 65 | end 66 | end 67 | 68 | def add_subnet_option(action) 69 | action.option '--subnets=' do 70 | summary 'Subnet of virtual network.' 71 | description <<-EOT 72 | Contains the specification for the subnets that you want to create 73 | within the address space of your virtual network sites. 74 | EOT 75 | end 76 | end 77 | 78 | def add_dns_server_option(action) 79 | action.option '--dns-servers=' do 80 | summary 'Dns server for virtual network.' 81 | description 'Contains the collection of DNS servers.' 82 | end 83 | end 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /manifests/bootstrap.pp: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | class microsoftazure::bootstrap ( 7 | $puppet_master_ip, 8 | $node_ipaddress, 9 | $homedir = undef, 10 | $ssh_user = undef, 11 | $winrm_user = undef, 12 | $private_key_file = undef, 13 | $winrm_port = undef, 14 | $password = undef, 15 | $ssh_port = 22, 16 | $winrm_transport = 'http' 17 | ) { 18 | 19 | Exec { path => ['/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/'] } 20 | 21 | $cmd = "puppet azure_vm bootstrap --node-ipaddress ${node_ipaddress} --puppet-master-ip ${puppet_master_ip}" 22 | 23 | if ($ssh_user == undef) and ($winrm_user == undef) { 24 | fail('Please specify SSH User or Winrm User.') 25 | } 26 | 27 | if ($ssh_user != undef) and ($winrm_user != undef) { 28 | fail('Please specify either SSH User or Winrm User.') 29 | } 30 | 31 | if ($homedir == undef) and ($ssh_user != undef) { 32 | fail('home directory path is required for Linux VM bootstrap.') 33 | }elsif ($homedir != undef){ 34 | $export_home_dir = "export HOME=${homedir};" 35 | } 36 | 37 | if ($node_ipaddress == undef) { 38 | fail('Please specify IP address of VM to be provisioned.') 39 | } 40 | 41 | if $winrm_user != undef { 42 | $winrmu = "--winrm-user ${winrm_user}" 43 | } 44 | 45 | if $ssh_user != undef { 46 | $sshu = "--ssh-user ${ssh_user}" 47 | } 48 | 49 | if $password != undef { 50 | $passwd = "--password ${password}" 51 | } 52 | 53 | if $private_key_file != undef { 54 | $pkf = "--private-key-file ${private_key_file}" 55 | } 56 | 57 | if $winrm_port != undef { 58 | $wp = "--winrm-port ${winrm_port}" 59 | } 60 | 61 | if $ssh_port != undef { 62 | $ssp = "--ssh-port ${ssh_port}" 63 | } 64 | 65 | if $winrm_transport != undef { 66 | $wrmtp = "--winrm-transport ${winrm_transport}" 67 | } 68 | 69 | $puppet_command = "${export_home_dir} ${cmd} ${passwd} ${pkf} ${wp} ${ssp} ${wrmtp} ${winrmu} ${sshu}" 70 | 71 | exec {"Provisioning VM ${title}": 72 | command => "/bin/bash -c \"${puppet_command}\"", 73 | logoutput => true, 74 | timeout => 900 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /manifests/cloudservice.pp: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | class microsoftazure::cloudservice ( 7 | $azure_management_certificate, 8 | $azure_subscription_id, 9 | $cloud_service_name, 10 | $description = undef, 11 | $label = undef, 12 | $location = undef, 13 | $affinity_group_name = undef 14 | ) { 15 | 16 | Exec { path => ['/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/'] } 17 | 18 | $cmd = "puppet azure_cloudservice create --cloud-service-name ${cloud_service_name} --management-certificate ${azure_management_certificate} --azure-subscription-id ${azure_subscription_id}" 19 | 20 | if $azure_management_certificate == undef { 21 | fail('Specify azure management certificate path.') 22 | } 23 | 24 | if $azure_subscription_id == undef { 25 | fail('Specify subscription id.') 26 | } 27 | 28 | if $cloud_service_name == undef { 29 | fail('Cloud service name is not specified for creating cloud service.') 30 | } 31 | 32 | if $label != undef { 33 | $lbl = "--label ${label}" 34 | } 35 | 36 | if $description != undef { 37 | $desc = "--description ${description}" 38 | } 39 | 40 | if $affinity_group_name != undef { 41 | $agn = "--affinity-group-name ${affinity_group_name}" 42 | } 43 | 44 | if $cloud_service_name != undef { 45 | $csn = "--cloud-service-name ${cloud_service_name}" 46 | } 47 | 48 | if $location != undef { 49 | $loc = "--location '${location}'" 50 | } 51 | 52 | $puppet_command = "${cmd} ${lbl} ${desc} ${csn} ${agn} ${loc}" 53 | 54 | if !defined( Package['azure'] ) { 55 | package { 'azure': 56 | ensure => '0.6.4', 57 | provider => 'gem', 58 | } 59 | } 60 | 61 | exec {"Cloud service": 62 | command => $puppet_command, 63 | logoutput => true, 64 | } 65 | 66 | Package['azure'] -> Exec['Cloud service'] 67 | 68 | } 69 | -------------------------------------------------------------------------------- /manifests/db.pp: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | class microsoftazure::db ( 7 | $azure_management_certificate, 8 | $azure_subscription_id, 9 | $login, 10 | $password, 11 | $location 12 | ) { 13 | 14 | Exec { path => ['/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/'] } 15 | 16 | $puppet_command = "puppet azure_sqldb create --login ${login} --management-certificate ${azure_management_certificate} --azure-subscription-id ${azure_subscription_id} --password ${password} --location '${location}'" 17 | 18 | if $azure_management_certificate == undef { 19 | fail('Specify azure management certificate path.') 20 | } 21 | 22 | if $azure_subscription_id == undef { 23 | fail('Specify subscription id.') 24 | } 25 | 26 | if $login == undef { 27 | fail('No login specified for provisioning VM.') 28 | } 29 | 30 | if $password == undef { 31 | fail('No password specified for provisioning VM.') 32 | } 33 | 34 | if $location == undef { 35 | fail('No location specified for provisioning VM.') 36 | } 37 | 38 | if !defined( Package['azure'] ) { 39 | package { 'azure': 40 | ensure => '0.6.4', 41 | provider => 'gem', 42 | } 43 | } 44 | 45 | exec {"SQL database": 46 | command => $puppet_command, 47 | logoutput => true 48 | } 49 | 50 | Package['azure'] -> Exec['SQL database'] 51 | } 52 | -------------------------------------------------------------------------------- /manifests/storage.pp: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | class microsoftazure::storage ( 7 | $azure_management_certificate, 8 | $azure_subscription_id, 9 | $storage_account_name, 10 | $description = undef, 11 | $label = undef, 12 | $location = undef, 13 | $affinity_group_name = undef 14 | ) { 15 | 16 | Exec { path => ['/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/'] } 17 | 18 | $cmd = "puppet azure_storage create --storage-account-name ${storage_account_name} --management-certificate ${azure_management_certificate} --azure-subscription-id ${azure_subscription_id}" 19 | 20 | if $azure_management_certificate == undef { 21 | fail('Specify azure management certificate path.') 22 | } 23 | 24 | if $azure_subscription_id == undef { 25 | fail('Specify subscription id.') 26 | } 27 | 28 | if $storage_account_name == undef { 29 | fail('Storage account name is not specified for storage account.') 30 | } 31 | 32 | if $label != undef { 33 | $lbl = "--label ${label}" 34 | } 35 | 36 | if $description != undef { 37 | $desc = "--description ${description}" 38 | } 39 | 40 | if $affinity_group_name != undef { 41 | $agn = "--affinity-group-name ${affinity_group_name}" 42 | } 43 | 44 | if $storage_account_name != undef { 45 | $sac = "--storage-account-name ${storage_account_name}" 46 | } 47 | 48 | if $location != undef { 49 | $loc = "--location '${location}'" 50 | } 51 | 52 | $puppet_command = "${cmd} ${lbl} ${desc} ${sac} ${agn} ${loc}" 53 | 54 | if !defined( Package['azure'] ) { 55 | package { 'azure': 56 | ensure => '0.6.4', 57 | provider => 'gem', 58 | } 59 | } 60 | 61 | exec {"Storage Account": 62 | command => $puppet_command, 63 | logoutput => true, 64 | } 65 | 66 | Package['azure'] -> Exec['Storage Account'] 67 | 68 | } 69 | -------------------------------------------------------------------------------- /manifests/vm.pp: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | class microsoftazure::vm ( 7 | $vm_name, 8 | $vm_user, 9 | $image, 10 | $location, 11 | $azure_subscription_id, 12 | $azure_management_certificate, 13 | $homedir = undef, 14 | $vm_size = 'Small', 15 | $puppet_master_ip = undef, 16 | $private_key_file = undef, 17 | $certificate_file = undef , 18 | $storage_account_name = undef, 19 | $cloud_service_name = undef, 20 | $availability_set_name = undef, 21 | $password = undef, 22 | $add_role = 'false' 23 | ) { 24 | 25 | Exec { path => ['/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/'] } 26 | if $add_role == 'true' { 27 | $cmd = "puppet azure_vm add_role --vm-user ${vm_user} --management-certificate ${azure_management_certificate} --azure-subscription-id ${azure_subscription_id} --image ${image} --vm-name ${vm_name}" 28 | }else{ 29 | $cmd = "puppet azure_vm create --vm-user ${vm_user} --management-certificate ${azure_management_certificate} --azure-subscription-id ${azure_subscription_id} --image ${image} --vm-name ${vm_name} --location '${location}'" 30 | } 31 | if $vm_name == undef { 32 | fail('No vm_name specified for provisioning VM.') 33 | } 34 | 35 | if $vm_user == undef { 36 | fail('No vm_user specified for provisioning VM.') 37 | } 38 | 39 | if $image == undef { 40 | fail('No image specified for provisioning VM.') 41 | } 42 | 43 | if $location == undef { 44 | fail('No location specified for provisioning VM.') 45 | } 46 | 47 | if ($cloud_service_name == undef) and ($add_role == 'true') { 48 | fail('No cloud service name specified for add role.') 49 | } 50 | 51 | if ($homedir == undef) and ($puppet_master_ip != undef) { 52 | fail('Specify home directory path.') 53 | }elsif ($homedir != undef){ 54 | $export_home_dir = "export HOME=${homedir}; " 55 | } 56 | 57 | if $azure_management_certificate == undef { 58 | fail('Specify azure management certificate path.') 59 | } 60 | 61 | if $azure_subscription_id == undef { 62 | fail('Specify subscription id.') 63 | } 64 | 65 | if $puppet_master_ip != undef { 66 | $pmi = "--puppet-master-ip ${puppet_master_ip}" 67 | } 68 | 69 | if $password != undef { 70 | $passwd = "--password ${password}" 71 | } 72 | 73 | if $storage_account_name != undef { 74 | $san = " --storage-account-name ${storage_account_name}" 75 | } 76 | 77 | if $certificate_file != undef { 78 | $crtf = "--certificate-file ${certificate_file}" 79 | } 80 | 81 | if $private_key_file != undef { 82 | $pkf = "--private-key-file ${private_key_file}" 83 | } 84 | 85 | if $cloud_service_name != undef { 86 | $csn = "--cloud-service-name ${cloud_service_name}" 87 | } 88 | 89 | if $availability_set_name != undef { 90 | $asn = "--availability-set-name ${availability_set_name}" 91 | } 92 | 93 | $puppet_command = "${export_home_dir} ${cmd} ${pmi} ${passwd} ${san} ${crtf} ${pkf} ${csn} ${asn}" 94 | 95 | if !defined( Package['azure'] ) { 96 | package { 'azure': 97 | ensure => '0.6.4', 98 | provider => 'gem', 99 | } 100 | } 101 | 102 | exec {"Provisioning VM": 103 | command => "/bin/bash -c \"${puppet_command}\"", 104 | logoutput => true, 105 | timeout => 900 106 | } 107 | 108 | Package['azure'] -> Exec['Provisioning VM'] 109 | } 110 | -------------------------------------------------------------------------------- /manifests/vnet.pp: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | class microsoftazure::vnet ( 7 | $azure_management_certificate, 8 | $azure_subscription_id, 9 | $virtual_network_name, 10 | $affinity_group_name, 11 | $address_space, 12 | $subnets = undef, 13 | $dns_servers = undef 14 | ) { 15 | 16 | Exec { path => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'] } 17 | 18 | if !defined( Package['azure'] ) { 19 | package { 'azure': 20 | ensure => '0.6.4', 21 | provider => 'gem', 22 | } 23 | } 24 | 25 | if $virtual_network_name == undef { 26 | fail('No virtual network name specified for virtual network.') 27 | } 28 | 29 | if $affinity_group_name == undef { 30 | fail('No affinity group name specified for virtual network.') 31 | } 32 | 33 | if $address_space == undef { 34 | fail('No address space specified for virtual network.') 35 | }else { 36 | $addr_spc_val = inline_template("<%=(@address_space).join(',')%>") 37 | } 38 | 39 | if $subnets != undef { 40 | $subnet_values = inline_template("<% values=[] %><% @subnets.each do |x| %><% values << x.values.join(':') %><% end %><%= values.join(',') %>") 41 | $snet = "--subnets '${subnet_values}'" 42 | } 43 | 44 | if $dns_servers != undef { 45 | $dns_values = inline_template("<% values=[] %><% @dns_servers.each do |x| %><% values << x.values.join(':') %><% end %><%= values.join(',') %>") 46 | $dns = "--dns-servers '${dns_values}'" 47 | } 48 | 49 | $cmd = "puppet azure_vnet set --virtual-network-name ${virtual_network_name} --management-certificate ${azure_management_certificate} --azure-subscription-id ${azure_subscription_id} --affinity-group-name ${affinity_group_name} --address-space '${addr_spc_val}' " 50 | 51 | $puppet_command = "${cmd} ${dns} ${snet}" 52 | 53 | exec {"Creating virtual network": 54 | command => $puppet_command, 55 | logoutput => true 56 | } 57 | 58 | Package['azure'] -> Exec['Creating virtual network'] 59 | } -------------------------------------------------------------------------------- /spec/fixtures/certificate.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDXTCCAkWgAwIBAgIJANykirZF/EsgMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV 3 | BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm4ldCBX 4 | aWRnaXRzIFB0eSBMdGQwHhcNMTMwNTIwMDkxNzI4WhcNMTQwNTIwMDkxNzI4WjBF 5 | MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 6 | ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB 7 | CgKCAQEAvbyc1P9OVJmlvFLHLhoIAn0lZaJ5BhA5Y4xjVxTdSrbvfPuhifN0fZFx 8 | W5r/emW2IS9+eMkjTB6HuEMHU818At16TXTSIUiD6zjUs5a4zGbuOnfZXhmSgjqZ 9 | FfjpoOpq8BJwNymPyW8bjSzj/FFOxeQ1prIA8listYqm0cKMXYrxHzEm9mfNsiQO 10 | ZdR6AGPgBmBtgi2SgBRo5peidSHOWt1Hq09L4b8CvQhCunSMQaQbjaS4PEEiyAAy 11 | pNQwtlkbHxfae4pY4mcNqaXisOIT/OFbF3ipBJZj0GsrdTw5aKBCa4+v4MrlHpIY 12 | 0IGEst9VusNaHsgZ9fDo2AuHJxYYPwIDAQABo1AwTjAdBgNVHQ4EFgQUMe+pjlnP 13 | u45jWWGwDBHj/glY5+QwHwYDVR0jBBgwFoAUMe+pjlnPu45jWWGwDBHj/glY5+Qw 14 | DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAMIHvO+LuVq/e5Fesr6Q7 15 | p6PSyth4pfVLfx3tKosvfEzGmdVB7yryx4oVPVUygkmZyHwXqkgU0+k5QH2L0SjF 16 | fYS/T9RAke3zAHQ31O97aMj7ourjvOXwa87K4g8d/4y75zBewxtga51MZbZEguNy 17 | Edi/eyM7OuU1LFmoNyc0fakq0tBn68J3bDaNvCskptBASXvIGhlUNq1RT3agbGml 18 | f8x9SuJofXtqDACgLDQMUGrCWqklMhZohuApMg07Q4bIz/BhXhKETab55gGFX+Ow 19 | lroGwF29OCyUvpxWmXmcYxmFNlkVOuol6wJWKoeaGc1JphmyvbmS8qaeqgqxFTkP 20 | kw== 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /spec/fixtures/invalid_file.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/azure-puppet/2170f8ba0c79f13208c72e7f3850da69428a0053/spec/fixtures/invalid_file.txt -------------------------------------------------------------------------------- /spec/fixtures/management_certificate.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICZTCCAc6gAwIBAwIBADANBgkqhkiG9w0BAQUFADAnMSUwIwYDVQQDDBxBenVy 3 | ZSBNYW5hZ2VtZW50IENlcnRpZmljYXRlMB4XDTcwMDEwMTAwMDAwMFoXDTM4MDEx 4 | OTAzMTQwN1owJzElMCMGA1UEAwwcQXp1cmUgTWFuYWdlbWVudCBDZXJ0aWZpY2F0 5 | ZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAvPZH7xOgBM69PjoOeKdAVY6r 6 | u6Nfp6kPVgPIMJYcgQRFqwqiKvwCHWdCeRmqKGc29yBEo1CTQUcwdJf1gxhRufQI 7 | fO+P+fYIgqoQUikZvEigkqSXdrV1FSkqiQ9FIpwBspEdEgK4JFEt/ztD2btM8Bxb 8 | S0i7HwERIh3dTEEAuI0CAwEAAaOBoDCBnTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIF 9 | IDAdBgNVHQ4EFgQUCE08cCIKtq+KpPDz96Q/0W5zzNQwEwYDVR0lBAwwCgYIKwYB 10 | BQUHAwEwTwYDVR0jBEgwRoAUCE08cCIKtq+KpPDz96Q/0W5zzNShK6QpMCcxJTAj 11 | BgNVBAMMHEF6dXJlIE1hbmFnZW1lbnQgQ2VydGlmaWNhdGWCAQAwDQYJKoZIhvcN 12 | AQEFBQADgYEAsVVj7BEzTbPWBucf2OI0jHMalJ8jvq4VN7XNfX+r/tK/BthwedM0 13 | dYpRwa1fRUzyLk9yxmvpWIN68OOad+YB3+AiI+pB2NeV3ocJNM1fMSSMkEaRiUvl 14 | DKpuHMXOEpKyBNW+b+ah5EQoGj49tsLVQ+Fb8vhrUcuseOKy8CiUAic= 15 | -----END CERTIFICATE----- 16 | -----BEGIN RSA PRIVATE KEY----- 17 | MIICWwIBAAKBgQC89kfvE6AEzr0+Og54p0BVjqu7o1+nqQ9WA8gwlhyBBEWrCqIq 18 | /AIdZ0J5GaooZzb3IESjUJNBRzB0l/WDGFG59Ah874/59giCqhBSKRm8SKCSpJd2 19 | tXUVKSqJD0UinAGykR0SArgkUS3/O0PZu0zwHFtLSLsfAREiHd1MQQC4jQIDAQAB 20 | AoGAcFpjRQS/NXyTSweMCTMw7m4pMCUgv/imdLdE9Zablh6rKdrlt3cl7sOx431e 21 | Di3ooaGfDhffpoWkiv67bNot5MRl+KZwUIFKzyrl3G3zdc9XxtlwlPyEJR/RBGxu 22 | YdWw78eFF/EQ5OwDyE6nIttdYtE8GgiKSaDdRaiyHZdp/AECQQDdJPyydCLZa01H 23 | 0ZAj4J9yp7aoimAfz5/pab9Hrn8ILTwZY45lFkdPVKe4+UHKhCSXgAmJm6JAA0WZ 24 | NpwypjMBAkEA2r7BqcwmkV4438qLhQy6xZOyypeFdchYY4Yh98PZgeBlkUgPQmni 25 | ICZ0U8MaolWdT3p/QQyQymPp+RmQHGOhjQJAW1cUnKzFXCIqyFgxffAgS54kHtcQ 26 | vvLl7OXFoNjdFUaBxUbOoMgj6gtgP1GMsBYGeyDiT5kd2ezACXl56J2nAQJAKFwh 27 | 525ff1rfK4t3iqj6nRHPX0ntufmpNVO+WLSuISSCGPguuJZIvp3ZwMqy01jwmYWE 28 | jUAARxeASBHLYTGQ0QJAQXSTYMBj/0bha+JE9gV1X+Ui5v6p3xsA++mqCPwFv0wP 29 | VVJZapkcxfmALj8edsxrnXDkdbayA2XjzNQht+dApw== 30 | -----END RSA PRIVATE KEY----- 31 | -------------------------------------------------------------------------------- /spec/fixtures/private_key.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC9vJzU/05UmaW8 3 | UscuGggCfSVm0nkGEDljjGNXFN1Ktu98+6GJ83R9kXFbmv96ZbYhL354ySNMHoe4 4 | QwdTzXwC3XpNdNIhSIPrONSzlrjMZu46d9leGZKCOpkV+Omg6mrwEnA3KY/JbxuN 5 | LOP8UU7F5DWmsgDyWKy1iqbRwoxdivEfMSb2Z82yJA5l1HoAY+AGYG2CLZKAFGjm 6 | l6J1Ic5a3UerT0vhvwK9CEK6dIxBpBuNpLg8QSLIADKk1DC2WRsfF9p7ilDiZw3p 7 | peKw4hP84VsXeKkElmPQayt1PDlooEJrj6/gyuUekhjQgYSy31W6w1oeyBn18OjY 8 | C4cnFhg/AgMBAAECggEAW33B2mup592XL7Jy3WYsCpcyG9zOAwB7y+b8WBd1hfuk 9 | jA4CnTTKLWqe0N9y5iB5rJLsV24WGTR3mYCo3d4uOGt3+DWmxenjwt9KobbCMb5I 10 | jeUQ6fFG1olPHGtErRWcr1sUxWTDMwziqjbEUPwcEgyzWkhncHUWAwxy2J8JdGkg 11 | mVBz6wubaFiO6MHAa1eHV/et1tLKRRpAc2/vrJpc4wcvu23CgM2rC+W7GggufH0z 12 | rVKhNTKklTm3K/2tZfgpAyzi7L/3KPVjEUysyCSEwaoY6nXIFC7E16JlPBa0HS9U 13 | 9yPxDqvE1EAZUdWUtF5FNvaohl4an8M85PgEV6OxIQKBgQDlPvIj4gSnbkv7VLSA 14 | 5TEdcJBJbTJDsyNWgUUmFZeCo7KtpXc0g2B0fKuBaJi5KiLpfkaNgUVMF5UyOIKO 15 | 1m0Yv+B+PMkVfUoYgWZ1YSF169nR/CB5sq496a1W+Qx2KxMlyl98MU7Q6rOPJ+KE 16 | qXuZLdt38OwS2inYhb3n0daSmQKBgQDT4UZGyjAxK0RCCmVaxrlbTf/rtn1InMld 17 | lulxRVNs5q9Rd64U0gfQY7UsxSNi5xS1e36EW8jvbg3fRvevvvziHsBTueEJSty8 18 | EuFLq6tSRj6VZjS7SPkSAKuMNM2g5OasK9E1+yvisM7LGNubCXJOGEGH1Mx7hX5Y 19 | mEEBytaglwKBgHE//28qoRH1syOeXO2wS+s3SJB9mW9IeBSsF/UQhaDMLeEK9TDE 20 | Fkp1rGRpv8h7SHQBJemSCyHkJJiCwjy+QXcQk17JuK0dEBW7F1q1eUpAEYNjAsgc 21 | NWfwoOlub3GRJgxtRW6dDUq4J6x5D7Zp491wghNmubk2faWxrHdxeodBAoGAMwDn 22 | ieLh9vQTWlJmU5PCytfb40HqprAXSRAq4blue6iMS3Aj1583glJ+KmjKO+Skd4ti 23 | yTnPBNPZQwYyWXwAI+6DHaSBJ1t+B0gEM9L/Sq7eIdiYmPzX+B1xLi8H0NNJM+jY 24 | U8ZCqi8lmH5DXu7HNUVhgPEYyCM6Ztk/zM6nG8ECgYAV3/2k/9T7TVgdEMV0wPEu 25 | +neVz7rdeSGOa56ThFSQRRvxADRSeqzmLkW1HcvSZzkiSa0LAYEnXlbPApzO+FL2 26 | uJ+dD7akMYTZx3lo2bLz0jYQkIwsh1L4+bymqJEa7AN0A+Gfqnxo7lgbUOXzExGI 27 | mH4F7Y5/CEE9TsYdKYDXAA== 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /spec/fixtures/vnet_schema.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 172.16.0.0/12 13 | 10.0.0.0/8 14 | 192.168.0.0/24 15 | 16 | 17 | 18 | 172.16.0.0/12 19 | 20 | 21 | 10.0.0.0/8 22 | 23 | 24 | 192.168.0.0/26 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | require 'puppet' 9 | require 'puppet/face' 10 | require 'azure' 11 | require 'mocha/api' 12 | gem 'rspec', '>=2.0.0' 13 | 14 | Dir['./spec/support/**/*.rb'].sort.each { |f| require f } 15 | 16 | RSpec.configure do |config| 17 | config.mock_with :mocha 18 | 19 | config.after :each do 20 | Puppet.settings.clear 21 | Puppet::Node::Environment.clear 22 | Puppet::Util::Storage.clear 23 | Puppet::Util::Log.close_all 24 | end 25 | 26 | config.before :each do 27 | $puppet_application_mode = nil 28 | $puppet_application_name = nil 29 | Puppet[:confdir] = '/dev/null' 30 | Puppet[:vardir] = '/dev/null' 31 | Puppet.settings[:bindaddress] = '127.0.0.1' 32 | @logs = [] 33 | Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(@logs)) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /spec/support/credential_validation.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | 8 | shared_examples 'validate authentication credential' do |service_method| 9 | describe '(management_certificate)' do 10 | it 'should require a management_certificate' do 11 | @options.delete(:management_certificate) 12 | expect { subject.send(service_method, @options) }.to raise_error( 13 | ArgumentError, 14 | /required: management_certificate/ 15 | ) 16 | end 17 | 18 | it 'management_certificate doesn\'t exist' do 19 | @options[:management_certificate] = 'FileNotExist' 20 | expect { subject.send(service_method, @options) }.to raise_error( 21 | ArgumentError, 22 | /Could not find file 'FileNotExist'/ 23 | ) 24 | end 25 | 26 | it 'management_certificate extension is not valid' do 27 | file_path = File.expand_path('spec/fixtures/invalid_file.txt') 28 | @options[:management_certificate] = file_path 29 | expect { subject.send(service_method, @options) }.to raise_error( 30 | RuntimeError, 31 | /Management certificate expects a .pem or .pfx file/ 32 | ) 33 | end 34 | end 35 | 36 | describe '(azure_subscription_id)' do 37 | it 'should require a azure_subscription_id' do 38 | @options.delete(:azure_subscription_id) 39 | expect { subject.send(service_method, @options) }.to raise_error( 40 | ArgumentError, 41 | /required: azure_subscription_id/ 42 | ) 43 | end 44 | end 45 | 46 | describe '(management_endpoint)' do 47 | it 'management_endpoint should be optional' do 48 | @options.delete(:management_endpoint) 49 | expect { subject.send(service_method, @options) }.to_not raise_error 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_affinitygroup/create_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_affinitygroup, :current] do 10 | let(:base_service) { Azure::BaseManagementService } 11 | before :each do 12 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 13 | @options = { 14 | management_certificate: mgmtcertfile, 15 | azure_subscription_id: 'Subscription-id', 16 | management_endpoint: 'management.core.windows.net', 17 | affinity_group_name: 'ag-name', 18 | location: 'West US', 19 | label: 'Affinity group label', 20 | description: 'Affinity group Description' 21 | } 22 | Azure.configure do |config| 23 | config.management_certificate = @options[:management_certificate] 24 | config.subscription_id = @options[:azure_subscription_id] 25 | end 26 | 27 | end 28 | 29 | describe 'option validation' do 30 | before :each do 31 | base_service.any_instance.stubs(:create_affinity_group).with( 32 | any_parameters 33 | ) 34 | end 35 | 36 | describe 'valid options' do 37 | it 'should not raise any exception' do 38 | expect { subject.create(@options) }.to_not raise_error 39 | end 40 | end 41 | 42 | describe '(affinity_group_name)' do 43 | it 'should validate the affinity group name' do 44 | @options.delete(:affinity_group_name) 45 | expect { subject.create(@options) }.to raise_error( 46 | ArgumentError, 47 | /required: affinity_group_name/ 48 | ) 49 | end 50 | end 51 | 52 | describe '(location)' do 53 | it 'should validate the location' do 54 | @options.delete(:location) 55 | expect { subject.create(@options) }.to raise_error( 56 | ArgumentError, 57 | /required: location/ 58 | ) 59 | end 60 | end 61 | 62 | describe '(label)' do 63 | it 'should validate cloud service name' do 64 | @options.delete(:label) 65 | expect { subject.create(@options) }.to raise_error( 66 | ArgumentError, 67 | /required: label/ 68 | ) 69 | end 70 | end 71 | 72 | it_behaves_like 'validate authentication credential', :create 73 | end 74 | 75 | describe 'optional parameter validation' do 76 | before :each do 77 | base_service.any_instance.stubs(:create_affinity_group).with( 78 | any_parameters 79 | ) 80 | end 81 | 82 | describe '(description)' do 83 | it 'description should be optional' do 84 | @options.delete(:description) 85 | expect { subject.create(@options) }.to_not raise_error 86 | end 87 | end 88 | end 89 | 90 | end 91 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_affinitygroup/delete_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | require 'spec_helper' 3 | 4 | describe Puppet::Face[:azure_affinitygroup, :current] do 5 | let(:base_service) { Azure::BaseManagementService } 6 | let(:affinity_group) do 7 | Azure::BaseManagement::AffinityGroup.new do |ag| 8 | ag.name = 'AG1' 9 | ag.label = 'Label' 10 | ag.description = 'Description' 11 | ag.capability = %w(PersistentVMRole HighMemory) 12 | end 13 | end 14 | 15 | before :each do 16 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 17 | @options = { 18 | management_certificate: mgmtcertfile, 19 | management_endpoint: 'management.core.windows.net', 20 | azure_subscription_id: 'Subscription-id', 21 | affinity_group_name: 'ag-name' 22 | } 23 | Azure.configure do |config| 24 | config.management_certificate = @options[:management_certificate] 25 | config.subscription_id = @options[:azure_subscription_id] 26 | end 27 | end 28 | 29 | describe 'option validation' do 30 | before :each do 31 | base_service.any_instance.stubs(:delete_affinity_group) 32 | end 33 | describe 'valid options' do 34 | it 'should not raise any exception' do 35 | expect { subject.delete(@options) }.to_not raise_error 36 | end 37 | end 38 | 39 | describe '(affinity_group_name)' do 40 | it 'should validate the affinity group name' do 41 | @options.delete(:affinity_group_name) 42 | expect { subject.delete(@options) }.to raise_error( 43 | ArgumentError, 44 | /required: affinity_group_name/ 45 | ) 46 | end 47 | end 48 | 49 | it_behaves_like 'validate authentication credential', :delete 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_affinitygroup/list_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | require 'spec_helper' 3 | 4 | describe Puppet::Face[:azure_affinitygroup, :current] do 5 | let(:base_service) { Azure::BaseManagementService } 6 | let(:affinity_group) do 7 | Azure::BaseManagement::AffinityGroup.new do |ag| 8 | ag.name = 'AG1' 9 | ag.label = 'Label' 10 | ag.description = 'Description' 11 | ag.capability = %w(PersistentVMRole HighMemory) 12 | end 13 | end 14 | 15 | before :each do 16 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 17 | @options = { 18 | management_certificate: mgmtcertfile, 19 | management_endpoint: 'management.core.windows.net', 20 | azure_subscription_id: 'Subscription-id' 21 | } 22 | Azure.configure do |config| 23 | config.management_certificate = @options[:management_certificate] 24 | config.subscription_id = @options[:azure_subscription_id] 25 | end 26 | end 27 | 28 | describe 'option validation' do 29 | before :each do 30 | base_service.any_instance.stubs( 31 | :list_affinity_groups 32 | ).returns([affinity_group]) 33 | end 34 | describe 'valid options' do 35 | it 'should not raise any exception' do 36 | expect { subject.list(@options) }.to_not raise_error 37 | end 38 | 39 | it 'should print affinity groups details' do 40 | affinity_groups = subject.list(@options) 41 | name = "#{'Name'.fix(20)}: #{affinity_group.name}" 42 | expect(affinity_groups).to match(/#{name}/) 43 | label = "#{'Label'.fix(20)}: #{affinity_group.label}" 44 | expect(affinity_groups).to match(/#{label}/) 45 | capability = "#{'Capability'.fix(20)}: #{affinity_group.capability}" 46 | expect(affinity_groups).to match(/#{capability}/) 47 | end 48 | end 49 | 50 | it_behaves_like 'validate authentication credential', :list 51 | 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_affinitygroup/update_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_affinitygroup, :current] do 10 | let(:base_service) { Azure::BaseManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | management_endpoint: 'management.core.windows.net', 17 | azure_subscription_id: 'Subscription-id', 18 | affinity_group_name: 'ag-name', 19 | label: 'Label', 20 | description: 'Affinity group Description' 21 | } 22 | Azure.configure do |config| 23 | config.management_certificate = @options[:management_certificate] 24 | config.subscription_id = @options[:azure_subscription_id] 25 | end 26 | end 27 | 28 | describe 'option validation' do 29 | 30 | describe 'valid options' do 31 | before :each do 32 | base_service.any_instance.stubs(:update_affinity_group).with( 33 | any_parameters 34 | ) 35 | end 36 | it 'should not raise any exception' do 37 | expect { subject.update(@options) }.to_not raise_error 38 | end 39 | 40 | it_behaves_like 'validate authentication credential', :update 41 | end 42 | 43 | describe '(affinity_group_name)' do 44 | it 'should validate the affinity group name' do 45 | @options.delete(:affinity_group_name) 46 | expect { subject.update(@options) }.to raise_error( 47 | ArgumentError, 48 | /required: affinity_group_name/ 49 | ) 50 | end 51 | end 52 | 53 | describe '(label)' do 54 | it 'should validate the label' do 55 | @options.delete(:label) 56 | expect { subject.update(@options) }.to raise_error( 57 | ArgumentError, 58 | /required: label/ 59 | ) 60 | end 61 | end 62 | 63 | end 64 | 65 | describe 'optional parameter validation' do 66 | before :each do 67 | base_service.any_instance.stubs(:update_affinity_group).with( 68 | any_parameters 69 | ) 70 | end 71 | describe '(description)' do 72 | it 'description should be optional' do 73 | @options.delete(:description) 74 | expect { subject.update(@options) }.to_not raise_error 75 | end 76 | end 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_cloudservice/create_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_cloudservice, :current] do 10 | let(:cloud_service) { Azure::CloudServiceManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | cloud_service_name: 'cloud-name', 18 | location: 'west us', 19 | description: 'Some description', 20 | label: 'label', 21 | affinity_group_name: 'ag-1' 22 | } 23 | Azure.configure do |config| 24 | config.management_certificate = @options[:management_certificate] 25 | config.subscription_id = @options[:azure_subscription_id] 26 | end 27 | cloud_service.any_instance.stubs( 28 | :create_cloud_service 29 | ).with(anything, anything) 30 | end 31 | 32 | describe 'option validation' do 33 | describe 'valid options' do 34 | it 'should not raise any exception' do 35 | expect { subject.create(@options) }.to_not raise_error 36 | end 37 | end 38 | 39 | describe '(cloud_service_name)' do 40 | it 'should validate cloud service name' do 41 | @options.delete(:cloud_service_name) 42 | expect { subject.create(@options) }.to raise_error( 43 | ArgumentError, 44 | /required: cloud_service_name/ 45 | ) 46 | end 47 | end 48 | 49 | describe '(location)' do 50 | it 'should validate the cloud service location or affinity group' do 51 | @options.delete(:location) 52 | @options.delete(:affinity_group_name) 53 | expect { subject.create(@options) }.to raise_error( 54 | ArgumentError, 55 | /affinity group name or location is required/ 56 | ) 57 | end 58 | 59 | it 'should not raise any exception when only location is given' do 60 | @options.delete(:affinity_group_name) 61 | expect { subject.create(@options) }.to_not raise_error 62 | end 63 | 64 | it 'should not raise any exception when only affinity group is given' do 65 | @options.delete(:location) 66 | expect { subject.create(@options) }.to_not raise_error 67 | end 68 | end 69 | 70 | describe '(description)' do 71 | it 'should validate the cloud service description' do 72 | @options.delete(:description) 73 | expect { subject.create(@options) }.to_not raise_error 74 | end 75 | end 76 | 77 | describe '(label)' do 78 | it 'should validate the cloud service label' do 79 | @options.delete(:label) 80 | expect { subject.create(@options) }.to_not raise_error 81 | end 82 | end 83 | 84 | it_behaves_like 'validate authentication credential', :create 85 | 86 | end 87 | end 88 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_cloudservice/delete_deployment_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_cloudservice, :current] do 10 | let(:cloud_service) { Azure::CloudServiceManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | cloud_service_name: 'cloud-name' 18 | } 19 | Azure.configure do |config| 20 | config.management_certificate = @options[:management_certificate] 21 | config.subscription_id = @options[:azure_subscription_id] 22 | end 23 | cloud_service.any_instance.stubs( 24 | :delete_cloud_service_deployment 25 | ).with(anything) 26 | end 27 | 28 | describe 'option validation' do 29 | describe 'valid options' do 30 | it 'should not raise any exception' do 31 | expect { subject.delete_deployment(@options) }.to_not raise_error 32 | end 33 | end 34 | 35 | describe '(cloud_service_name)' do 36 | it 'should validate cloud service name' do 37 | @options.delete(:cloud_service_name) 38 | expect { subject.delete_deployment(@options) }.to raise_error( 39 | ArgumentError, 40 | /required: cloud_service_name/ 41 | ) 42 | end 43 | end 44 | 45 | it_behaves_like 'validate authentication credential', :delete_deployment 46 | 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_cloudservice/delete_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_cloudservice, :current] do 10 | let(:cloud_service) { Azure::CloudServiceManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | cloud_service_name: 'cloud-name' 18 | } 19 | Azure.configure do |config| 20 | config.management_certificate = @options[:management_certificate] 21 | config.subscription_id = @options[:azure_subscription_id] 22 | end 23 | cloud_service.any_instance.stubs(:delete_cloud_service).with(anything) 24 | end 25 | 26 | describe 'option validation' do 27 | describe 'valid options' do 28 | it 'should not raise any exception' do 29 | expect { subject.delete(@options) }.to_not raise_error 30 | end 31 | end 32 | 33 | describe '(cloud_service_name)' do 34 | it 'should validate cloud service name' do 35 | @options.delete(:cloud_service_name) 36 | expect { subject.delete(@options) }.to raise_error( 37 | ArgumentError, 38 | /required: cloud_service_name/ 39 | ) 40 | end 41 | end 42 | 43 | it_behaves_like 'validate authentication credential', :delete 44 | 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_cloudservice/list_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_cloudservice, :current] do 10 | let(:cloud_service) { Azure::CloudServiceManagementService } 11 | let(:cloud_service_obj) do 12 | Azure::CloudServiceManagement::CloudService.new do |cs| 13 | cs.name = 'cs-1' 14 | cs.location = 'West US' 15 | end 16 | end 17 | 18 | before :each do 19 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 20 | @options = { 21 | management_certificate: mgmtcertfile, 22 | azure_subscription_id: 'Subscription-id' 23 | } 24 | Azure.configure do |config| 25 | config.management_certificate = @options[:management_certificate] 26 | config.subscription_id = @options[:azure_subscription_id] 27 | end 28 | end 29 | 30 | describe 'option validation' do 31 | 32 | before :each do 33 | cloud_service.any_instance.stubs( 34 | :list_cloud_services 35 | ).returns([cloud_service_obj]) 36 | end 37 | 38 | describe 'valid options' do 39 | it 'should not raise any exception' do 40 | expect { subject.list(@options) }.to_not raise_error 41 | end 42 | 43 | it 'should print affinity groups details' do 44 | cs_services = subject.list(@options) 45 | name = "#{'Name'.fix(20)}: #{cloud_service_obj.name}" 46 | location = "#{'Locaton'.fix(20)}: #{cloud_service_obj.location}" 47 | expect(cs_services).to match(/#{name}/) 48 | expect(cs_services).to match(/#{location}/) 49 | end 50 | end 51 | 52 | it_behaves_like 'validate authentication credential', :list 53 | 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_queue/create_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'spec_helper' 7 | describe Puppet::Face[:azure_queue, :current] do 8 | let(:queue_service) { Azure::QueueService } 9 | 10 | before :each do 11 | 12 | @options = { 13 | storage_account_name: 'storage-account', 14 | storage_access_key: 'nD/E49P4SJG8UVEpABOeZRc=', 15 | queue_name: 'queue' 16 | } 17 | 18 | Azure.configure do |config| 19 | config.storage_account_name = @options[:storage_account_name] 20 | config.storage_access_key = @options[:storage_access_key] 21 | end 22 | 23 | queue_service.any_instance.stubs(:create_queue).with(any_parameters) 24 | end 25 | 26 | describe 'option validation' do 27 | describe 'valid options' do 28 | it 'should not raise any exception' do 29 | expect { subject.create(@options) }.to_not raise_error 30 | end 31 | end 32 | 33 | describe '(queue_name)' do 34 | it 'should validate queue name' do 35 | @options.delete(:queue_name) 36 | expect { subject.create(@options) }.to raise_error( 37 | ArgumentError, 38 | /required: queue_name/ 39 | ) 40 | end 41 | end 42 | 43 | describe '(storage_access_key)' do 44 | it 'should validate service bus access key' do 45 | @options.delete(:storage_access_key) 46 | expect { subject.create(@options) }.to raise_error( 47 | ArgumentError, 48 | /required: storage_access_key/ 49 | ) 50 | end 51 | end 52 | 53 | describe '(storage_account_name)' do 54 | it 'should validate storage account name' do 55 | @options.delete(:storage_account_name) 56 | expect { subject.create(@options) }.to raise_error( 57 | ArgumentError, 58 | /required: storage_account_name/ 59 | ) 60 | end 61 | end 62 | 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_servicebus/create_queue_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'spec_helper' 7 | describe Puppet::Face[:azure_servicebus, :current] do 8 | let(:service_bus) { Azure::ServiceBusService } 9 | 10 | before :each do 11 | 12 | @options = { 13 | sb_namespace: 'busname', 14 | sb_access_key: 'nD/E49P4SJG8UVEpABOeZRc=', 15 | queue_name: 'queue' 16 | } 17 | 18 | Azure.configure do |config| 19 | config.sb_namespace = @options[:sb_namespace] 20 | config.sb_access_key = @options[:sb_access_key] 21 | end 22 | service_bus.any_instance.stubs(:create_queue).with(any_parameters) 23 | end 24 | 25 | describe 'option validation' do 26 | describe 'valid options' do 27 | it 'should not raise any exception' do 28 | expect { subject.create_queue(@options) }.to_not raise_error 29 | end 30 | end 31 | 32 | describe '(queue_name)' do 33 | it 'should validate queue name' do 34 | @options.delete(:queue_name) 35 | expect { subject.create_queue(@options) }.to raise_error( 36 | ArgumentError, 37 | /required: queue_name/ 38 | ) 39 | end 40 | end 41 | 42 | describe '(sb_access_key)' do 43 | it 'should validate service bus access key' do 44 | @options.delete(:sb_access_key) 45 | expect { subject.create_queue(@options) }.to raise_error( 46 | ArgumentError, 47 | /required: sb_access_key/ 48 | ) 49 | end 50 | end 51 | 52 | describe '(sb_namespace)' do 53 | it 'should validate service bus namespace' do 54 | @options.delete(:sb_namespace) 55 | expect { subject.create_queue(@options) }.to raise_error( 56 | ArgumentError, 57 | /required: sb_namespace/ 58 | ) 59 | end 60 | end 61 | 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_servicebus/create_topic_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'spec_helper' 7 | describe Puppet::Face[:azure_servicebus, :current] do 8 | let(:service_bus) { Azure::ServiceBusService } 9 | 10 | before :each do 11 | 12 | @options = { 13 | sb_namespace: 'busname', 14 | sb_access_key: 'nD/E49P4SJG8UVEpABOeZRc=', 15 | topic_name: 'topic' 16 | } 17 | 18 | Azure.configure do |config| 19 | config.sb_namespace = @options[:sb_namespace] 20 | config.sb_access_key = @options[:sb_access_key] 21 | end 22 | service_bus.any_instance.stubs(:create_topic).with(any_parameters) 23 | end 24 | 25 | describe 'option validation' do 26 | describe 'valid options' do 27 | it 'should not raise any exception' do 28 | expect { subject.create_topic(@options) }.to_not raise_error 29 | end 30 | end 31 | 32 | describe '(topic_name)' do 33 | it 'should validate topic name' do 34 | @options.delete(:topic_name) 35 | expect { subject.create_topic(@options) }.to raise_error( 36 | ArgumentError, 37 | /required: topic_name/ 38 | ) 39 | end 40 | end 41 | 42 | describe '(sb_access_key)' do 43 | it 'should validate service bus access key' do 44 | @options.delete(:sb_access_key) 45 | expect { subject.create_topic(@options) }.to raise_error( 46 | ArgumentError, 47 | /required: sb_access_key/ 48 | ) 49 | end 50 | end 51 | 52 | describe '(sb_namespace)' do 53 | it 'should validate service bus namespace' do 54 | @options.delete(:sb_namespace) 55 | expect { subject.create_topic(@options) }.to raise_error( 56 | ArgumentError, 57 | /required: sb_namespace/ 58 | ) 59 | end 60 | end 61 | 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_servicebus/delete_queue_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'spec_helper' 7 | describe Puppet::Face[:azure_servicebus, :current] do 8 | let(:service_bus) { Azure::ServiceBusService } 9 | 10 | before :each do 11 | 12 | @options = { 13 | sb_namespace: 'busname', 14 | sb_access_key: 'nD/E49P4SJG8UVEpABOeZRc=', 15 | queue_name: 'queue' 16 | } 17 | 18 | Azure.configure do |config| 19 | config.sb_namespace = @options[:sb_namespace] 20 | config.sb_access_key = @options[:sb_access_key] 21 | end 22 | service_bus.any_instance.stubs(:delete_queue).with(any_parameters) 23 | end 24 | 25 | describe 'option validation' do 26 | describe 'valid options' do 27 | it 'should not raise any exception' do 28 | expect { subject.delete_queue(@options) }.to_not raise_error 29 | end 30 | end 31 | 32 | describe '(queue_name)' do 33 | it 'should validate queue name' do 34 | @options.delete(:queue_name) 35 | expect { subject.delete_queue(@options) }.to raise_error( 36 | ArgumentError, 37 | /required: queue_name/ 38 | ) 39 | end 40 | end 41 | 42 | describe '(sb_access_key)' do 43 | it 'should validate service bus access key' do 44 | @options.delete(:sb_access_key) 45 | expect { subject.delete_queue(@options) }.to raise_error( 46 | ArgumentError, 47 | /required: sb_access_key/ 48 | ) 49 | end 50 | end 51 | 52 | describe '(sb_namespace)' do 53 | it 'should validate service bus namespace' do 54 | @options.delete(:sb_namespace) 55 | expect { subject.delete_queue(@options) }.to raise_error( 56 | ArgumentError, 57 | /required: sb_namespace/ 58 | ) 59 | end 60 | end 61 | 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_servicebus/delete_topic_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | require 'spec_helper' 7 | describe Puppet::Face[:azure_servicebus, :current] do 8 | let(:service_bus) { Azure::ServiceBusService } 9 | 10 | before :each do 11 | 12 | @options = { 13 | sb_namespace: 'busname', 14 | sb_access_key: 'nD/E49P4SJG8UVEpABOeZRc=', 15 | topic_name: 'topic' 16 | } 17 | 18 | Azure.configure do |config| 19 | config.sb_namespace = @options[:sb_namespace] 20 | config.sb_access_key = @options[:sb_access_key] 21 | end 22 | service_bus.any_instance.stubs(:delete_topic).with(any_parameters) 23 | end 24 | 25 | describe 'option validation' do 26 | describe 'valid options' do 27 | it 'should not raise any exception' do 28 | expect { subject.delete_topic(@options) }.to_not raise_error 29 | end 30 | end 31 | 32 | describe '(topic_name)' do 33 | it 'should validate topic name' do 34 | @options.delete(:topic_name) 35 | expect { subject.delete_topic(@options) }.to raise_error( 36 | ArgumentError, 37 | /required: topic_name/ 38 | ) 39 | end 40 | end 41 | 42 | describe '(sb_access_key)' do 43 | it 'should validate service bus access key' do 44 | @options.delete(:sb_access_key) 45 | expect { subject.delete_topic(@options) }.to raise_error( 46 | ArgumentError, 47 | /required: sb_access_key/ 48 | ) 49 | end 50 | end 51 | 52 | describe '(sb_namespace)' do 53 | it 'should validate service bus namespace' do 54 | @options.delete(:sb_namespace) 55 | expect { subject.delete_topic(@options) }.to raise_error( 56 | ArgumentError, 57 | /required: sb_namespace/ 58 | ) 59 | end 60 | end 61 | 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_sqldb/create_firewall_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_sqldb, :current] do 10 | let(:sql_service) { Azure::SqlDatabaseManagementService } 11 | before :each do 12 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 13 | @options = { 14 | management_certificate: mgmtcertfile, 15 | azure_subscription_id: 'Subscription-id', 16 | management_endpoint: 'management.core.windows.net', 17 | start_ip_address: '192.168.1.1', 18 | end_ip_address: '192.168.1.5', 19 | server_name: 'sql-db', 20 | rule_name: 'rule 1' 21 | } 22 | Azure.configure do |config| 23 | config.management_certificate = @options[:management_certificate] 24 | config.subscription_id = @options[:azure_subscription_id] 25 | end 26 | sql_service.any_instance.stubs( 27 | :set_sql_server_firewall_rule).with( 28 | any_parameters 29 | ) 30 | end 31 | 32 | describe 'option validation' do 33 | 34 | describe 'valid options' do 35 | it 'should not raise any exception' do 36 | expect { subject.create_firewall(@options) }.to_not raise_error 37 | end 38 | end 39 | 40 | describe '(server_name)' do 41 | it 'should validate the sql server name' do 42 | @options.delete(:server_name) 43 | expect { subject.create_firewall(@options) }.to raise_error( 44 | ArgumentError, 45 | /required: server_name/ 46 | ) 47 | end 48 | end 49 | 50 | describe '(rule_name)' do 51 | it 'should validate the sql db location' do 52 | @options.delete(:rule_name) 53 | expect { subject.create_firewall(@options) }.to raise_error( 54 | ArgumentError, 55 | /required: rule_name/ 56 | ) 57 | end 58 | end 59 | 60 | it_behaves_like 'validate authentication credential', :create_firewall 61 | end 62 | 63 | describe 'optional parameter validation' do 64 | describe '(start_ip_address)' do 65 | it 'start_ip_address should be optional' do 66 | @options.delete(:start_ip_address) 67 | expect { subject.create_firewall(@options) }.to_not raise_error 68 | end 69 | 70 | it 'end_ip_address should be optional' do 71 | @options.delete(:end_ip_address) 72 | expect { subject.create_firewall(@options) }.to_not raise_error 73 | end 74 | end 75 | end 76 | end 77 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_sqldb/create_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_sqldb, :current] do 10 | let(:sql_service) { Azure::SqlDatabaseManagementService } 11 | let(:sql_server) do 12 | Azure::SqlDatabaseManagement::SqlDatabase.new do |db| 13 | db.name = 'db-1' 14 | db.administrator_login = 'login-name' 15 | db.location = 'West US' 16 | end 17 | end 18 | before :each do 19 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 20 | @options = { 21 | management_certificate: mgmtcertfile, 22 | azure_subscription_id: 'Subscription-id', 23 | management_endpoint: 'management.core.windows.net', 24 | login: 'login-name', 25 | location: 'West US', 26 | password: 'ComplexPassword$' 27 | } 28 | Azure.configure do |config| 29 | config.management_certificate = @options[:management_certificate] 30 | config.subscription_id = @options[:azure_subscription_id] 31 | end 32 | sql_service.any_instance.stubs( 33 | :create_server).with( 34 | any_parameters).returns(sql_server) 35 | end 36 | 37 | describe 'option validation' do 38 | 39 | describe 'valid options' do 40 | it 'should not raise any exception' do 41 | expect { subject.create(@options) }.to_not raise_error 42 | end 43 | 44 | it 'should print sql server details' do 45 | server = subject.create(@options) 46 | expect(server).to match(/Server Name : #{sql_server.name}/) 47 | login = "Administrator login : #{sql_server.administrator_login}" 48 | expect(server).to match(/#{login}/) 49 | expect(server).to match(/Location : #{sql_server.location}/) 50 | end 51 | end 52 | 53 | describe '(login)' do 54 | it 'should validate the sql db login' do 55 | @options.delete(:login) 56 | expect { subject.create(@options) }.to raise_error( 57 | ArgumentError, 58 | /required: login/ 59 | ) 60 | end 61 | end 62 | 63 | describe '(location)' do 64 | it 'should validate the sql db location' do 65 | @options.delete(:location) 66 | expect { subject.create(@options) }.to raise_error( 67 | ArgumentError, 68 | /required: location/ 69 | ) 70 | end 71 | end 72 | 73 | describe '(password)' do 74 | it 'should validate sql db password' do 75 | @options.delete(:password) 76 | expect { subject.create(@options) }.to raise_error( 77 | ArgumentError, 78 | /required: password/ 79 | ) 80 | end 81 | end 82 | 83 | it_behaves_like 'validate authentication credential', :create 84 | end 85 | end 86 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_sqldb/delete_firewall_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_sqldb, :current] do 10 | let(:sql_service) { Azure::SqlDatabaseManagementService } 11 | before :each do 12 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 13 | @options = { 14 | management_certificate: mgmtcertfile, 15 | management_endpoint: 'management.core.windows.net', 16 | azure_subscription_id: 'Subscription-id', 17 | server_name: 'sql-db', 18 | rule_name: 'rule 1' 19 | } 20 | Azure.configure do |config| 21 | config.management_certificate = @options[:management_certificate] 22 | config.subscription_id = @options[:azure_subscription_id] 23 | end 24 | end 25 | 26 | describe 'option validation' do 27 | before :each do 28 | sql_service.any_instance.stubs(:delete_sql_server_firewall_rule).with( 29 | any_parameters) 30 | end 31 | 32 | describe 'valid options' do 33 | it 'should not raise any exception' do 34 | expect { subject.delete_firewall(@options) }.to_not raise_error 35 | end 36 | end 37 | 38 | describe '(server_name)' do 39 | it 'should validate the sql server_name' do 40 | @options.delete(:server_name) 41 | expect { subject.delete_firewall(@options) }.to raise_error( 42 | ArgumentError, 43 | /required: server_name/ 44 | ) 45 | end 46 | 47 | describe '(rule_name)' do 48 | it 'should validate the sql server_name' do 49 | @options.delete(:rule_name) 50 | expect { subject.delete_firewall(@options) }.to raise_error( 51 | ArgumentError, 52 | /required: rule_name/ 53 | ) 54 | end 55 | end 56 | end 57 | 58 | it_behaves_like 'validate authentication credential', :delete_firewall 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_sqldb/delete_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_sqldb, :current] do 10 | let(:sql_service) { Azure::SqlDatabaseManagementService } 11 | before :each do 12 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 13 | @options = { 14 | management_certificate: mgmtcertfile, 15 | management_endpoint: 'management.core.windows.net', 16 | azure_subscription_id: 'Subscription-id', 17 | server_name: 'sql-db' 18 | } 19 | Azure.configure do |config| 20 | config.management_certificate = @options[:management_certificate] 21 | config.subscription_id = @options[:azure_subscription_id] 22 | end 23 | end 24 | 25 | describe 'option validation' do 26 | before :each do 27 | sql_service.any_instance.stubs(:delete_server).with(anything) 28 | end 29 | 30 | describe 'valid options' do 31 | it 'should not raise any exception' do 32 | expect { subject.delete(@options) }.to_not raise_error 33 | end 34 | end 35 | 36 | describe '(server_name)' do 37 | it 'should validate the sql server_name' do 38 | @options.delete(:server_name) 39 | expect { subject.delete(@options) }.to raise_error( 40 | ArgumentError, 41 | /required: server_name/ 42 | ) 43 | end 44 | end 45 | 46 | it_behaves_like 'validate authentication credential', :delete 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_sqldb/list_firewall_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_sqldb, :current] do 10 | let(:sql_service) { Azure::SqlDatabaseManagementService } 11 | let(:firewalls) do 12 | [ 13 | { 14 | rule: 'Rule 1', 15 | start_ip_address: '192.168.1.1', 16 | end_ip_address: '192.168.1.255' 17 | } 18 | ] 19 | end 20 | 21 | before :each do 22 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 23 | @options = { 24 | management_certificate: mgmtcertfile, 25 | management_endpoint: 'management.core.windows.net', 26 | azure_subscription_id: 'Subscription-id', 27 | server_name: 'db-server' 28 | } 29 | Azure.configure do |config| 30 | config.management_certificate = @options[:management_certificate] 31 | config.subscription_id = @options[:azure_subscription_id] 32 | end 33 | end 34 | 35 | describe 'option validation' do 36 | before :each do 37 | sql_service.any_instance.stubs( 38 | :list_sql_server_firewall_rules 39 | ).returns(firewalls) 40 | end 41 | describe 'valid options' do 42 | it 'should not raise any exception' do 43 | expect { subject.list_firewall(@options) }.to_not raise_error 44 | end 45 | 46 | it 'should print affinity groups details' do 47 | server_firewalls = subject.list_firewall(@options) 48 | firewall = firewalls.first 49 | start_ip = firewall[:start_ip_address] 50 | end_ip = firewall[:end_ip_address] 51 | rule = "#{'Rule Name'.fix(20)}: #{firewall[:rule]}" 52 | expect(server_firewalls).to match(/#{rule}/) 53 | start_ip_text = "#{'Start IP Address'.fix(20)}: #{start_ip}" 54 | expect(server_firewalls).to match(/#{start_ip_text}/) 55 | end_ip_text = "#{'End IP Address'.fix(20)}: #{end_ip}" 56 | expect(server_firewalls).to match(/#{end_ip_text}/) 57 | end 58 | end 59 | 60 | it_behaves_like 'validate authentication credential', :list_firewall 61 | 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_sqldb/list_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_sqldb, :current] do 10 | let(:sql_service) { Azure::SqlDatabaseManagementService } 11 | let(:sql_server) do 12 | Azure::SqlDatabaseManagement::SqlDatabase.new do |db| 13 | db.name = 'db-1' 14 | db.administrator_login = 'login-name' 15 | db.location = 'West US' 16 | end 17 | end 18 | 19 | before :each do 20 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 21 | @options = { 22 | management_certificate: mgmtcertfile, 23 | management_endpoint: 'management.core.windows.net', 24 | azure_subscription_id: 'Subscription-id' 25 | } 26 | Azure.configure do |config| 27 | config.management_certificate = @options[:management_certificate] 28 | config.subscription_id = @options[:azure_subscription_id] 29 | end 30 | end 31 | 32 | describe 'option validation' do 33 | before :each do 34 | sql_service.any_instance.stubs( 35 | :list_servers 36 | ).returns([sql_server]) 37 | end 38 | describe 'valid options' do 39 | it 'should not raise any exception' do 40 | expect { subject.list(@options) }.to_not raise_error 41 | end 42 | 43 | it 'should print affinity groups details' do 44 | db_servers = subject.list(@options) 45 | expect(db_servers).to match(/Server Name : #{sql_server.name}/) 46 | login = "Administrator login : #{sql_server.administrator_login}" 47 | expect(db_servers).to match(/#{login}/) 48 | location = "#{'Location'.fix(20)}: #{sql_server.location}" 49 | expect(db_servers).to match(/#{location}/) 50 | end 51 | end 52 | 53 | it_behaves_like 'validate authentication credential', :list 54 | 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_sqldb/reset_password_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_sqldb, :current] do 10 | let(:sql_service) { Azure::SqlDatabaseManagementService } 11 | before :each do 12 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 13 | @options = { 14 | management_certificate: mgmtcertfile, 15 | management_endpoint: 'management.core.windows.net', 16 | azure_subscription_id: 'Subscription-id', 17 | server_name: 'sql-db', 18 | password: 'ComplexPassword$!' 19 | } 20 | Azure.configure do |config| 21 | config.management_certificate = @options[:management_certificate] 22 | config.subscription_id = @options[:azure_subscription_id] 23 | end 24 | end 25 | 26 | describe 'option validation' do 27 | before :each do 28 | sql_service.any_instance.stubs(:reset_password).with(anything, anything) 29 | end 30 | 31 | describe 'valid options' do 32 | it 'should not raise any exception' do 33 | expect { subject.reset_password(@options) }.to_not raise_error 34 | end 35 | end 36 | 37 | describe '(server_name)' do 38 | it 'should validate the sql server_name' do 39 | @options.delete(:server_name) 40 | expect { subject.reset_password(@options) }.to raise_error( 41 | ArgumentError, 42 | /required: server_name/ 43 | ) 44 | end 45 | end 46 | 47 | describe '(password)' do 48 | it 'should validate the sql server password' do 49 | @options.delete(:password) 50 | expect { subject.reset_password(@options) }.to raise_error( 51 | ArgumentError, 52 | /required: password/ 53 | ) 54 | end 55 | end 56 | 57 | it_behaves_like 'validate authentication credential', :reset_password 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_storage/create_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_storage, :current] do 10 | let(:storage_service) { Azure::StorageManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | storage_account_name: 'storage-account', 18 | location: 'west us', 19 | description: 'Some description', 20 | label: 'label', 21 | affinity_group_name: 'ag-1', 22 | extended_properties: 'key-1:value1,key-2:value2' 23 | } 24 | Azure.configure do |config| 25 | config.management_certificate = @options[:management_certificate] 26 | config.subscription_id = @options[:azure_subscription_id] 27 | end 28 | storage_service.any_instance.stubs( 29 | :create_storage_account 30 | ).with(anything, anything) 31 | end 32 | 33 | describe 'option validation' do 34 | describe 'valid options' do 35 | it 'should not raise any exception' do 36 | expect { subject.create(@options) }.to_not raise_error 37 | end 38 | end 39 | 40 | describe '(storage_account_name)' do 41 | it 'should validate storage account name' do 42 | @options.delete(:storage_account_name) 43 | expect { subject.create(@options) }.to raise_error( 44 | ArgumentError, 45 | /required: storage_account_name/ 46 | ) 47 | end 48 | end 49 | 50 | describe '(location)' do 51 | it 'should validate the storage account location or affinity group' do 52 | @options.delete(:location) 53 | @options.delete(:affinity_group_name) 54 | expect { subject.create(@options) }.to raise_error( 55 | ArgumentError, 56 | /affinity group name or location is required/ 57 | ) 58 | end 59 | 60 | it 'should not raise any exception when only location is given' do 61 | @options.delete(:affinity_group_name) 62 | expect { subject.create(@options) }.to_not raise_error 63 | end 64 | 65 | it 'should not raise any exception when only affinity group is given' do 66 | @options.delete(:location) 67 | expect { subject.create(@options) }.to_not raise_error 68 | end 69 | end 70 | 71 | describe '(description)' do 72 | it 'should validate the cloud service description' do 73 | @options.delete(:description) 74 | expect { subject.create(@options) }.to_not raise_error 75 | end 76 | end 77 | 78 | describe '(label)' do 79 | it 'should validate the cloud service label' do 80 | @options.delete(:label) 81 | expect { subject.create(@options) }.to_not raise_error 82 | end 83 | end 84 | 85 | describe '(extended_properties)' do 86 | it 'should validate the cloud service extended_properties' do 87 | @options.delete(:extended_properties) 88 | expect { subject.create(@options) }.to_not raise_error 89 | end 90 | end 91 | 92 | it_behaves_like 'validate authentication credential', :create 93 | 94 | end 95 | end 96 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_storage/delete_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_storage, :current] do 10 | let(:storage_service) { Azure::StorageManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | storage_account_name: 'storage-account', 18 | } 19 | Azure.configure do |config| 20 | config.management_certificate = @options[:management_certificate] 21 | config.subscription_id = @options[:azure_subscription_id] 22 | end 23 | storage_service.any_instance.stubs(:delete_storage_account).with(anything) 24 | end 25 | 26 | describe 'option validation' do 27 | describe 'valid options' do 28 | it 'should not raise any exception' do 29 | expect { subject.delete(@options) }.to_not raise_error 30 | end 31 | end 32 | 33 | describe '(storage_account_name)' do 34 | it 'should validate storage account name' do 35 | @options.delete(:storage_account_name) 36 | expect { subject.delete(@options) }.to raise_error( 37 | ArgumentError, 38 | /required: storage_account_name/ 39 | ) 40 | end 41 | end 42 | 43 | it_behaves_like 'validate authentication credential', :delete 44 | 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_storage/list_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_storage, :current] do 10 | let(:storage_service) { Azure::StorageManagementService } 11 | let(:storage_account_obj) do 12 | Azure::StorageManagement::StorageAccount.new do |sa| 13 | sa.name = 'cs-1' 14 | sa.location = 'West US' 15 | end 16 | end 17 | 18 | before :each do 19 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 20 | @options = { 21 | management_certificate: mgmtcertfile, 22 | azure_subscription_id: 'Subscription-id' 23 | } 24 | Azure.configure do |config| 25 | config.management_certificate = @options[:management_certificate] 26 | config.subscription_id = @options[:azure_subscription_id] 27 | end 28 | end 29 | 30 | describe 'option validation' do 31 | 32 | before :each do 33 | storage_service.any_instance.stubs( 34 | :list_storage_accounts 35 | ).returns([storage_account_obj]) 36 | end 37 | 38 | describe 'valid options' do 39 | it 'should not raise any exception' do 40 | expect { subject.list(@options) }.to_not raise_error 41 | end 42 | 43 | it 'should print storage account details' do 44 | cs_services = subject.list(@options) 45 | name = "#{'Name'.fix(20)}: #{storage_account_obj.name}" 46 | location = "#{'Locaton'.fix(20)}: #{storage_account_obj.location}" 47 | expect(cs_services).to match(/#{name}/) 48 | expect(cs_services).to match(/#{location}/) 49 | end 50 | end 51 | 52 | it_behaves_like 'validate authentication credential', :list 53 | 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_storage/update_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_storage, :current] do 10 | let(:storage_service) { Azure::StorageManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | storage_account_name: 'storage-account', 18 | location: 'west us', 19 | description: 'Some description', 20 | label: 'label', 21 | affinity_group_name: 'ag-1', 22 | extended_properties: 'key-1:value1,key-2:value2' 23 | } 24 | Azure.configure do |config| 25 | config.management_certificate = @options[:management_certificate] 26 | config.subscription_id = @options[:azure_subscription_id] 27 | end 28 | storage_service.any_instance.stubs( 29 | :update_storage_account 30 | ).with(anything, anything) 31 | end 32 | 33 | describe 'option validation' do 34 | describe 'valid options' do 35 | it 'should not raise any exception' do 36 | expect { subject.update(@options) }.to_not raise_error 37 | end 38 | end 39 | 40 | describe '(storage_account_name)' do 41 | it 'should validate storage account name' do 42 | @options.delete(:storage_account_name) 43 | expect { subject.update(@options) }.to raise_error( 44 | ArgumentError, 45 | /required: storage_account_name/ 46 | ) 47 | end 48 | end 49 | 50 | describe '(location)' do 51 | it 'should not raise any exception when only location is given' do 52 | @options.delete(:affinity_group_name) 53 | expect { subject.update(@options) }.to_not raise_error 54 | end 55 | 56 | it 'should not raise any exception when only affinity group is given' do 57 | @options.delete(:location) 58 | expect { subject.update(@options) }.to_not raise_error 59 | end 60 | end 61 | 62 | describe '(description)' do 63 | it 'should validate the cloud service description' do 64 | @options.delete(:description) 65 | expect { subject.update(@options) }.to_not raise_error 66 | end 67 | end 68 | 69 | describe '(label)' do 70 | it 'should validate the cloud service label' do 71 | @options.delete(:label) 72 | expect { subject.update(@options) }.to_not raise_error 73 | end 74 | end 75 | 76 | describe '(extended_properties)' do 77 | it 'should validate the cloud service extended_properties' do 78 | @options.delete(:extended_properties) 79 | expect { subject.update(@options) }.to_not raise_error 80 | end 81 | end 82 | 83 | it_behaves_like 'validate authentication credential', :update 84 | 85 | end 86 | end 87 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vm/add_disk_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vm, :current] do 10 | let(:vms) { Azure::VirtualMachineManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | vm_name: 'test-vm', 18 | cloud_service_name: 'cloud-name', 19 | import: 'false', 20 | disk_size: '100', 21 | disk_label: 'Disk_label', 22 | disk_name: 'Disk Name' 23 | } 24 | Azure.configure do |config| 25 | config.management_certificate = @options[:management_certificate] 26 | config.subscription_id = @options[:azure_subscription_id] 27 | end 28 | vms.any_instance.stubs(:add_data_disk).with( 29 | anything, 30 | anything, 31 | anything 32 | ) 33 | end 34 | 35 | describe 'option validation' do 36 | describe 'valid options' do 37 | it 'should not raise any exception' do 38 | expect { subject.add_disk(@options) }.to_not raise_error 39 | end 40 | end 41 | 42 | describe '(vm_name)' do 43 | it 'should require a vm name' do 44 | @options.delete(:vm_name) 45 | expect { subject.add_disk(@options) }.to raise_error( 46 | ArgumentError, 47 | /required: vm_name/ 48 | ) 49 | end 50 | end 51 | 52 | describe '(cloud_service_name)' do 53 | it 'should require a cloud service name' do 54 | @options.delete(:cloud_service_name) 55 | expect { subject.add_disk(@options) }.to raise_error( 56 | ArgumentError, 57 | /required: cloud_service_name/ 58 | ) 59 | end 60 | end 61 | 62 | describe '(disk_size)' do 63 | it 'should validate the disk_size' do 64 | @options.delete(:disk_size) 65 | expect { subject.add_disk(@options) }.to_not raise_error 66 | end 67 | end 68 | 69 | describe '(disk_label)' do 70 | it 'should validate disk_label' do 71 | @options.delete(:disk_label) 72 | expect { subject.add_disk(@options) }.to_not raise_error 73 | end 74 | end 75 | 76 | describe '(disk_name)' do 77 | it 'should require disk_name when import is true' do 78 | @options[:import] = 'true' 79 | expect { subject.add_disk(@options) }.to_not raise_error 80 | end 81 | 82 | it 'should raise error when import is true and disk_name is empty' do 83 | @options[:import] = 'true' 84 | @options.delete(:disk_name) 85 | expect { subject.add_disk(@options) }.to raise_error( 86 | ArgumentError, 87 | /Disk name is required when import is true/ 88 | ) 89 | end 90 | end 91 | 92 | describe '(import)' do 93 | it 'import should be true, false or empty' do 94 | @options[:import] = 'wrong_value' 95 | expect { subject.add_disk(@options) }.to raise_error( 96 | ArgumentError, 97 | /Disk import option is not valid/ 98 | ) 99 | end 100 | 101 | it 'should validate disk_name when import is false' do 102 | @options.delete(:import) 103 | expect { subject.add_disk(@options) }.to_not raise_error 104 | end 105 | end 106 | 107 | it_behaves_like 'validate authentication credential', :add_disk 108 | 109 | end 110 | end 111 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vm/delete_endpoint_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vm, :current] do 10 | let(:vms) { Azure::VirtualMachineManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | vm_name: 'test-vm', 18 | cloud_service_name: 'cloud-name', 19 | endpoint_name: 'endpoint_name' 20 | } 21 | Azure.configure do |config| 22 | config.management_certificate = @options[:management_certificate] 23 | config.subscription_id = @options[:azure_subscription_id] 24 | end 25 | vms.any_instance.stubs(:delete_endpoint).with( 26 | anything, 27 | anything, 28 | anything 29 | ) 30 | end 31 | 32 | describe 'option validation' do 33 | describe 'valid options' do 34 | it 'should not raise any exception' do 35 | expect { subject.delete_endpoint(@options) }.to_not raise_error 36 | end 37 | end 38 | 39 | describe '(vm_name)' do 40 | it 'should require a vm name' do 41 | @options.delete(:vm_name) 42 | expect { subject.delete_endpoint(@options) }.to raise_error( 43 | ArgumentError, 44 | /required: vm_name/ 45 | ) 46 | end 47 | end 48 | 49 | describe '(cloud_service_name)' do 50 | it 'should require a cloud service name' do 51 | @options.delete(:cloud_service_name) 52 | expect { subject.delete_endpoint(@options) }.to raise_error( 53 | ArgumentError, 54 | /required: cloud_service_name/ 55 | ) 56 | end 57 | end 58 | 59 | describe '(endpoint_name)' do 60 | it 'should require endpoint name' do 61 | @options.delete(:endpoint_name) 62 | expect { subject.delete_endpoint(@options) }.to raise_error( 63 | ArgumentError, 64 | /required: endpoint_name/ 65 | ) 66 | end 67 | end 68 | 69 | it_behaves_like 'validate authentication credential', :delete_endpoint 70 | 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vm/delete_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vm, :current] do 10 | let(:vms) { Azure::VirtualMachineManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | management_endpoint: 'management.core.windows.net', 18 | vm_name: 'test-vm', 19 | cloud_service_name: 'cloud-name' 20 | } 21 | Azure.configure do |config| 22 | config.management_certificate = @options[:management_certificate] 23 | config.subscription_id = @options[:azure_subscription_id] 24 | end 25 | vms.any_instance.stubs(:delete_virtual_machine).with(anything, anything) 26 | end 27 | 28 | describe 'option validation' do 29 | describe 'valid options' do 30 | it 'should not raise any exception' do 31 | expect { subject.delete(@options) }.to_not raise_error 32 | end 33 | end 34 | 35 | describe '(vm_name)' do 36 | it 'should validate the vm name' do 37 | @options.delete(:vm_name) 38 | expect { subject.delete(@options) }.to raise_error( 39 | ArgumentError, 40 | /required: vm_name/ 41 | ) 42 | end 43 | end 44 | 45 | describe '(cloud_service_name)' do 46 | it 'should validate cloud service name' do 47 | @options.delete(:cloud_service_name) 48 | expect { subject.delete(@options) }.to raise_error( 49 | ArgumentError, 50 | /required: cloud_service_name/ 51 | ) 52 | end 53 | end 54 | 55 | it_behaves_like 'validate authentication credential', :delete 56 | 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vm/images_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vm, :current] do 10 | let(:image_service) { Azure::VirtualMachineImageManagementService } 11 | let(:image) do 12 | VirtualMachineImage.new do |image| 13 | image.os_type = 'Windows' 14 | image.name = 'SQL-Server-2014CTP2-CU1-12.0.1736.0-ENU-WS2012R2-CY13SU12' 15 | image.category = ' Microsoft SQL Server' 16 | image.locations = 'West US' 17 | end 18 | end 19 | 20 | before :each do 21 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 22 | @options = { 23 | management_certificate: mgmtcertfile, 24 | management_endpoint: 'management.core.windows.net', 25 | azure_subscription_id: 'Subscription-id', 26 | location: 'west us' 27 | } 28 | Azure.configure do |config| 29 | config.management_certificate = @options[:management_certificate] 30 | config.subscription_id = @options[:azure_subscription_id] 31 | end 32 | end 33 | 34 | describe 'option validation' do 35 | before :each do 36 | $stdout.stubs(:write) 37 | image_service.any_instance.stubs( 38 | :list_virtual_machine_images 39 | ).returns([image]) 40 | end 41 | 42 | describe 'valid options' do 43 | it 'should not raise any exception' do 44 | expect { subject.images(@options) }.to_not raise_error 45 | end 46 | 47 | it 'should print images details' do 48 | images = subject.images(@options) 49 | expect(images).to match( 50 | /#{image.os_type.fix} #{image.category[0..19]} #{image.name}/ 51 | ) 52 | end 53 | end 54 | 55 | describe 'optional parameter validation' do 56 | describe '(location)' do 57 | it 'location should be optional' do 58 | @options.delete(:location) 59 | expect { subject.images(@options) }.to_not raise_error 60 | end 61 | end 62 | end 63 | 64 | it_behaves_like 'validate authentication credential', :images 65 | 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vm/locations_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vm, :current] do 10 | let(:base_service) { Azure::BaseManagementService } 11 | let(:location_name) { 'West US' } 12 | let(:loc_services) { 'Compute, Storage, PersistentVMRole, HighMemory' } 13 | let(:location) do 14 | Location.new do |loc| 15 | loc.name = location_name 16 | loc.available_services = loc_services 17 | end 18 | end 19 | 20 | before :each do 21 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 22 | @options = { 23 | management_certificate: mgmtcertfile, 24 | management_endpoint: 'management.core.windows.net', 25 | azure_subscription_id: 'Subscription-id' 26 | } 27 | Azure.configure do |config| 28 | config.management_certificate = @options[:management_certificate] 29 | config.subscription_id = @options[:azure_subscription_id] 30 | end 31 | end 32 | 33 | describe 'option validation' do 34 | before :each do 35 | base_service.any_instance.stubs(:list_locations).returns([location]) 36 | end 37 | 38 | describe 'valid options' do 39 | it 'should not raise any exception' do 40 | expect { subject.locations(@options) }.to_not raise_error 41 | end 42 | 43 | it 'should print locations details' do 44 | locations = subject.locations(@options) 45 | expect(locations).to match(/#{location_name.fix} #{loc_services}/) 46 | end 47 | end 48 | 49 | it_behaves_like 'validate authentication credential', :locations 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vm/restart_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vm, :current] do 10 | let(:vms) { Azure::VirtualMachineManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | management_endpoint: 'management.core.windows.net', 18 | vm_name: 'test-vm', 19 | cloud_service_name: 'cloud-name' 20 | } 21 | Azure.configure do |config| 22 | config.management_certificate = @options[:management_certificate] 23 | config.subscription_id = @options[:azure_subscription_id] 24 | end 25 | vms.any_instance.stubs(:restart_virtual_machine).with(anything, anything) 26 | end 27 | 28 | describe 'option validation' do 29 | describe 'valid options' do 30 | it 'should not raise any exception' do 31 | expect { subject.restart(@options) }.to_not raise_error 32 | end 33 | end 34 | 35 | describe '(vm_name)' do 36 | it 'should validate the vm name' do 37 | @options.delete(:vm_name) 38 | expect { subject.restart(@options) }.to raise_error( 39 | ArgumentError, 40 | /required: vm_name/ 41 | ) 42 | end 43 | end 44 | 45 | describe '(cloud_service_name)' do 46 | it 'cloud_service_name should be optional' do 47 | @options.delete(:cloud_service_name) 48 | expect { subject.restart(@options) }.to raise_error( 49 | ArgumentError, 50 | /required: cloud_service_name/ 51 | ) 52 | end 53 | end 54 | 55 | it_behaves_like 'validate authentication credential', :restart 56 | 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vm/servers_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vm, :current] do 10 | let(:vms) { Azure::VirtualMachineManagementService } 11 | let(:vm) { Azure::VirtualMachineManagement::VirtualMachine } 12 | let(:vm_name) { 'windows-instance' } 13 | let(:ip_address) { '192.168.1.1' } 14 | let(:os_type) { 'Windows' } 15 | let(:virtual_machine_obj) do 16 | vm.new do |virtual_machine| 17 | virtual_machine.vm_name = vm_name 18 | virtual_machine.ipaddress = ip_address 19 | virtual_machine.os_type = os_type 20 | end 21 | end 22 | before :each do 23 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 24 | @options = { 25 | management_certificate: mgmtcertfile, 26 | management_endpoint: 'management.core.windows.net', 27 | azure_subscription_id: 'Subscription-id' 28 | } 29 | Azure.configure do |config| 30 | config.management_certificate = @options[:management_certificate] 31 | config.subscription_id = @options[:azure_subscription_id] 32 | end 33 | end 34 | 35 | describe 'option validation' do 36 | before :each do 37 | vms.any_instance.stubs(:list_virtual_machines).with( 38 | anything, 39 | anything 40 | ).returns([virtual_machine_obj]) 41 | end 42 | 43 | describe 'valid options' do 44 | it 'should not raise any exception' do 45 | expect { subject.servers(@options) }.to_not raise_error 46 | end 47 | 48 | it 'should print server details' do 49 | servers = subject.servers(@options) 50 | expect(servers).to match(/Role : #{vm_name}/) 51 | expect(servers).to match(/IP Address : #{ip_address}/) 52 | end 53 | end 54 | 55 | it_behaves_like 'validate authentication credential', :servers 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vm/shutdown_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vm, :current] do 10 | let(:vms) { Azure::VirtualMachineManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | management_endpoint: 'management.core.windows.net', 18 | vm_name: 'test-vm', 19 | cloud_service_name: 'cloud-name' 20 | } 21 | Azure.configure do |config| 22 | config.management_certificate = @options[:management_certificate] 23 | config.subscription_id = @options[:azure_subscription_id] 24 | end 25 | vms.any_instance.stubs(:shutdown_virtual_machine).with(anything, anything) 26 | end 27 | 28 | describe 'option validation' do 29 | describe 'valid options' do 30 | it 'should not raise any exception' do 31 | expect { subject.shutdown(@options) }.to_not raise_error 32 | end 33 | end 34 | 35 | describe '(vm_name)' do 36 | it 'should validate the vm name' do 37 | @options.delete(:vm_name) 38 | expect { subject.shutdown(@options) }.to raise_error( 39 | ArgumentError, 40 | /required: vm_name/ 41 | ) 42 | end 43 | end 44 | 45 | describe '(cloud_service_name)' do 46 | it 'cloud_service_name should be optional' do 47 | @options.delete(:cloud_service_name) 48 | expect { subject.shutdown(@options) }.to raise_error( 49 | ArgumentError, 50 | /required: cloud_service_name/ 51 | ) 52 | end 53 | end 54 | 55 | it_behaves_like 'validate authentication credential', :shutdown 56 | 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vm/start_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vm, :current] do 10 | let(:vms) { Azure::VirtualMachineManagementService } 11 | 12 | before :each do 13 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | management_endpoint: 'management.core.windows.net', 18 | vm_name: 'test-vm', 19 | cloud_service_name: 'cloud-name' 20 | } 21 | Azure.configure do |config| 22 | config.management_certificate = @options[:management_certificate] 23 | config.subscription_id = @options[:azure_subscription_id] 24 | end 25 | vms.any_instance.stubs(:start_virtual_machine).with(anything, anything) 26 | end 27 | 28 | describe 'option validation' do 29 | describe 'valid options' do 30 | it 'should not raise any exception' do 31 | expect { subject.start(@options) }.to_not raise_error 32 | end 33 | end 34 | 35 | describe '(vm_name)' do 36 | it 'should validate the vm name' do 37 | @options.delete(:vm_name) 38 | expect { subject.start(@options) }.to raise_error( 39 | ArgumentError, 40 | /required: vm_name/ 41 | ) 42 | end 43 | end 44 | 45 | describe '(cloud_service_name)' do 46 | it 'cloud_service_name should be optional' do 47 | @options.delete(:cloud_service_name) 48 | expect { subject.start(@options) }.to raise_error( 49 | ArgumentError, 50 | /required: cloud_service_name/ 51 | ) 52 | end 53 | end 54 | 55 | it_behaves_like 'validate authentication credential', :start 56 | 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vnet/list_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vnet, :current] do 10 | let(:vnet_service) { Azure::VirtualNetworkManagementService } 11 | let(:vnet) do 12 | v = Azure::VirtualNetworkManagement::VirtualNetwork.new 13 | v.name = 'vnet-name' 14 | v.affinity_group = 'test' 15 | v.address_space = %w(172.16.0.0/12 10.0.0.0/8 192.168.0.0/24) 16 | v.dns_servers = [ 17 | { name: 'dns-1', ip_address: '8.8.8.8' }, 18 | { name: 'dns-2', ip_address: '1.2.3.4' } 19 | ] 20 | v.subnets = [ 21 | { name: 'Subnet-2', address_prefix: '10.0.0.0/8' }, 22 | { name: 'Subnet-4', address_prefix: '192.168.0.0/26' } 23 | ] 24 | v 25 | end 26 | 27 | before :each do 28 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 29 | @options = { 30 | management_certificate: mgmtcertfile, 31 | management_endpoint: 'management.core.windows.net', 32 | azure_subscription_id: 'Subscription-id' 33 | } 34 | Azure.configure do |config| 35 | config.management_certificate = @options[:management_certificate] 36 | config.subscription_id = @options[:azure_subscription_id] 37 | end 38 | end 39 | 40 | describe 'option validation' do 41 | before :each do 42 | vnet_service.any_instance.stubs( 43 | :list_virtual_networks 44 | ).returns([vnet]) 45 | end 46 | 47 | describe 'valid options' do 48 | it 'should not raise any exception' do 49 | expect { subject.list(@options) }.to_not raise_error 50 | end 51 | 52 | it 'should print affinity groups details' do 53 | vnets = subject.list(@options) 54 | expect(vnets).to match(/#{"Server Name".fix(20)}: #{vnet.name}/) 55 | address_spaces = vnet.address_space.join(', ') 56 | expect(vnets).to match(/Address Space : #{address_spaces}/) 57 | expect(vnets).to match(/Subnet-2 10.0.0.0\/8/) 58 | expect(vnets).to match(/dns-2 1.2.3.4/) 59 | end 60 | end 61 | 62 | it_behaves_like 'validate authentication credential', :list 63 | 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /spec/unit/puppet/face/azure_vnet/set_xml_schema_spec.rb: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Open Technologies, Inc. 3 | # All Rights Reserved. Licensed under the Apache 2.0 License. 4 | #-------------------------------------------------------------------------- 5 | 6 | # encoding: UTF-8 7 | require 'spec_helper' 8 | 9 | describe Puppet::Face[:azure_vnet, :current] do 10 | let(:vnet_service) { Azure::VirtualNetworkManagementService } 11 | before :each do 12 | mgmtcertfile = File.expand_path('spec/fixtures/management_certificate.pem') 13 | netowork_schema = File.expand_path('spec/fixtures/vnet_schema.xml') 14 | @options = { 15 | management_certificate: mgmtcertfile, 16 | azure_subscription_id: 'Subscription-id', 17 | management_endpoint: 'management.core.windows.net', 18 | xml_schema_file: netowork_schema 19 | } 20 | Azure.configure do |config| 21 | config.management_certificate = @options[:management_certificate] 22 | config.subscription_id = @options[:azure_subscription_id] 23 | end 24 | vnet_service.any_instance.stubs(:set_network_configuration).with( 25 | anything 26 | ) 27 | end 28 | 29 | describe 'option validation' do 30 | 31 | describe 'valid options' do 32 | it 'should not raise any exception' do 33 | expect { subject.set_xml_schema(@options) }.to_not raise_error 34 | end 35 | end 36 | 37 | describe '(xml_schema_file)' do 38 | it 'should validate the xml schema file' do 39 | @options.delete(:xml_schema_file) 40 | expect { subject.set_xml_schema(@options) }.to raise_error( 41 | ArgumentError, 42 | /required: xml_schema_file/ 43 | ) 44 | end 45 | 46 | it 'xml_schema_file doesn\'t exist' do 47 | @options[:xml_schema_file] = 'FileNotExist' 48 | expect { subject.set_xml_schema(@options) }.to raise_error( 49 | ArgumentError, 50 | /Could not find file 'FileNotExist'/ 51 | ) 52 | end 53 | 54 | it 'xml_schema_file extension is not valid' do 55 | file_path = File.expand_path('spec/fixtures/invalid_file.txt') 56 | @options[:xml_schema_file] = file_path 57 | expect { subject.set_xml_schema(@options) }.to raise_error( 58 | RuntimeError, 59 | /Network schema expects a .xml file/ 60 | ) 61 | end 62 | end 63 | 64 | it_behaves_like 'validate authentication credential', :set_xml_schema 65 | 66 | end 67 | end 68 | --------------------------------------------------------------------------------