This repository has been archived by the owner on Jul 24, 2020. It is now read-only.
/
rackspace_flavor_list.rb
74 lines (64 loc) · 2.65 KB
/
rackspace_flavor_list.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Copyright:: Copyright (c) 2011 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# 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 'fog'
require 'chef/knife'
require 'chef/json_compat'
class Chef
class Knife
class RackspaceFlavorList < Knife
banner "knife rackspace flavor list (options)"
option :rackspace_api_key,
:short => "-K KEY",
:long => "--rackspace-api-key KEY",
:description => "Your rackspace API key",
:proc => Proc.new { |key| Chef::Config[:knife][:rackspace_api_key] = key }
option :rackspace_api_username,
:short => "-A USERNAME",
:long => "--rackspace-api-username USERNAME",
:description => "Your rackspace API username",
:proc => Proc.new { |username| Chef::Config[:knife][:rackspace_api_username] = username }
option :rackspace_api_auth_url,
:long => "--rackspace-api-auth-url URL",
:description => "Your rackspace API auth url",
:default => "auth.api.rackspacecloud.com",
:proc => Proc.new { |url| Chef::Config[:knife][:rackspace_api_auth_url] = url }
def h
@highline ||= HighLine.new
end
def run
require 'fog'
connection = Fog::Compute.new(
:provider => 'Rackspace',
:rackspace_api_key => Chef::Config[:knife][:rackspace_api_key],
:rackspace_username => Chef::Config[:knife][:rackspace_api_username],
:rackspace_auth_url => Chef::Config[:knife][:rackspace_api_auth_url] || config[:rackspace_api_auth_url]
)
flavor_list = [ h.color('ID', :bold), h.color('Name', :bold), h.color('Architecture', :bold), h.color('RAM', :bold), h.color('Disk', :bold) , h.color('Cores', :bold) ]
connection.flavors.sort_by(&:id).each do |flavor|
flavor_list << flavor.id.to_s
flavor_list << flavor.name
flavor_list << "#{flavor.bits.to_s}-bit"
flavor_list << "#{flavor.ram.to_s}"
flavor_list << "#{flavor.disk.to_s} GB"
flavor_list << flavor.cores.to_s
end
puts h.list(flavor_list, :columns_across, 6)
end
end
end
end