Adding affinity group to puppet faces.
This commit is contained in:
Родитель
c44b26a6b6
Коммит
e1e5a59630
|
@ -0,0 +1,73 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright 2013 Microsoft Open Technologies, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#--------------------------------------------------------------------------
|
||||
require 'tilt'
|
||||
require 'puppet/application_config'
|
||||
require 'puppet/core/utility'
|
||||
include Puppet::ApplicationConfig
|
||||
|
||||
module Puppet::AffinityGroup
|
||||
|
||||
class << self
|
||||
def views(name)
|
||||
File.join(File.dirname(__FILE__), 'face/azure_affinity_group/views', name)
|
||||
end
|
||||
|
||||
def add_create_options(action)
|
||||
add_default_options(action)
|
||||
add_affinity_group_name_option(action)
|
||||
add_location_option(action)
|
||||
add_description_option(action)
|
||||
add_label_option(action)
|
||||
end
|
||||
|
||||
def add_delete_options(action)
|
||||
add_default_options(action)
|
||||
add_affinity_group_name_option(action)
|
||||
end
|
||||
|
||||
def add_update_options(action)
|
||||
add_default_options(action)
|
||||
add_affinity_group_name_option(action)
|
||||
add_label_option(action)
|
||||
add_description_option(action)
|
||||
end
|
||||
|
||||
def add_description_option(action)
|
||||
action.option '--description=' do
|
||||
summary "Description of affinity group"
|
||||
description <<-EOT
|
||||
Description of affinity group.
|
||||
EOT
|
||||
end
|
||||
end
|
||||
|
||||
def add_label_option(action)
|
||||
action.option '--label=' do
|
||||
summary "Label of affinity group"
|
||||
description <<-EOT
|
||||
Label of affinity group.
|
||||
EOT
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:label].empty?
|
||||
raise ArgumentError, "Label is required"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright 2013 Microsoft Open Technologies, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#--------------------------------------------------------------------------
|
||||
require 'puppet/face'
|
||||
require 'puppet/application/face_base'
|
||||
|
||||
class Puppet::Application::AzureAffinityGroup < Puppet::Application::FaceBase
|
||||
end
|
|
@ -82,6 +82,39 @@ module Puppet
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
def add_location_option(action)
|
||||
action.option '--location=' do
|
||||
summary "The location identifier for the Windows Azure portal."
|
||||
description <<-EOT
|
||||
The location identifier for the Windows Azure portal.
|
||||
valid choices are ('West US', 'East US', 'East Asia', 'Southeast Asia',
|
||||
'North Europe', 'West Europe' ...).
|
||||
EOT
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:location].empty?
|
||||
raise ArgumentError, "Location is required"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_affinity_group_name_option(action)
|
||||
action.option '--affinity-group-name=' do
|
||||
summary "The affinity group name."
|
||||
description <<-EOT
|
||||
The affinity group name.
|
||||
EOT
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:affinity_group_name].empty?
|
||||
raise ArgumentError, "Affinity group name is required"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
require 'puppet/affinity_group'
|
||||
|
||||
Puppet::Face.define(:azure_affinity_group, '0.0.1') do
|
||||
copyright "Windows Azure", 2013
|
||||
license "Microsoft Open Technologies, Inc; see COPYING"
|
||||
|
||||
summary "View and manage Window Azure affinity groups."
|
||||
description <<-'EOT'
|
||||
This subcommand provides a command line interface to work with Windows Azure
|
||||
affinity groups. The goal of these actions are to easily create new or update
|
||||
affinity group.
|
||||
EOT
|
||||
|
||||
end
|
|
@ -0,0 +1,44 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright 2013 Microsoft Open Technologies, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
Puppet::Face.define :azure_affinity_group, '0.0.1' do
|
||||
action :create do
|
||||
|
||||
summary 'Create affinity group.'
|
||||
|
||||
description <<-'EOT'
|
||||
The create action create a affinity group.
|
||||
EOT
|
||||
|
||||
Puppet::AffinityGroup.add_create_options(self)
|
||||
|
||||
when_invoked do |options|
|
||||
Puppet::AffinityGroup.initialize_env_variable(options)
|
||||
affinity_group_service = Azure::BaseManagementService.new
|
||||
others = { :description => options[:description] }
|
||||
begin
|
||||
affinity_group_service.create_affinity_group(options[:affinity_group_name], options[:location], options[:label], others)
|
||||
rescue Exception => e
|
||||
puts e.message
|
||||
end
|
||||
end
|
||||
|
||||
examples <<-'EOT'
|
||||
$ puppet azure_affinity_group create --management-certificate path-to-azure-certificate \
|
||||
--azure-subscription-id YOUR-SUBSCRIPTION-ID --location 'West Us' --label aglabel\
|
||||
--affinity-group-name agname --description 'Some Description'
|
||||
EOT
|
||||
end
|
||||
end
|
|
@ -0,0 +1,42 @@
|
|||
#-------------------------------------------------------------------------
|
||||
# Copyright 2013 Microsoft Open Technologies, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#--------------------------------------------------------------------------
|
||||
|
||||
Puppet::Face.define :azure_affinity_group, '0.0.1' do
|
||||
action :delete do
|
||||
|
||||
summary 'Delete affinity group.'
|
||||
|
||||
description <<-'EOT'
|
||||
The delete action delete a affinity group.
|
||||
EOT
|
||||
|
||||
Puppet::AffinityGroup.add_delete_options(self)
|
||||
|
||||
when_invoked do |options|
|
||||
Puppet::AffinityGroup.initialize_env_variable(options)
|
||||
affinity_group_service = Azure::BaseManagementService.new
|
||||
begin
|
||||
affinity_group_service.delete_affinity_group(options[:affinity_group_name])
|
||||
rescue Exception => e
|
||||
puts e.message
|
||||
end
|
||||
end
|
||||
|
||||
examples <<-'EOT'
|
||||
$ puppet azure_affinity_group delete --management-certificate path-to-azure-certificate \
|
||||
--azure-subscription-id YOUR-SUBSCRIPTION-ID --affinity-group-name ag-name
|
||||
EOT
|
||||
end
|
||||
end
|
|
@ -0,0 +1,44 @@
|
|||
Puppet::Face.define :azure_affinity_group, '0.0.1' do
|
||||
action :list do
|
||||
|
||||
summary 'List affinity groups.'
|
||||
arguments 'list'
|
||||
description <<-'EOT'
|
||||
The list action obtains a list of affinity groups and
|
||||
displays them on the console output.
|
||||
EOT
|
||||
|
||||
Puppet::AffinityGroup.add_default_options(self)
|
||||
|
||||
when_invoked do |options|
|
||||
Puppet::AffinityGroup.initialize_env_variable(options)
|
||||
affinity_group_service = Azure::BaseManagementService.new
|
||||
affinity_groups = affinity_group_service.list_affinity_groups
|
||||
puts Tilt.new(Puppet::AffinityGroup.views('affinity_groups.erb'), 1, :trim => '%').render(nil, :affinity_groups => affinity_groups)
|
||||
end
|
||||
|
||||
returns 'Array of affinity group objets.'
|
||||
|
||||
examples <<-'EOT'
|
||||
$ puppet affinity_group list --management-certificate path-to-azure-certificate \
|
||||
--azure-subscription-id YOUR-SUBSCRIPTION-ID --management-endpoint=https://management.core.windows.net
|
||||
|
||||
Listing affinity groups
|
||||
|
||||
Affinity Group: 1
|
||||
Name : integration-test-affinity-group
|
||||
Label : Label
|
||||
Locaton : East Asia
|
||||
Description : Description
|
||||
Capability : PersistentVMRole, HighMemory
|
||||
|
||||
Affinity Group: 2
|
||||
Name : Test
|
||||
Label : this is update operation
|
||||
Locaton : West US
|
||||
Description : My Description
|
||||
Capability : PersistentVMRole, HighMemory
|
||||
|
||||
EOT
|
||||
end
|
||||
end
|
|
@ -0,0 +1,29 @@
|
|||
Puppet::Face.define :azure_affinity_group, '0.0.1' do
|
||||
action :update do
|
||||
|
||||
summary 'Update affinity group.'
|
||||
|
||||
description <<-'EOT'
|
||||
The update action updates a affinity group.
|
||||
EOT
|
||||
|
||||
Puppet::AffinityGroup.add_update_options(self)
|
||||
|
||||
when_invoked do |options|
|
||||
Puppet::AffinityGroup.initialize_env_variable(options)
|
||||
affinity_group_service = Azure::BaseManagementService.new
|
||||
others = { :description => options[:description] }
|
||||
begin
|
||||
affinity_group_service.update_affinity_group(options[:affinity_group_name], options[:label], others)
|
||||
rescue Exception => e
|
||||
puts e.message
|
||||
end
|
||||
end
|
||||
|
||||
examples <<-'EOT'
|
||||
$ puppet azure_affinity_group update --management-certificate path-to-azure-certificate \
|
||||
--azure-subscription-id YOUR-SUBSCRIPTION-ID --label aglabel \
|
||||
--affinity-group-name agname --description 'Some Description'
|
||||
EOT
|
||||
end
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
<%="Listing affinity groups".bold%><%index=1%>
|
||||
<%affinity_groups.each do |ag|%>
|
||||
<%="Affinity Group: #{index}".bold%>
|
||||
<%="Name".fix(20)%>: <%=ag.name %>
|
||||
<%="Label".fix(20)%>: <%=ag.label%>
|
||||
<%="Locaton".fix(20)%>: <%=ag.location%>
|
||||
<%="Description".fix(20)%>: <%=ag.description%>
|
||||
<%="Capability".fix(20)%>: <%=ag.capability.join(", ")%><%index+=1%>
|
||||
<%end%>
|
|
@ -94,21 +94,6 @@ module Puppet::SqlDatabase
|
|||
end
|
||||
end
|
||||
|
||||
def add_location_option(action)
|
||||
action.option '--location=' do
|
||||
summary 'The location of Windows Azure sql database server.'
|
||||
description <<-EOT
|
||||
The location of the Windows Azure sql database server.
|
||||
EOT
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:location].empty?
|
||||
raise ArgumentError, "Location is required."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_server_name_option(action)
|
||||
action.option '--server-name=' do
|
||||
summary 'The server name for the Windows Azure sql database server.'
|
||||
|
|
|
@ -75,26 +75,6 @@ module Puppet::VirtualMachine
|
|||
add_affinity_group_option(action)
|
||||
end
|
||||
|
||||
def add_location_option(action)
|
||||
action.option '--location=' do
|
||||
summary "The location identifier for the Windows Azure portal.valid choices are ('West US', 'East US', 'East Asia', 'Southeast Asia','North Europe', 'West Europe')."
|
||||
description <<-EOT
|
||||
The location identifier for the Windows Azure portal.
|
||||
valid choices are ('West US', 'East US', 'East Asia', 'Southeast Asia',
|
||||
'North Europe', 'West Europe').
|
||||
EOT
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
valid_locations = ['west us', 'east us', 'east asia', 'southeast asia', 'north europe', 'west europe']
|
||||
if options[:location].empty?
|
||||
raise ArgumentError, "Location is required"
|
||||
elsif options[:location] && !valid_locations.include?(options[:location].downcase)
|
||||
raise ArgumentError, "The location is not valid. .valid choices are ('West US', 'East US', 'East Asia', 'Southeast Asia','North Europe', 'West Europe')."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_vm_name_option(action, optional=true)
|
||||
action.option '--vm-name=' do
|
||||
summary 'The name of the virtual machine.'
|
||||
|
|
|
@ -74,22 +74,7 @@ module Puppet::VirtualNetwork
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def add_affinity_group_name_option(action)
|
||||
action.option '--affinity-group-name=' do
|
||||
summary "The affinity group name."
|
||||
description <<-EOT
|
||||
The affinity group name.
|
||||
EOT
|
||||
required
|
||||
before_action do |action, args, options|
|
||||
if options[:affinity_group_name].empty?
|
||||
raise ArgumentError, "Affinity group name is required"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def add_address_space_option(action)
|
||||
action.option '--address-space=' do
|
||||
summary "The address space for virtual network."
|
||||
|
|
Загрузка…
Ссылка в новой задаче