knife-joyent 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/LICENSE +13 -0
- data/README.md +64 -0
- data/Rakefile +1 -0
- data/knife-joyent.gemspec +22 -0
- data/lib/knife-joyent.rb +1 -0
- data/lib/knife-joyent/base.rb +46 -0
- data/lib/knife-joyent/joyent_flavor_list.rb +28 -0
- data/lib/knife-joyent/joyent_image_list.rb +30 -0
- data/lib/knife-joyent/joyent_key_add.rb +54 -0
- data/lib/knife-joyent/joyent_key_delete.rb +33 -0
- data/lib/knife-joyent/joyent_key_list.rb +25 -0
- data/lib/knife-joyent/joyent_server_create.rb +38 -0
- data/lib/knife-joyent/joyent_server_list.rb +37 -0
- data/lib/knife-joyent/joyent_server_reboot.rb +34 -0
- data/lib/knife-joyent/joyent_server_resize.rb +44 -0
- data/lib/knife-joyent/joyent_server_start.rb +39 -0
- data/lib/knife-joyent/joyent_server_stop.rb +40 -0
- data/lib/knife-joyent/joyent_snapshot_create.rb +41 -0
- data/lib/knife-joyent/joyent_snapshot_delete.rb +39 -0
- data/lib/knife-joyent/joyent_snapshot_list.rb +44 -0
- data/lib/knife-joyent/version.rb +3 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2012 Joyent, Inc
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
Knife Joyent
|
2
|
+
===
|
3
|
+
|
4
|
+
This is a Knife plugin for Joyent CloudAPI. This plugin gives knife
|
5
|
+
the ability to create, bootstrap, and manage servers on the Joyent Public Cloud
|
6
|
+
as well as Cloud providers powered by Joyent's SmartDataCenter product.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
With chef already installed (> 0.10.0):
|
11
|
+
|
12
|
+
gem install knife-joyent
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
|
16
|
+
For available commands:
|
17
|
+
|
18
|
+
knife joyent --help
|
19
|
+
|
20
|
+
## Configuration
|
21
|
+
|
22
|
+
The following options can be specified in your knife configuration file
|
23
|
+
|
24
|
+
### Required
|
25
|
+
|
26
|
+
You can authenticate against CloudAPI using either:
|
27
|
+
|
28
|
+
a username and password
|
29
|
+
|
30
|
+
knife[:joyent_username] = "Your Joyent CloudAPI username"
|
31
|
+
knife[:joyent_password] = "Your Joyent CloudAPI password"
|
32
|
+
|
33
|
+
or, your ssh key
|
34
|
+
|
35
|
+
knife[:joyent_username] = "Your Joyent CloudAPI username"
|
36
|
+
knife[:joyent_keyname] = "Name of key stored on Joyent"
|
37
|
+
knife[:joyent_keyfile] = "/path/to/your/private/key"
|
38
|
+
|
39
|
+
### Optional
|
40
|
+
|
41
|
+
# Specify a custom API endpoint, this is required if you want to specify
|
42
|
+
# where you want to provision your machines, or if you are using knife with a
|
43
|
+
# provider powered by SmartDataCenter.
|
44
|
+
#
|
45
|
+
# Defaults to https://us-west-1.api.joyentcloud.com/
|
46
|
+
knife[:joyent_api_url] = "https://us-sw-1.api.joyentcloud.com/"
|
47
|
+
|
48
|
+
## License
|
49
|
+
|
50
|
+
Copyright 2012 Joyent, Inc
|
51
|
+
|
52
|
+
Author: Kevin Chan <kevin@joyent.com>
|
53
|
+
|
54
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
55
|
+
you may not use this file except in compliance with the License.
|
56
|
+
You may obtain a copy of the License at
|
57
|
+
|
58
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
59
|
+
|
60
|
+
Unless required by applicable law or agreed to in writing, software
|
61
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
62
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
63
|
+
See the License for the specific language governing permissions and
|
64
|
+
limitations under the License.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'knife-joyent/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "knife-joyent"
|
7
|
+
s.version = KnifeJoyent::VERSION
|
8
|
+
s.has_rdoc = true
|
9
|
+
s.authors = ["Kevin Chan"]
|
10
|
+
s.email = ["kevin@joyent.com"]
|
11
|
+
s.homepage = "http://wiki.opscode.com/display/chef"
|
12
|
+
s.summary = "Joyent CloudAPI Support for Chef's Knife Command"
|
13
|
+
s.description = s.summary
|
14
|
+
s.extra_rdoc_files = ["README.md", "LICENSE"]
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.add_dependency "fog", "1.3.1"
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
end
|
data/lib/knife-joyent.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'knife-joyent/version'
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'chef/knife'
|
2
|
+
|
3
|
+
module KnifeJoyent
|
4
|
+
module Base
|
5
|
+
|
6
|
+
def self.included(includer)
|
7
|
+
includer.class_eval do
|
8
|
+
deps do
|
9
|
+
require 'fog'
|
10
|
+
require 'net/ssh/multi'
|
11
|
+
require 'readline'
|
12
|
+
require 'chef/json_compat'
|
13
|
+
end
|
14
|
+
|
15
|
+
option :joyent_username,
|
16
|
+
:short => '-U USERNAME',
|
17
|
+
:long => '--joyent-username USERNAME',
|
18
|
+
:description => 'Your Joyent username',
|
19
|
+
:proc => Proc.new {|key| Chef::Config[:knife][:joyent_username]}
|
20
|
+
|
21
|
+
option :joyent_password,
|
22
|
+
:short => '-P PASSWORD',
|
23
|
+
:long => '--joyent-password PASSOWRD',
|
24
|
+
:description => 'Your Joyent password',
|
25
|
+
:proc => Proc.new {|key| Chef::Config[:knife][:joyent_password]}
|
26
|
+
|
27
|
+
option :joyent_url,
|
28
|
+
:short => "-L JOYENT_API_URL",
|
29
|
+
:long => "--joyent-api-url JOYENT_API_URL",
|
30
|
+
:description => "Joyent API URL",
|
31
|
+
:proc => Proc.new {|key| Chef::Config[:knife][:joyent_url]}
|
32
|
+
end
|
33
|
+
|
34
|
+
def connection
|
35
|
+
@connection ||= begin
|
36
|
+
connection = Fog::Compute.new(
|
37
|
+
:provider => 'Joyent',
|
38
|
+
:joyent_username => Chef::Config[:knife][:joyent_username],
|
39
|
+
:joyent_password => Chef::Config[:knife][:joyent_password],
|
40
|
+
:joyent_url => Chef::Config[:knife][:joyent_url]
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
|
4
|
+
module KnifeJoyent
|
5
|
+
class JoyentFlavorList < Chef::Knife
|
6
|
+
|
7
|
+
include KnifeJoyent::Base
|
8
|
+
|
9
|
+
banner "knife joyent flavor list <options>"
|
10
|
+
|
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
|
+
]
|
18
|
+
|
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
|
25
|
+
puts ui.list(flavor_list, :columns_across, 4)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
module KnifeJoyent
|
4
|
+
class JoyentImageList < Chef::Knife
|
5
|
+
|
6
|
+
include KnifeJoyent::Base
|
7
|
+
|
8
|
+
banner "knife joyent image list <options>"
|
9
|
+
|
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
|
+
]
|
18
|
+
|
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
|
26
|
+
|
27
|
+
puts ui.list(images, :columns_across, 5)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
|
4
|
+
module KnifeJoyent
|
5
|
+
class JoyentKeyAdd < Chef::Knife
|
6
|
+
|
7
|
+
include KnifeJoyent::Base
|
8
|
+
|
9
|
+
banner "knife joyent key add -f <keyfile> -k <name>"
|
10
|
+
|
11
|
+
option :keyname,
|
12
|
+
:short => '-k KEY_NAME',
|
13
|
+
:long => '--keyname KEY_NAME',
|
14
|
+
:description => 'Name for identifying this key'
|
15
|
+
|
16
|
+
option :keyfile,
|
17
|
+
:short => '-f KEY_FILE',
|
18
|
+
:long => '--keyfile KEY_FILE',
|
19
|
+
:description => 'Full path to location of ssh public key'
|
20
|
+
|
21
|
+
def run
|
22
|
+
keyfile = config[:keyfile]
|
23
|
+
keyname = config[:keyname]
|
24
|
+
|
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
|
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
|
49
|
+
|
50
|
+
puts ui.color('Created key: '+keyname, :cyan)
|
51
|
+
exit 0
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
|
4
|
+
module KnifeJoyent
|
5
|
+
class JoyentKeyDelete < Chef::Knife
|
6
|
+
|
7
|
+
include KnifeJoyent::Base
|
8
|
+
|
9
|
+
banner "knife joyent key delete <name>"
|
10
|
+
|
11
|
+
def run
|
12
|
+
unless name_args.size === 1
|
13
|
+
show_usage
|
14
|
+
end
|
15
|
+
|
16
|
+
keyname = name_args.first
|
17
|
+
|
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
|
28
|
+
|
29
|
+
puts ui.color('Deleted key: '+keyname, :cyan)
|
30
|
+
exit 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
module KnifeJoyent
|
4
|
+
class JoyentKeyList < Chef::Knife
|
5
|
+
|
6
|
+
include KnifeJoyent::Base
|
7
|
+
|
8
|
+
banner "knife joyent key list"
|
9
|
+
|
10
|
+
def run
|
11
|
+
keys = [
|
12
|
+
ui.color('Name', :bold),
|
13
|
+
ui.color('Key', :bold),
|
14
|
+
]
|
15
|
+
|
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, :columns_across, 2)
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module KnifeJoyent
|
2
|
+
class JoyentServerCreate < Chef::Knife
|
3
|
+
|
4
|
+
include KnifeJoyent::Base
|
5
|
+
|
6
|
+
banner 'knife joyent server create (options)'
|
7
|
+
|
8
|
+
option :name,
|
9
|
+
:long => '--name <name>',
|
10
|
+
:description => 'name for this machine'
|
11
|
+
|
12
|
+
option :package,
|
13
|
+
:long => '--flavor <name>',
|
14
|
+
:description => 'specify flavor/package for the server'
|
15
|
+
|
16
|
+
option :dataset,
|
17
|
+
:short => '--image <id>',
|
18
|
+
:description => 'specify image for the server'
|
19
|
+
|
20
|
+
def run
|
21
|
+
if s = self.connection.servers.create(:dataset => config[:dataset],
|
22
|
+
:package => config[:package],
|
23
|
+
:name => config[:name])
|
24
|
+
puts ui.color("Created machine: #{s.uuid}", :cyan)
|
25
|
+
exit 0
|
26
|
+
end
|
27
|
+
rescue => e
|
28
|
+
if e.response && e.response.body.kind_of?(String)
|
29
|
+
error = MultiJson.decode(e.response.body)
|
30
|
+
puts ui.error(error['message'])
|
31
|
+
exit 1
|
32
|
+
else
|
33
|
+
puts ui.error('Unexpected Error Occured:' + e.message)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
|
4
|
+
module KnifeJoyent
|
5
|
+
class JoyentServerList < Chef::Knife
|
6
|
+
|
7
|
+
include KnifeJoyent::Base
|
8
|
+
|
9
|
+
banner "knife joyent server list <options>"
|
10
|
+
|
11
|
+
def run
|
12
|
+
servers = [
|
13
|
+
ui.color('ID', :bold),
|
14
|
+
ui.color('Name', :bold),
|
15
|
+
ui.color('State', :bold),
|
16
|
+
ui.color('Type', :bold),
|
17
|
+
ui.color('Dataset', :bold),
|
18
|
+
ui.color('IPs', :bold),
|
19
|
+
ui.color('Memory', :bold),
|
20
|
+
ui.color('Disk', :bold),
|
21
|
+
]
|
22
|
+
|
23
|
+
self.connection.servers.sort_by(&:name).each do |s|
|
24
|
+
servers << s.id.to_s
|
25
|
+
servers << s.name
|
26
|
+
servers << s.state
|
27
|
+
servers << s.type
|
28
|
+
servers << s.dataset
|
29
|
+
servers << s.ips.join(" ")
|
30
|
+
servers << s.memory.to_s
|
31
|
+
servers << s.disk.to_s
|
32
|
+
end
|
33
|
+
|
34
|
+
puts ui.list(servers, :columns_across, 8)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
|
4
|
+
module KnifeJoyent
|
5
|
+
class JoyentServerReboot < Chef::Knife
|
6
|
+
|
7
|
+
include KnifeJoyent::Base
|
8
|
+
|
9
|
+
banner 'knife joyent server reboot <server_id>'
|
10
|
+
|
11
|
+
def run
|
12
|
+
unless name_args.size === 1
|
13
|
+
show_usage
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
id = name_args.first
|
18
|
+
|
19
|
+
server = self.connection.servers.get(id)
|
20
|
+
unless server
|
21
|
+
puts ui.error("Server with id: #{id} not found")
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
if server.reboot
|
26
|
+
puts ui.color("Rebooted Server #{id}", :cyan)
|
27
|
+
exit 0
|
28
|
+
else
|
29
|
+
puts ui.error("Reboot server failed")
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
|
4
|
+
module KnifeJoyent
|
5
|
+
class JoyentServerResize < Chef::Knife
|
6
|
+
|
7
|
+
include KnifeJoyent::Base
|
8
|
+
|
9
|
+
banner 'knife joyent server resize <server_id> -f <flavor>'
|
10
|
+
|
11
|
+
option :flavor,
|
12
|
+
:short => "-f <flavor>",
|
13
|
+
:long => "--flavor <flavor>",
|
14
|
+
:description => "name of flavor/package to resize to"
|
15
|
+
|
16
|
+
def run
|
17
|
+
unless config[:flavor]
|
18
|
+
show_usage
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
unless name_args.size === 1
|
23
|
+
show_usage
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
id = name_args.first
|
28
|
+
|
29
|
+
server = self.connection.servers.get(id)
|
30
|
+
unless server
|
31
|
+
puts ui.error("Server with id: #{id} not found")
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
|
35
|
+
if self.connection.resize_machine(id, config[:flavor])
|
36
|
+
puts ui.color("Resized server #{id}", :cyan)
|
37
|
+
exit 0
|
38
|
+
else
|
39
|
+
puts ui.error("Resize server failed")
|
40
|
+
exit 1
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
module KnifeJoyent
|
4
|
+
class JoyentServerStart < Chef::Knife
|
5
|
+
|
6
|
+
include KnifeJoyent::Base
|
7
|
+
|
8
|
+
banner 'knife joyent server start <server_id>'
|
9
|
+
|
10
|
+
def run
|
11
|
+
unless name_args.size === 1
|
12
|
+
show_usage
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
|
16
|
+
id = name_args.first
|
17
|
+
|
18
|
+
server = self.connection.servers.get(id)
|
19
|
+
|
20
|
+
unless server
|
21
|
+
puts ui.error("Unable to locate server: #{id}")
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
|
25
|
+
if server.ready?
|
26
|
+
puts ui.error("Server is already started")
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
if server.start
|
31
|
+
puts ui.color("Started server: #{id}", :cyan)
|
32
|
+
exit 0
|
33
|
+
else
|
34
|
+
puts ui.error("Start server failed")
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
|
4
|
+
module KnifeJoyent
|
5
|
+
class JoyentServerStop < Chef::Knife
|
6
|
+
|
7
|
+
include KnifeJoyent::Base
|
8
|
+
|
9
|
+
banner 'knife joyent server stop <server_id>'
|
10
|
+
|
11
|
+
def run
|
12
|
+
unless name_args.size === 1
|
13
|
+
show_usage
|
14
|
+
exit 1
|
15
|
+
end
|
16
|
+
|
17
|
+
id = name_args.first
|
18
|
+
|
19
|
+
server = self.connection.servers.get(id)
|
20
|
+
|
21
|
+
unless server
|
22
|
+
puts ui.error("Unable to locate server: #{id}")
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
|
26
|
+
if server.stopped?
|
27
|
+
puts ui.error("Server #{id} is already stopped")
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
if server.stop
|
32
|
+
puts ui.color("Stopped server: #{id}", :cyan)
|
33
|
+
exit 0
|
34
|
+
else
|
35
|
+
puts ui.error("Failed to stop server")
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module KnifeJoyent
|
2
|
+
class JoyentSnapshotCreate < Chef::Knife
|
3
|
+
|
4
|
+
include KnifeJoyent::Base
|
5
|
+
|
6
|
+
banner 'knife joyent snapshot create <server> <snapshot_name>'
|
7
|
+
|
8
|
+
def run
|
9
|
+
unless name_args.size == 2
|
10
|
+
show_usage
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
|
14
|
+
server = name_args[0]
|
15
|
+
ssname = name_args[1]
|
16
|
+
|
17
|
+
snapshot = self.connection.snapshots.create(server, ssname)
|
18
|
+
puts ui.color("Created snapshot", :cyan)
|
19
|
+
puts ui.output({
|
20
|
+
:server => snapshot.machine_id,
|
21
|
+
:name => snapshot.name,
|
22
|
+
:state => snapshot.state,
|
23
|
+
:created => snapshot.created
|
24
|
+
})
|
25
|
+
exit 0
|
26
|
+
rescue Excon::Errors::Conflict => e
|
27
|
+
if e.response && e.response.body.kind_of?(String)
|
28
|
+
error = MultiJson.decode(e.response.body)
|
29
|
+
puts ui.error(error['message'])
|
30
|
+
exit 1
|
31
|
+
else
|
32
|
+
puts ui.error(e.message)
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
rescue => e
|
36
|
+
puts ui.error('Unexpected Error Occured:' + e.message)
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module KnifeJoyent
|
2
|
+
class JoyentSnapshotDelete < Chef::Knife
|
3
|
+
|
4
|
+
include KnifeJoyent::Base
|
5
|
+
|
6
|
+
banner 'knife joyent snapshot delete <server> <snapshot_name>'
|
7
|
+
|
8
|
+
def run
|
9
|
+
unless name_args.size == 2
|
10
|
+
show_usage
|
11
|
+
exit 1
|
12
|
+
end
|
13
|
+
|
14
|
+
server = name_args[0]
|
15
|
+
ssname = name_args[1]
|
16
|
+
|
17
|
+
snapshot = self.connection.snapshots.get(server, ssname)
|
18
|
+
snapshot.destroy
|
19
|
+
puts ui.color("Deleted snapshot #{snapshot.name}", :cyan)
|
20
|
+
exit 0
|
21
|
+
rescue Excon::Errors::NotFound => e
|
22
|
+
puts ui.error("Snapshot #{ssname} on server #{server} not found")
|
23
|
+
exit 1
|
24
|
+
rescue Excon::Errors::Conflict => e
|
25
|
+
if e.response && e.response.body.kind_of?(String)
|
26
|
+
error = MultiJson.decode(e.response.body)
|
27
|
+
puts ui.error(error['message'])
|
28
|
+
exit 1
|
29
|
+
else
|
30
|
+
puts ui.error(e.message)
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
rescue => e
|
34
|
+
puts ui.error('Unexpected Error Occured:' + e.message)
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/base')
|
2
|
+
|
3
|
+
|
4
|
+
module KnifeJoyent
|
5
|
+
class JoyentSnapshotList < Chef::Knife
|
6
|
+
|
7
|
+
include KnifeJoyent::Base
|
8
|
+
|
9
|
+
banner "knife joyent snapshot list <server_id>"
|
10
|
+
|
11
|
+
def run
|
12
|
+
|
13
|
+
unless name_args.size == 1
|
14
|
+
show_usage
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
|
18
|
+
server = name_args.first
|
19
|
+
|
20
|
+
snapshots = [
|
21
|
+
ui.color('ID', :bold),
|
22
|
+
ui.color('State', :bold),
|
23
|
+
ui.color('Created', :bold),
|
24
|
+
]
|
25
|
+
|
26
|
+
self.connection.snapshots.all(server).each do |s|
|
27
|
+
snapshots << ui.color(s.name, :bold)
|
28
|
+
snapshots << case s.state
|
29
|
+
when "queued" then
|
30
|
+
ui.color(s.state, :yellow)
|
31
|
+
when "success" then
|
32
|
+
ui.color(s.state, :green)
|
33
|
+
else
|
34
|
+
ui.color(s.state, :red)
|
35
|
+
end
|
36
|
+
snapshots << s.created.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
puts ui.list(snapshots, :columns_across, 3)
|
40
|
+
rescue Fog::Compute::Joyent::Errors::NotFound
|
41
|
+
puts ui.error("Server #{server} not found.")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knife-joyent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Kevin Chan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-04-11 00:00:00 +08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: fog
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - "="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 25
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 3
|
33
|
+
- 1
|
34
|
+
version: 1.3.1
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
description: Joyent CloudAPI Support for Chef's Knife Command
|
38
|
+
email:
|
39
|
+
- kevin@joyent.com
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README.md
|
46
|
+
- LICENSE
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- knife-joyent.gemspec
|
54
|
+
- lib/knife-joyent.rb
|
55
|
+
- lib/knife-joyent/base.rb
|
56
|
+
- lib/knife-joyent/joyent_flavor_list.rb
|
57
|
+
- lib/knife-joyent/joyent_image_list.rb
|
58
|
+
- lib/knife-joyent/joyent_key_add.rb
|
59
|
+
- lib/knife-joyent/joyent_key_delete.rb
|
60
|
+
- lib/knife-joyent/joyent_key_list.rb
|
61
|
+
- lib/knife-joyent/joyent_server_create.rb
|
62
|
+
- lib/knife-joyent/joyent_server_list.rb
|
63
|
+
- lib/knife-joyent/joyent_server_reboot.rb
|
64
|
+
- lib/knife-joyent/joyent_server_resize.rb
|
65
|
+
- lib/knife-joyent/joyent_server_start.rb
|
66
|
+
- lib/knife-joyent/joyent_server_stop.rb
|
67
|
+
- lib/knife-joyent/joyent_snapshot_create.rb
|
68
|
+
- lib/knife-joyent/joyent_snapshot_delete.rb
|
69
|
+
- lib/knife-joyent/joyent_snapshot_list.rb
|
70
|
+
- lib/knife-joyent/version.rb
|
71
|
+
has_rdoc: true
|
72
|
+
homepage: http://wiki.opscode.com/display/chef
|
73
|
+
licenses: []
|
74
|
+
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.3.7
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Joyent CloudAPI Support for Chef's Knife Command
|
105
|
+
test_files: []
|
106
|
+
|