---
bin/aeolus-hwp | 20 +++
lib/aeolus_cli/command/hwp_create_command.rb | 80 ++++++++++++
lib/aeolus_cli/command/hwp_delete_command.rb | 38 ++++++
lib/aeolus_cli/command/hwp_list_command.rb | 42 ++++++
lib/aeolus_cli/command/hwp_parser.rb | 175 ++++++++++++++++++++++++++
5 files changed, 355 insertions(+), 0 deletions(-)
create mode 100644 bin/aeolus-hwp
create mode 100644 lib/aeolus_cli/command/hwp_create_command.rb
create mode 100644 lib/aeolus_cli/command/hwp_delete_command.rb
create mode 100644 lib/aeolus_cli/command/hwp_list_command.rb
create mode 100644 lib/aeolus_cli/command/hwp_parser.rb
diff --git a/bin/aeolus-hwp b/bin/aeolus-hwp
new file mode 100644
index 0000000..c5fd803
--- /dev/null
+++ b/bin/aeolus-hwp
@@ -0,0 +1,20 @@
+#!/usr/bin/env ruby
+
+# Copyright 2011 Red Hat, 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.
+
+$: << File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'aeolus_cli'
+parser = Aeolus::CLI::HwpParser.new(ARGV)
+parser.process
diff --git a/lib/aeolus_cli/command/hwp_create_command.rb
b/lib/aeolus_cli/command/hwp_create_command.rb
new file mode 100644
index 0000000..2f5d789
--- /dev/null
+++ b/lib/aeolus_cli/command/hwp_create_command.rb
@@ -0,0 +1,80 @@
+# Copyright 2011 Red Hat, 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 'rest_client'
+
+module Aeolus
+ module CLI
+ class HwpCreateCommand < BaseCommand
+ def initialize(opts={}, logger=nil)
+ super(opts, logger)
+ end
+
+ def run
+ begin
+ hwp = Aeolus::CLI::HardwareProfile.new(request_parameters)
+ hwp.save!
+
+ headers = ActiveSupport::OrderedHash.new
+ headers[:id] = "ID"
+ headers[:name] = "Name"
+ headers[:memory] = "Memory"
+ headers[:storage] = "Storage"
+ headers[:cpu] = "CPU"
+ headers[:architecture] = "architecture"
+
+ collection = [hwp]
+ print_collection(collection, headers)
+ quit(0)
+ rescue => e
+ handle_exception(e)
+ end
+ end
+
+ def request_parameters
+ if @options[:name]
+ request_map = {:name => @options[:name]}
+ else
+ puts "Error: You must specify a name for the hardware profile"
+ quit(1)
+ end
+
+ memory_attributes = {:value => nil, :unit => "MB", :name =>
"memory"}
+ storage_attributes = {:value => nil, :unit => "GB", :name =>
"storage"}
+ cpu_attributes = {:value => nil, :unit => "count", :name =>
"cpu"}
+ architecture_attributes = {:value => nil, :unit => "label", :name
=> "architecture"}
+
+ unless @options[:memory].nil?
+ memory_attributes[:value] = @options[:memory]
+ end
+ unless @options[:storage].nil?
+ storage_attributes[:value] = @options[:storage]
+ end
+ unless @options[:cpu].nil?
+ cpu_attributes[:value] = @options[:cpu]
+ end
+ unless @options[:arch].nil?
+ architecture_attributes[:value] = @options[:arch]
+ end
+
+ request_map[:memory_attributes] = memory_attributes
+ request_map[:storage_attributes] = storage_attributes
+ request_map[:cpu_attributes] = cpu_attributes
+ request_map[:architecture_attributes] = architecture_attributes
+
+ request_map
+ end
+ end
+ end
+end
diff --git a/lib/aeolus_cli/command/hwp_delete_command.rb
b/lib/aeolus_cli/command/hwp_delete_command.rb
new file mode 100644
index 0000000..f400802
--- /dev/null
+++ b/lib/aeolus_cli/command/hwp_delete_command.rb
@@ -0,0 +1,38 @@
+# Copyright 2011 Red Hat, 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.
+
+module Aeolus
+ module CLI
+ class HwpDeleteCommand < BaseCommand
+ def initialize(opts={}, logger=nil)
+ super(opts, logger)
+ end
+
+ def run
+ begin
+ h = Aeolus::CLI::HardwareProfile.new({:id => @options[:id]})
+ if response = h.destroy
+ puts "Hardware profile: " + @options[:id].to_s + " Deleted
Successfully"
+ puts ""
+ exit(0)
+ end
+ rescue => e
+ handle_exception(e)
+ end
+ end
+
+ end
+ end
+end
+
diff --git a/lib/aeolus_cli/command/hwp_list_command.rb
b/lib/aeolus_cli/command/hwp_list_command.rb
new file mode 100644
index 0000000..f29ca18
--- /dev/null
+++ b/lib/aeolus_cli/command/hwp_list_command.rb
@@ -0,0 +1,42 @@
+# Copyright 2011 Red Hat, 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.
+
+module Aeolus
+ module CLI
+ class HwpListCommand < BaseCommand
+ def initialize(opts={}, logger=nil)
+ super(opts, logger)
+ end
+
+ def run
+ begin
+ headers = ActiveSupport::OrderedHash.new
+ headers[:id] = "ID"
+ headers[:name] = "Name"
+ headers[:memory] = "Memory"
+ headers[:storage] = "Storage"
+ headers[:cpu] = "CPU"
+ headers[:architecture] = "architecture"
+ collection = Aeolus::CLI::HardwareProfile.all
+ print_collection(collection, headers)
+ quit(0)
+ rescue => e
+ handle_exception(e)
+ end
+ end
+
+ end
+ end
+end
+
diff --git a/lib/aeolus_cli/command/hwp_parser.rb b/lib/aeolus_cli/command/hwp_parser.rb
new file mode 100644
index 0000000..37c99cd
--- /dev/null
+++ b/lib/aeolus_cli/command/hwp_parser.rb
@@ -0,0 +1,175 @@
+# Copyright 2011 Red Hat, 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 'optparse'
+require 'logger'
+
+module Aeolus
+ module CLI
+ class HwpParser
+ COMMANDS = %w(create delete list)
+
+ attr_accessor :options, :command, :args
+
+ def initialize(argv)
+ @args = argv
+ # Default options
+ @options = {}
+ end
+
+ def process
+ # Check for command, then call appropriate Optionparser and initiate
+ # call to that class.
+ @command = @args.shift
+ # Eventually get the config file from user dir if it exists.
+ # File.expand_path("~")
+ if COMMANDS.include?(@command)
+ opts = self.send((@command + "Options").to_sym)
+ if @args.include?('-h') || @args.include?('--help')
+ puts opts
+ else
+ parse(opts)
+ begin
+ self.send((a)command.to_sym)
+ rescue ArgumentError => e
+ puts "Warning, #{e.message}"
+ puts opts
+ exit(1)
+ end
+ end
+ else
+ puts generalOptions
+ exit(1)
+ end
+ end
+
+ def parse(opts)
+ begin
+ opts.parse(@args)
+ rescue OptionParser::ParseError => e
+ puts "Warning, " + e.message + "\n\tSee `aeolus-hwp " +
@command + " -h` for usage information."
+ exit(1)
+ rescue
+ puts "An error occurred: See `aeolus-hwp " + @command + " -h`
for usage information."
+ exit(1)
+ end
+ end
+
+ def generalOptions
+ subtext = "Aeolus Hardware Profile Commands:"
+ subtext += "\n create : Create a new front-end hardware profile"
+ subtext += "\n delete : Delete a front-end hardware profile"
+ subtext += "\n list : List all front-end hardware profiles"
+ subtext += "\nSee `aeolus-hwp <command> -h` for more information on
each command"
+
+ general = OptionParser.new do |opts|
+ opts.banner = "Usage: aeolus-hwp [#{COMMANDS.join('|')}] [command
options]"
+ opts.on( '-h', '--help', 'Get usage information for this
tool') do
+ puts opts
+ exit(0)
+ end
+ opts.separator(subtext)
+ end
+ general
+ end
+
+ def listOptions
+ OptionParser.new do |opts|
+ opts.banner = "Usage: aeolus-hwp list"
+
+ opts.on( '-h', '--help', 'Get usage information for this
command')
+
+ opts.separator ""
+ opts.separator "Examples:"
+ opts.separator "aeolus-hwp list # list available
front-end hardware profiles"
+ opts.separator ""
+ opts.separator "N.B. Aeolus Credentials should be defined in the
configuration file ~/.aeolus-cli"
+ end
+ end
+
+ def createOptions
+ @options[:memory] = nil
+ @options[:storage] = nil
+ @options[:cpu] = nil
+ @options[:arch] = nil
+
+ OptionParser.new do |opts|
+ opts.banner = "Usage: aeolus-hwp create [command options]"
+ opts.separator ""
+ opts.separator "Options:"
+ opts.on('-n', '--name NAME', 'name for hardware
profile') do |name|
+ @options[:name] = name
+ end
+ opts.on('-m', '--memory [VALUE]', 'minimum memory value in
MB for hardware profile') do |value|
+ @options[:memory] = value
+ end
+ opts.on('-s', '--storage [VALUE]', 'minimum storage value
in GB for hardware profile') do |value|
+ @options[:storage] = value
+ end
+ opts.on('-c', '--cpu [VALUE]', 'minimum cpu count for
hardware profile') do |value|
+ @options[:cpu] = value
+ end
+ opts.on('-a', '--arch [VALUE]', 'architecture label for
hardware profile') do |value|
+ @options[:arch] = value
+ end
+ opts.on( '-h', '--help', 'Get usage information for this
command')
+
+ opts.separator ""
+ opts.separator "Examples:"
+ opts.separator "aeolus-hwp create --name $hwp_name --memory $memory_value
--cpu $cpu_count --arch $arch_label"
+ opts.separator "aeolus-hwp create --name $hwp_name --memory $memory_value
--cpu $cpu_count --storage $storge_value --arch $arch_label"
+ opts.separator ""
+ opts.separator "N.B. Aeolus Credentials should be defined in the
configuration file ~/.aeolus-cli"
+ end
+ end
+
+ def deleteOptions
+ OptionParser.new do |opts|
+ opts.banner = "Usage: aeolus-hwp delete [command options]"
+ opts.separator ""
+
+ opts.separator "Delete options:"
+ opts.on('-I', '--id ID', 'delete front-end hardware
profile') do |id|
+ @options[:id] = id
+ end
+
+ opts.separator ""
+ opts.separator "Delete examples:"
+ opts.separator "aeolus-hwp delete --id $hwp_id # deletes a
front-end hardware profile"
+ opts.separator ""
+ opts.separator "N.B. Aeolus Credentials should be defined in the
configuration file ~/.aeolus-cli"
+ end
+ end
+
+ def list
+ list_command = HwpListCommand.new(@options)
+ list_command.run
+ end
+
+ def create
+ create_command = HwpCreateCommand.new(@options)
+ create_command.run
+ end
+
+ def delete
+ if @options[:id].nil?
+ puts "A valid ID is required for delete, run `./aeolus-hwp delete --help`
for usage instructions"
+ exit(1)
+ end
+ delete_command = HwpDeleteCommand.new(@options)
+ delete_command.run
+ end
+ end
+ end
+end
--
1.7.7.6