[PATCH aeolus-cli 4/4] hwp create command added to aeolus-cli
Samridh
samridh90 at gmail.com
Fri Jun 29 08:36:07 UTC 2012
---
lib/aeolus_cli.rb | 2 +
lib/aeolus_cli/command/create_command.rb | 80 ++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 0 deletions(-)
create mode 100644 lib/aeolus_cli/command/create_command.rb
diff --git a/lib/aeolus_cli.rb b/lib/aeolus_cli.rb
index 2e6e88c..fef1571 100644
--- a/lib/aeolus_cli.rb
+++ b/lib/aeolus_cli.rb
@@ -21,6 +21,7 @@ require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'push_command')
require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'import_command')
require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'delete_command')
require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'status_command')
+require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'create_command')
require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'config_parser')
require File.join(File.dirname(__FILE__), 'aeolus_cli/command', 'cli_parser')
@@ -33,5 +34,6 @@ require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'provider')
require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'provider_account')
require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'provider_type')
require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'environment')
+require File.join(File.dirname(__FILE__), 'aeolus_cli/model', 'hardware_profile')
require File.join(File.dirname(__FILE__), 'aeolus_cli/', 'exceptions')
diff --git a/lib/aeolus_cli/command/create_command.rb b/lib/aeolus_cli/command/create_command.rb
new file mode 100644
index 0000000..e3cb628
--- /dev/null
+++ b/lib/aeolus_cli/command/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 CreateCommand < BaseCommand
+ def initialize(opts={}, logger=nil)
+ super(opts, logger)
+ end
+
+ def hardwareProfile
+ 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
--
1.7.7.6
More information about the aeolus-devel
mailing list