knife-joyent 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -72,9 +72,9 @@ provider powered by [SmartDataCenter](http://www.joyent.com/products/smartdatace
72
72
 
73
73
  ## Contributors
74
74
 
75
- [Sean Omera](https://github.com/someara) - Opscode
76
- [Eric Saxby](https://github.com/sax) - ModCloth
77
- [Stephen Lauck](https://github.com/stephenlauck) - ModCloth
75
+ - [Sean Omera](https://github.com/someara) - Opscode
76
+ - [Eric Saxby](https://github.com/sax) - ModCloth
77
+ - [Stephen Lauck](https://github.com/stephenlauck) - ModCloth
78
78
 
79
79
  ## License
80
80
 
data/knife-joyent.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.unshift File.expand_path("../lib", __FILE__)
2
+ $:.push File.expand_path("../lib", __FILE__)
3
3
  require 'knife-joyent/version'
4
4
 
5
5
  Gem::Specification.new do |s|
@@ -16,8 +16,8 @@ Gem::Specification.new do |s|
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.add_dependency "fog", "~> 1.3"
20
- s.add_dependency "chef", "~> 0.10"
19
+ s.add_dependency "fog", "~> 1.6"
20
+ s.add_dependency "chef", ">= 0.10.10"
21
21
  s.require_paths = ["lib"]
22
22
 
23
23
  end
@@ -0,0 +1,60 @@
1
+ require 'chef/knife'
2
+
3
+ class Chef
4
+ class Knife
5
+ module JoyentBase
6
+
7
+ def self.included(includer)
8
+ includer.class_eval do
9
+ deps do
10
+ require 'fog'
11
+ require 'net/ssh/multi'
12
+ require 'readline'
13
+ require 'chef/json_compat'
14
+ end
15
+
16
+ option :joyent_username,
17
+ :short => '-U USERNAME',
18
+ :long => '--joyent-username USERNAME',
19
+ :description => 'Your Joyent username',
20
+ :proc => Proc.new {|key| Chef::Config[:knife][:joyent_username] = key}
21
+
22
+ option :joyent_password,
23
+ :short => '-P PASSWORD',
24
+ :long => '--joyent-password PASSOWRD',
25
+ :description => 'Your Joyent password',
26
+ :proc => Proc.new {|key| Chef::Config[:knife][:joyent_password] = key }
27
+
28
+ option :joyent_keyname,
29
+ :long => '--joyent-keyname name of ssh key for signature auth',
30
+ :description => 'name of ssh key for signature auth',
31
+ :proc => Proc.new {|key| Chef::Config[:knife][:joyent_keyname] = key }
32
+
33
+ option :joyent_keyfile,
34
+ :long => '--joyent-keyfile path to ssh private key for signature auth',
35
+ :description => 'path to ssh private key for signature auth',
36
+ :proc => Proc.new {|key| Chef::Config[:knife][:joyent_keyfile] = key }
37
+
38
+ option :joyent_api_url,
39
+ :short => "-L JOYENT_API_URL",
40
+ :long => "--joyent-api-url JOYENT_API_URL",
41
+ :description => "Joyent API URL",
42
+ :proc => Proc.new {|key| Chef::Config[:knife][:joyent_api_url] = key }
43
+ end
44
+ end
45
+
46
+ def connection
47
+ @connection ||= begin
48
+ connection = Fog::Compute.new(
49
+ :provider => 'Joyent',
50
+ :joyent_username => Chef::Config[:knife][:joyent_username],
51
+ :joyent_password => Chef::Config[:knife][:joyent_password],
52
+ :joyent_keyname => Chef::Config[:knife][:joyent_keyname],
53
+ :joyent_keyfile => Chef::Config[:knife][:joyent_keyfile],
54
+ :joyent_url => Chef::Config[:knife][:joyent_api_url]
55
+ )
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,29 +1,30 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/base')
1
+ require 'chef/knife/joyent_base'
2
2
 
3
+ class Chef
4
+ class Knife
5
+ class JoyentFlavorList < Knife
3
6
 
4
- module KnifeJoyent
5
- class JoyentFlavorList < Chef::Knife
7
+ include Knife::JoyentBase
6
8
 
7
- include KnifeJoyent::Base
9
+ banner "knife joyent flavor list <options>"
8
10
 
9
- banner "knife joyent flavor list <options>"
11
+ def run
12
+ flavor_list = [
13
+ ui.color('Name', :bold),
14
+ ui.color('RAM', :bold),
15
+ ui.color('Disk', :bold),
16
+ ui.color('Swap', :bold),
17
+ ]
10
18
 
11
- def run
12
- flavor_list = [
13
- ui.color('Name', :bold),
14
- ui.color('RAM', :bold),
15
- ui.color('Disk', :bold),
16
- ui.color('Swap', :bold),
17
- ]
19
+ self.connection.flavors.sort_by(&:memory).each do |flavor|
20
+ 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"
24
+ end
18
25
 
19
- self.connection.flavors.sort_by(&:memory).each do |flavor|
20
- 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"
26
+ puts ui.list(flavor_list, :uneven_columns_across, 4)
24
27
  end
25
-
26
- puts ui.list(flavor_list, :uneven_columns_across, 4)
27
28
  end
28
29
  end
29
30
  end
@@ -1,30 +1,32 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/base')
1
+ require 'chef/knife/joyent_base'
2
2
 
3
- module KnifeJoyent
4
- class JoyentImageList < Chef::Knife
3
+ class Chef
4
+ class Knife
5
+ class JoyentImageList < Knife
5
6
 
6
- include KnifeJoyent::Base
7
+ include Knife::JoyentBase
7
8
 
8
- banner "knife joyent image list <options>"
9
+ banner "knife joyent image list <options>"
9
10
 
10
- def run
11
- images = [
12
- ui.color('ID', :bold),
13
- ui.color('Name', :bold),
14
- ui.color('Version', :bold),
15
- ui.color('OS', :bold),
16
- ui.color('Type', :bold),
17
- ]
11
+ def run
12
+ images = [
13
+ ui.color('ID', :bold),
14
+ ui.color('Name', :bold),
15
+ ui.color('Version', :bold),
16
+ ui.color('OS', :bold),
17
+ ui.color('Type', :bold),
18
+ ]
18
19
 
19
- self.connection.images.sort_by(&:name).each do |i|
20
- images << i.id.to_s
21
- images << i.name
22
- images << i.version
23
- images << i.os
24
- images << i.type
25
- end
20
+ self.connection.images.sort_by(&:name).each do |i|
21
+ images << i.id.to_s
22
+ images << i.name
23
+ images << i.version
24
+ images << i.os
25
+ images << i.type
26
+ end
26
27
 
27
- puts ui.list(images, :uneven_columns_across, 5)
28
+ puts ui.list(images, :uneven_columns_across, 5)
29
+ end
28
30
  end
29
31
  end
30
32
  end
@@ -1,54 +1,55 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/base')
1
+ require 'chef/knife/joyent_base'
2
2
 
3
+ class Chef
4
+ class Knife
5
+ class JoyentKeyAdd < Knife
3
6
 
4
- module KnifeJoyent
5
- class JoyentKeyAdd < Chef::Knife
7
+ include Knife::JoyentBase
6
8
 
7
- include KnifeJoyent::Base
9
+ banner "knife joyent key add -f <keyfile> -k <name>"
8
10
 
9
- banner "knife joyent key add -f <keyfile> -k <name>"
11
+ option :keyname,
12
+ :short => '-k KEY_NAME',
13
+ :long => '--keyname KEY_NAME',
14
+ :description => 'Name for identifying this key'
10
15
 
11
- option :keyname,
12
- :short => '-k KEY_NAME',
13
- :long => '--keyname KEY_NAME',
14
- :description => 'Name for identifying this key'
16
+ option :keyfile,
17
+ :short => '-f KEY_FILE',
18
+ :long => '--keyfile KEY_FILE',
19
+ :description => 'Full path to location of ssh public key'
15
20
 
16
- option :keyfile,
17
- :short => '-f KEY_FILE',
18
- :long => '--keyfile KEY_FILE',
19
- :description => 'Full path to location of ssh public key'
21
+ def run
22
+ keyfile = config[:keyfile]
23
+ keyname = config[:keyname]
20
24
 
21
- def run
22
- keyfile = config[:keyfile]
23
- keyname = config[:keyname]
25
+ unless File.exists?(keyfile)
26
+ ui.error('keyfile specified does not exist')
27
+ exit 1
28
+ end
24
29
 
25
- unless File.exists?(keyfile)
26
- ui.error('keyfile specified does not exist')
27
- exit 1
28
- end
29
30
 
31
+ key = begin
32
+ File.read(keyfile)
33
+ rescue
34
+ puts ui.error('Unable to read contents of keyfile')
35
+ exit 1
36
+ end
30
37
 
31
- key = begin
32
- File.read(keyfile)
33
- rescue
34
- puts ui.error('Unable to read contents of keyfile')
35
- exit 1
36
- end
37
38
 
39
+ begin
40
+ r = self.connection.create_key(
41
+ :name => keyname,
42
+ :key => key
43
+ )
44
+ rescue Excon::Errors::Conflict => e
45
+ body = MultiJson.decode(e.response.body)
46
+ ui.error(body["message"])
47
+ exit 1
48
+ end
38
49
 
39
- begin
40
- r = self.connection.create_key(
41
- :name => keyname,
42
- :key => key
43
- )
44
- rescue Excon::Errors::Conflict => e
45
- body = MultiJson.decode(e.response.body)
46
- ui.error(body["message"])
47
- exit 1
50
+ puts ui.color('Created key: '+keyname, :cyan)
51
+ exit 0
48
52
  end
49
-
50
- puts ui.color('Created key: '+keyname, :cyan)
51
- exit 0
52
53
  end
53
54
  end
54
55
  end
@@ -1,33 +1,34 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/base')
1
+ require 'chef/knife/joyent_base'
2
2
 
3
+ class Chef
4
+ class Knife
5
+ class JoyentKeyDelete < Knife
3
6
 
4
- module KnifeJoyent
5
- class JoyentKeyDelete < Chef::Knife
7
+ include Knife::JoyentBase
6
8
 
7
- include KnifeJoyent::Base
9
+ banner "knife joyent key delete <name>"
8
10
 
9
- banner "knife joyent key delete <name>"
11
+ def run
12
+ unless name_args.size === 1
13
+ show_usage
14
+ end
10
15
 
11
- def run
12
- unless name_args.size === 1
13
- show_usage
14
- end
16
+ keyname = name_args.first
15
17
 
16
- keyname = name_args.first
18
+ begin
19
+ self.connection.delete_key(keyname)
20
+ rescue Excon::Errors::NotFound => e
21
+ ui.error("Key [#{keyname}] does not exist.")
22
+ exit 1
23
+ rescue Excon::Errors::Conflict => e
24
+ body = MultiJson.decode(e.response.body)
25
+ ui.error(body["message"])
26
+ exit 1
27
+ end
17
28
 
18
- begin
19
- self.connection.delete_key(keyname)
20
- rescue Excon::Errors::NotFound => e
21
- ui.error("Key [#{keyname}] does not exist.")
22
- exit 1
23
- rescue Excon::Errors::Conflict => e
24
- body = MultiJson.decode(e.response.body)
25
- ui.error(body["message"])
26
- exit 1
29
+ puts ui.color('Deleted key: '+keyname, :cyan)
30
+ exit 0
27
31
  end
28
-
29
- puts ui.color('Deleted key: '+keyname, :cyan)
30
- exit 0
31
32
  end
32
33
  end
33
34
  end
@@ -1,25 +1,26 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/base')
1
+ require 'chef/knife/joyent_base'
2
2
 
3
- module KnifeJoyent
4
- class JoyentKeyList < Chef::Knife
3
+ class Chef
4
+ class Knife
5
+ class JoyentKeyList < Knife
5
6
 
6
- include KnifeJoyent::Base
7
+ include Knife::JoyentBase
7
8
 
8
- banner "knife joyent key list"
9
+ banner "knife joyent key list"
9
10
 
10
- def run
11
- keys = [
12
- ui.color('Name', :bold),
13
- ui.color('Key', :bold),
14
- ]
11
+ def run
12
+ keys = [
13
+ ui.color('Name', :bold),
14
+ ui.color('Key', :bold),
15
+ ]
15
16
 
16
- self.connection.keys.sort_by(&:name).each do |k|
17
- keys << k.name
18
- keys << k.key[0..32] + '...'
19
- end
20
-
21
- puts ui.list(keys, :uneven_columns_across, 2)
17
+ self.connection.keys.sort_by(&:name).each do |k|
18
+ keys << k.name
19
+ keys << k.key[0..32] + '...'
20
+ end
22
21
 
22
+ puts ui.list(keys, :uneven_columns_across, 2)
23
+ end
23
24
  end
24
25
  end
25
26
  end