knife-joyent 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ac165c3d7a0158856758ccbb1bf651fa82627002
4
- data.tar.gz: 4e88bf3432f19c8745b23a6bcb90d30863e19cb2
3
+ metadata.gz: ee2fcd7ed58b4dc501d0499506fe5086d13d2d25
4
+ data.tar.gz: 9271025e54762e4a8c4d424fe09f87f832570c70
5
5
  SHA512:
6
- metadata.gz: 3d13b2fbda64ed712cd6816d9f9bafbfa402b0e88873793f7b6adaf554c596cd54a0aa5432a0fa555ca0d080b8cb83c53762237ff953587ae243e83940011c70
7
- data.tar.gz: df29deb158722b62918b54773280c1d91a2249ae709e690e164bc5a6e30d7a100ce48f52c1dab1093d214c23681a1388a2ef0083df7d35a2a722a241c7a7d30d
6
+ metadata.gz: ff52fed01168a0c8c36a71ba3e0ad3b2be6fcc1bc62645ba3e7d659ed34824ec28df21cbe4f06b1298c3d77eb0ecd6743e1cee18ef4c4daa0742b18f62d91df0
7
+ data.tar.gz: e7836fd3d2caeaf2684868409c04a57005c76b711fe45b684734bec5002be0dead2603c88c1b59316cb6cbee47afa9a552de967245358a70f19a1a0075f43403
data/.gitignore CHANGED
@@ -3,3 +3,5 @@ pkg
3
3
  .bundle
4
4
  Gemfile.lock
5
5
  .DS_Store
6
+ tmp/*
7
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara features specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/README.md CHANGED
@@ -48,26 +48,31 @@ Currently available commands:
48
48
  The following command will provision an Ubuntu 12.04 with 1GB of memory and bootstrap it with chef
49
49
 
50
50
  # knife joyent server create \
51
- --joyent-api-version '~7.0' \
52
- --flavor "Small 1GB" \
53
- --networks 42325ea0-eb62-44c1-8eb6-0af3e2f83abc,c8cde927-6277-49ca-82a3-741e8b23b02f \
54
- --image d2ba0f30-bbe8-11e2-a9a2-6bc116856d85 \
55
- --node-name 'cookbuntu1' \
56
- --server-name 'cookbuntu1' \
57
-
58
- Creating machine cookbuntu1
51
+ > --joyent-api-version '~7.0' \
52
+ > --flavor "Small 1GB" \
53
+ > --networks 42325ea0-eb62-44c1-8eb6-0af3e2f83abc,c8cde927-6277-49ca-82a3-741e8b23b02f \
54
+ > --image d2ba0f30-bbe8-11e2-a9a2-6bc116856d85 \
55
+ > --node-name 'cookbuntu0' \
56
+ > --server-name 'cookbuntu0'
57
+
58
+ Creating machine cookbuntu0
59
59
  Waiting for Server to be Provisioned
60
- ......................
61
- Bootstrap IP Address 165.225.150.195
60
+ ....................
61
+ Bootstrap IP Address 165.225.150.239
62
62
  No user defined in knife config for provision tagging -- continuing
63
63
  Created machine:
64
- ID: ecd7c515-8079-41d9-a04a-0c5a1d93a2da
65
- Name: cookbuntu1
64
+ ID: 9cdf6324-9769-4134-a7a8-a575c7dfcc13
65
+ Name: cookbuntu0
66
66
  State: running
67
67
  Type: virtualmachine
68
68
  Dataset: sdc:jpc:ubuntu-12.04:2.4.2
69
- IPs: 165.225.150.195
69
+ IPs: 165.225.150.239 10.12.29.210
70
70
  Waiting for server to fully initialize...
71
+ Waiting for SSH to come up on: 165.225.150.239
72
+ SSHD accepting connections on 165.225.150.239: banner is SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1
73
+
74
+ Bootstrapping Chef on 165.225.150.239
75
+ ...
71
76
 
72
77
  Please see ``knife joyent server create --help`` for more options
73
78
 
data/knife-joyent.gemspec CHANGED
@@ -19,6 +19,10 @@ Gem::Specification.new do |s|
19
19
  s.add_dependency "fog", "~> 1.15.0"
20
20
  s.add_dependency "multi_json", "~> 1.7"
21
21
  s.add_dependency "chef", ">= 0.10.10"
22
+
23
+ s.add_development_dependency 'rspec'
24
+ s.add_development_dependency 'guard-rspec'
25
+
22
26
  s.require_paths = ["lib"]
23
27
 
24
28
  end
@@ -1,4 +1,5 @@
1
1
  require 'chef/knife'
2
+ require_relative '../../knife-joyent/pricing'
2
3
 
3
4
  class Chef
4
5
  class Knife
@@ -72,6 +73,10 @@ class Chef
72
73
  end
73
74
  end
74
75
 
76
+ def pricing
77
+ @pricing ||= KnifeJoyent::Pricing::Config.new
78
+ end
79
+
75
80
  def locate_config_value(key)
76
81
  key = key.to_sym
77
82
  config[key] || Chef::Config[:knife][key]
@@ -9,21 +9,24 @@ class Chef
9
9
  banner "knife joyent flavor list <options>"
10
10
 
11
11
  def run
12
+
12
13
  flavor_list = [
13
14
  ui.color('Name', :bold),
14
- ui.color('RAM', :bold),
15
- ui.color('Disk', :bold),
16
- ui.color('Swap', :bold),
15
+ ui.color(' RAM', :bold),
16
+ ui.color(' Disk', :bold),
17
+ ui.color(' Swap', :bold),
18
+ ui.color('Price $/Hr', :bold),
17
19
  ]
18
20
 
19
21
  self.connection.flavors.sort_by(&:memory).each do |flavor|
20
22
  flavor_list << flavor.name.to_s
21
- flavor_list << "#{flavor.memory/1024} GB"
22
- flavor_list << "#{flavor.disk/1024} GB"
23
- flavor_list << "#{flavor.swap/1024} GB"
23
+ flavor_list << "#{sprintf "%6.2f", flavor.memory/1024.0} GB"
24
+ flavor_list << "#{sprintf "%6.0f", flavor.disk/1024.0} GB"
25
+ flavor_list << "#{sprintf "%5.0f", flavor.swap/1024.0} GB"
26
+ flavor_list << (pricing[flavor.name.to_s] ? sprintf("$%.3f", pricing[flavor.name.to_s]) : "")
24
27
  end
25
28
 
26
- puts ui.list(flavor_list, :uneven_columns_across, 4)
29
+ puts ui.list(flavor_list, :uneven_columns_across, 5)
27
30
  end
28
31
  end
29
32
  end
@@ -20,7 +20,7 @@ class Chef
20
20
  option :server_name,
21
21
  :short => "-S NAME",
22
22
  :long => "--server-name <name>",
23
- :description => "The Joyent server name"
23
+ :description => "The Joyent server name (may contain letters, numbers, dashes, and periods)"
24
24
 
25
25
  option :chef_node_name,
26
26
  :short => "-N NAME",
@@ -64,6 +64,12 @@ class Chef
64
64
  :boolean => true,
65
65
  :default => false
66
66
 
67
+ option :tags,
68
+ :long => "--tags JSON",
69
+ :description => "JSON-encoded {key:value} pairs tag server with",
70
+ :proc => Proc.new { |m| JSON.parse(m) },
71
+ :default => nil
72
+
67
73
  option :ssh_user,
68
74
  :short => "-x USERNAME",
69
75
  :long => "--ssh-user USERNAME",
@@ -155,15 +161,23 @@ class Chef
155
161
  Chef::Log.debug("Bootstrap IP Address #{bootstrap_ip}")
156
162
  puts "\n"
157
163
  puts ui.color("Bootstrap IP Address #{bootstrap_ip}", :cyan)
164
+
165
+ if config[:tags]
166
+ tags = [ ui.color('Name', :bold), ui.color('Value', :bold) ]
167
+
168
+ server.add_tags(config[:tags]).each do |k,v|
169
+ tags << k
170
+ tags << v
171
+ end
172
+
173
+ puts ui.color("Updated tags for #{@node_name}", :cyan)
174
+ puts ui.list(tags, :uneven_columns_across, 2)
175
+ end
176
+
158
177
  if Chef::Config[:knife][:provisioner]
178
+ tags = [ ui.color('Name', :bold), ui.color('Value', :bold) ]
159
179
  # tag the provision with 'provisioner'
160
- tagkey = 'provisioner'
161
- tagvalue = Chef::Config[:knife][:provisioner]
162
- tags = [
163
- ui.color('Name', :bold),
164
- ui.color('Value', :bold),
165
- ]
166
- server.add_tags({tagkey => tagvalue}).each do |k, v|
180
+ server.add_tags({'provisioner' => Chef::Config[:knife][:provisioner]}).each do |k, v|
167
181
  tags << k
168
182
  tags << v
169
183
  end
@@ -180,6 +194,7 @@ class Chef
180
194
  msg_pair("Type", server.type)
181
195
  msg_pair("Dataset", server.dataset)
182
196
  msg_pair("IPs", server.ips.join(" "))
197
+ msg_pair("Tags", config[:tags]) if config[:tags]
183
198
  msg_pair("JSON Attributes",config[:json_attributes]) unless config[:json_attributes].empty?
184
199
 
185
200
  puts ui.color("Waiting for server to fully initialize...", :cyan)
@@ -15,9 +15,10 @@ class Chef
15
15
  ui.color('State', :bold),
16
16
  ui.color('Type', :bold),
17
17
  ui.color('Image', :bold),
18
+ ui.color('Flavor', :bold),
18
19
  ui.color('IPs', :bold),
19
- ui.color('RAM', :bold),
20
- ui.color('Disk', :bold),
20
+ ui.color(' RAM', :bold),
21
+ ui.color(' Disk', :bold),
21
22
  ui.color('Tags', :bold)
22
23
  ]
23
24
 
@@ -40,18 +41,24 @@ class Chef
40
41
 
41
42
  servers << s.type
42
43
  servers << s.dataset
43
- servers << s.ips.join(" ")
44
- servers << "#{s.memory/1024} GB".to_s
45
- servers << "#{s.disk/1024} GB".to_s
44
+ servers << (s.respond_to?(:attributes) ? s.attributes["package"] : 'unknown')
45
+ servers << s.ips.join(",")
46
+ servers << "#{sprintf "%6.2f", s.memory/1024.0} GB"
47
+ servers << "#{sprintf "%5.0f", s.disk/1024} GB"
46
48
 
47
- if (servers.tags rescue nil)
48
- servers << s.tags.map { |k, v| "#{k}:#{v}" }.join(' ')
49
+
50
+ if (s.tags rescue nil)
51
+ servers << (show_tags? ? s.tags.map { |k, v| "#{k}:#{v}" }.join(' ') : "")
49
52
  else
50
53
  servers << "No Tags"
51
54
  end
52
55
  end
53
56
 
54
- puts ui.list(servers, :uneven_columns_across, 9)
57
+ puts ui.list(servers, :uneven_columns_across, 10)
58
+ end
59
+
60
+ def show_tags?
61
+ !ENV['SHOW_TAGS'].nil?
55
62
  end
56
63
  end
57
64
  end
@@ -0,0 +1,42 @@
1
+ require 'open-uri'
2
+ require 'nokogiri'
3
+
4
+ module KnifeJoyent
5
+ module Pricing
6
+ class Config < ::Hash
7
+ JOYENT_URL = "http://www.joyent.com/products/compute-service/pricing"
8
+
9
+ def initialize
10
+ super
11
+ from_uri
12
+ end
13
+
14
+ def from_uri(uri = JOYENT_URL)
15
+ parse_html_document Nokogiri::HTML(open(uri))
16
+ rescue
17
+ end
18
+
19
+ def from_html_file filename
20
+ parse_html_document Nokogiri::HTML(File.read(filename))
21
+ end
22
+
23
+ private
24
+
25
+ def parse_html_document doc
26
+ mappings = Hash.new
27
+ specs = doc.css("ul.full-specs")
28
+ specs.each do |ul|
29
+ lis = ul.css("span").map(&:content)
30
+ # grab last two <li> elements in each <ul class="full-spec"> block
31
+ os, cost, flavor = lis[-3], lis[-2].gsub(/^\$/, ''), lis[-1]
32
+ next if cost == "N/A"
33
+ next if flavor =~ /kvm/ && os !~ /linux/i
34
+
35
+ mappings[flavor] = cost.to_f
36
+ end
37
+
38
+ self.merge! mappings
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1 @@
1
+ require_relative 'pricing/config'
@@ -1,3 +1,3 @@
1
1
  module KnifeJoyent
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
data/lib/knife-joyent.rb CHANGED
@@ -1 +1,2 @@
1
1
  require 'knife-joyent/version'
2
+ require 'knife-joyent/pricing'
@@ -0,0 +1,26 @@
1
+ require_relative '../spec_helper'
2
+
3
+
4
+
5
+ describe KnifeJoyent::Pricing::Config do
6
+ context "URL Scraper" do
7
+
8
+ let(:config) { KnifeJoyent::Pricing::Config.new() }
9
+
10
+ let(:prices) { { "g3-standard-48-smartos" => 1.536,
11
+ "g3-standard-0.625-smartos" => 0.02,
12
+ "g3-standard-30-kvm" => 0.960 } }
13
+
14
+ def verify
15
+ prices.keys.each do |flavor|
16
+ config[flavor].should eql(prices[flavor])
17
+ end
18
+ end
19
+
20
+ it "should load pricing configuration hash from Joyent Website" do
21
+ config.from_uri
22
+ verify
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ #
8
+ require 'knife-joyent'
9
+
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-joyent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Chan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-22 00:00:00.000000000 Z
11
+ date: 2013-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.10.10
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Joyent CloudAPI Support for Chef's Knife Command
56
84
  email:
57
85
  - kevin@joyent.com
@@ -62,8 +90,10 @@ extra_rdoc_files:
62
90
  - LICENSE
63
91
  files:
64
92
  - .gitignore
93
+ - .rspec
65
94
  - CHANGES.md
66
95
  - Gemfile
96
+ - Guardfile
67
97
  - LICENSE
68
98
  - README.md
69
99
  - Rakefile
@@ -91,7 +121,11 @@ files:
91
121
  - lib/chef/knife/joyent_tag_delete.rb
92
122
  - lib/chef/knife/joyent_tag_list.rb
93
123
  - lib/knife-joyent.rb
124
+ - lib/knife-joyent/pricing.rb
125
+ - lib/knife-joyent/pricing/config.rb
94
126
  - lib/knife-joyent/version.rb
127
+ - spec/pricing/config_spec.rb
128
+ - spec/spec_helper.rb
95
129
  homepage: https://github.com/kevinykchan/knife-joyent
96
130
  licenses: []
97
131
  metadata: {}
@@ -115,5 +149,7 @@ rubygems_version: 2.0.5
115
149
  signing_key:
116
150
  specification_version: 4
117
151
  summary: Joyent CloudAPI Support for Chef's Knife Command
118
- test_files: []
152
+ test_files:
153
+ - spec/pricing/config_spec.rb
154
+ - spec/spec_helper.rb
119
155
  has_rdoc: true