docli 0.0.2.pre.alpha.pre.15 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/docli +32 -1
- data/lib/cmd/authen.rb +36 -0
- data/lib/cmd/create_new_droplets.rb +164 -0
- data/lib/docli.rb +5 -111
- data/lib/docli/create_new_droplets.rb +69 -0
- data/lib/docli/options_parse.rb +72 -0
- data/lib/docli/version.rb +8 -2
- metadata +16 -120
- data/.byebug_history +0 -9
- data/.gitignore +0 -13
- data/.rspec +0 -2
- data/.travis.yml +0 -18
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -3
- data/LICENSE.txt +0 -21
- data/README.md +0 -47
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/dev-build.sh +0 -4
- data/docli.gemspec +0 -54
- data/example/new-droplets.yaml +0 -20
- data/example/resources.template +0 -231
- data/lib/cmd/account.rb +0 -9
- data/lib/cmd/actions.rb +0 -15
- data/lib/cmd/certificates.rb +0 -1
- data/lib/cmd/domain_records.rb +0 -1
- data/lib/cmd/domains.rb +0 -12
- data/lib/cmd/droplets.rb +0 -1
- data/lib/cmd/floating_ips.rb +0 -1
- data/lib/cmd/images.rb +0 -1
- data/lib/cmd/loadbalancers.rb +0 -1
- data/lib/cmd/regions.rb +0 -1
- data/lib/cmd/sizes.rb +0 -1
- data/lib/cmd/snapshots.rb +0 -1
- data/lib/cmd/sshkeys.rb +0 -1
- data/lib/cmd/tags.rb +0 -1
- data/lib/cmd/volume.rb +0 -51
- data/lib/docli/create.rb +0 -52
- data/lib/docli/delete.rb +0 -4
- data/lib/docli/get.rb +0 -70
- data/lib/docli/get_user_information.rb +0 -1
- data/lib/docli/list_all_domains.rb +0 -10
- data/lib/docli/subcommand_base.rb +0 -11
- data/lib/docli/utils.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b5a19feb4efba06936d7508521a1f300910110f
|
4
|
+
data.tar.gz: c57ddd636a57812bb8d35780dd3a3435879da65e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ac7aa347385a2955b307966430febc0a0696d3d06e459b77554ba661d1ec559beb57c63ec29b1a50312c03c3112cb29239dcf31aba26cb90174b0472684b57b
|
7
|
+
data.tar.gz: 345ee1f4405c231ae0664a3f7c9cf6f156fc6b0f01e1f0b9e0df97258dbc9e34f820ad43025794dd1889a7023ece5a23cc89766ec34e771704604549950ed16f
|
data/exe/docli
CHANGED
@@ -1,5 +1,36 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
STDOUT.sync = true
|
2
3
|
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
5
|
+
|
6
|
+
require 'optparse'
|
3
7
|
require 'docli'
|
4
8
|
|
5
|
-
|
9
|
+
opt_parser = OptionParser.new do |opt|
|
10
|
+
opt.banner = "Usage: docli COMMAND [OPTIONS]"
|
11
|
+
opt.separator ""
|
12
|
+
opt.separator "Commands"
|
13
|
+
opt.separator " create / apply -f : create new resources from YAML config file"
|
14
|
+
opt.separator " (Support only YAML at the moment)"
|
15
|
+
opt.separator " droplets: droplets actions"
|
16
|
+
opt.separator ""
|
17
|
+
opt.separator "Options"
|
18
|
+
opt.on( "-v", "--version", String,
|
19
|
+
"Show version of DoCli." )
|
20
|
+
opt.on("-h","--help","show help message")
|
21
|
+
end
|
22
|
+
|
23
|
+
case ARGV[0]
|
24
|
+
when "create", "apply"
|
25
|
+
argv = ARGV*" "
|
26
|
+
DoCli::Parser.file_parse argv
|
27
|
+
when "droplets"
|
28
|
+
argv = ARGV*" "
|
29
|
+
DoCli::Parser.droplets_parse argv
|
30
|
+
when "-v", "--version"
|
31
|
+
DoCli::Version.show_version
|
32
|
+
when "-h", "--help", ""
|
33
|
+
puts opt_parser
|
34
|
+
else
|
35
|
+
puts opt_parser
|
36
|
+
end
|
data/lib/cmd/authen.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Authentication with DigitalOcean
|
2
|
+
module Cmd
|
3
|
+
class Authen
|
4
|
+
def self.check_config_file_exists
|
5
|
+
if !File.exists?(ENV['HOME'] + "/.digitalocean/config")
|
6
|
+
puts "Miss DigitalOcean config, please init your config " + "docli config create".red
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.get_token
|
12
|
+
file_config = ENV['HOME'] + '/.digitalocean/config'
|
13
|
+
|
14
|
+
exception_message = "Miss the DO config files, please run: " + "docli digitalocean config create".red + " to create a new config file"
|
15
|
+
unless File.exist?(file_config)
|
16
|
+
puts exception_message
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
file_data = {}
|
21
|
+
File.open(file_config, 'r') do |file|
|
22
|
+
file.each_line do |line|
|
23
|
+
line_data = line.split(' = ')
|
24
|
+
file_data[line_data[0]] = line_data[1]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
return file_data['DO_TOKEN']
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def self.client
|
33
|
+
@@client ||= DropletKit::Client.new(access_token: get_token)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
# Create new droplets
|
2
|
+
|
3
|
+
module Cmd
|
4
|
+
class NewDroplets
|
5
|
+
require 'yaml'
|
6
|
+
def self.create_new_droplets options
|
7
|
+
@client = Cmd::Authen.client
|
8
|
+
table = []
|
9
|
+
|
10
|
+
if options[:file_config] != nil
|
11
|
+
|
12
|
+
if options[:name] != nil
|
13
|
+
puts "Please specify the name of droplets into YAML config files, do not use both."
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
context = YAML.load(File.open(options[:file_config]))
|
18
|
+
resource_first_key = context.keys[0]
|
19
|
+
context[resource_first_key].reject!{ |k| k == "resource_type"}.each do |key, value|
|
20
|
+
if value['specs']['user_data'].nil? || value['specs']['user_data']['files'].nil? && value['specs']['user_data']['scripts'].nil?
|
21
|
+
user_data = nil
|
22
|
+
else
|
23
|
+
user_data = value['specs']['user_data']['files'].nil? ? value['specs']['user_data']['scripts'] : File.read(value['specs']['user_data']['files'])
|
24
|
+
end
|
25
|
+
|
26
|
+
if value['specs']['name'].length > 1
|
27
|
+
new_droplet = DropletKit::Droplet.new(
|
28
|
+
names: value['specs']['name'],
|
29
|
+
region: options[:region].nil? ? value['specs']['region'] : options[:region],
|
30
|
+
size: options[:size].nil? ? value['specs']['size'] : options[:size],
|
31
|
+
image: options[:image].nil? ? value['specs']['image'] : options[:image],
|
32
|
+
ipv6: options[:ipv6].nil? ? value['specs']['ipv6'] : options[:ipv6],
|
33
|
+
tags: options[:tags].nil? ? value['specs']['tags'] : options[:tags],
|
34
|
+
backups: options[:backups].nil? ? value['specs']['backups'] : options[:backups],
|
35
|
+
ssh_keys: options[:ssh_keys].nil? ? value['specs']['ssh_keys'] : options[:ssh_keys],
|
36
|
+
private_networking: options[:private_networking].nil? ? value['specs']['private_networking'] : options[:private_networking],
|
37
|
+
user_data: options[:user_data].nil? ? user_data : options[:user_data],
|
38
|
+
volumes: options[:volumes].nil? ? value['specs']['volumes'] : options[:volumes]
|
39
|
+
)
|
40
|
+
create_new_droplet = @client.droplets.create_multiple(new_droplet)
|
41
|
+
create_new_droplet.each do |droplet|
|
42
|
+
table << {
|
43
|
+
:id => droplet.id,
|
44
|
+
:name => droplet.name,
|
45
|
+
:region => droplet.region.name,
|
46
|
+
:size => droplet.size,
|
47
|
+
:status => droplet.status
|
48
|
+
}
|
49
|
+
end
|
50
|
+
else
|
51
|
+
new_droplet = DropletKit::Droplet.new(
|
52
|
+
name: value['specs']['name'][0],
|
53
|
+
region: options[:region].nil? ? value['specs']['region'] : options[:region],
|
54
|
+
size: options[:size].nil? ? value['specs']['size'] : options[:size],
|
55
|
+
image: options[:image].nil? ? value['specs']['image'] : options[:image],
|
56
|
+
ipv6: options[:ipv6].nil? ? value['specs']['ipv6'] : options[:ipv6],
|
57
|
+
tags: options[:tags].nil? ? value['specs']['tags'] : options[:tags],
|
58
|
+
backups: options[:backups].nil? ? value['specs']['backups'] : options[:backups],
|
59
|
+
ssh_keys: options[:ssh_keys].nil? ? value['specs']['ssh_keys'] : options[:ssh_keys],
|
60
|
+
private_networking: options[:private_networking].nil? ? value['specs']['private_networking'] : options[:private_networking],
|
61
|
+
user_data: options[:user_data].nil? ? user_data : options[:user_data],
|
62
|
+
volumes: options[:volumes].nil? ? value['specs']['volumes'] : options[:volumes]
|
63
|
+
)
|
64
|
+
create_new_droplet = @client.droplets.create(new_droplet)
|
65
|
+
table << {
|
66
|
+
:id => create_new_droplet.id,
|
67
|
+
:name => create_new_droplet.name,
|
68
|
+
:region => create_new_droplet.region.name,
|
69
|
+
:size => create_new_droplet.size,
|
70
|
+
:status => create_new_droplet.status
|
71
|
+
}
|
72
|
+
end
|
73
|
+
end
|
74
|
+
else
|
75
|
+
new_droplet = DropletKit::Droplet.new(
|
76
|
+
name: options[:name],
|
77
|
+
region: options[:region].nil? ? "nyc1" : options[:region],
|
78
|
+
size: options[:size].nil? ? "512mb" : options[:size],
|
79
|
+
image: options[:image].nil? ? "21669205" : options[:image],
|
80
|
+
ipv6: options[:ipv6].nil? ? true : options[:ipv6],
|
81
|
+
tags: options[:tags],
|
82
|
+
backups: options[:backups].nil? ? true : options[:backups],
|
83
|
+
ssh_keys: options[:ssh_keys],
|
84
|
+
private_networking: options[:private_networking].nil? ? false : options[:private_networking],
|
85
|
+
user_data: options[:user_data],
|
86
|
+
volumes: options[:volumes]
|
87
|
+
)
|
88
|
+
create_new_droplet = @client.droplets.create(new_droplet)
|
89
|
+
table << {
|
90
|
+
:id => create_new_droplet.id,
|
91
|
+
:name => create_new_droplet.name,
|
92
|
+
:region => create_new_droplet.region.name,
|
93
|
+
:size => create_new_droplet.size,
|
94
|
+
:status => create_new_droplet.status
|
95
|
+
}
|
96
|
+
end
|
97
|
+
puts "Droplets create successfully".red if !table[0][:id].nil?
|
98
|
+
tp table
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
def self.create_new_droplets_from_file value
|
103
|
+
@client = Cmd::Authen.client
|
104
|
+
table = []
|
105
|
+
value.reject!{ |k| k == "resource_type"}.each do |key, value|
|
106
|
+
if value['specs']['user_data'].nil? || value['specs']['user_data']['files'].nil? && value['specs']['user_data']['scripts'].nil?
|
107
|
+
user_data = nil
|
108
|
+
else
|
109
|
+
user_data = value['specs']['user_data']['files'].nil? ? value['specs']['user_data']['scripts'] : File.read(value['specs']['user_data']['files'])
|
110
|
+
end
|
111
|
+
|
112
|
+
if value['specs']['name'].length > 1
|
113
|
+
new_droplet = DropletKit::Droplet.new(
|
114
|
+
names: value['specs']['name'],
|
115
|
+
region: value['specs']['region'],
|
116
|
+
size: value['specs']['size'],
|
117
|
+
image: value['specs']['image'],
|
118
|
+
ipv6: value['specs']['ipv6'],
|
119
|
+
tags: value['specs']['tags'],
|
120
|
+
backups: value['specs']['backups'],
|
121
|
+
ssh_keys: value['specs']['ssh_keys'],
|
122
|
+
private_networking: value['specs']['private_networking'],
|
123
|
+
user_data: user_data,
|
124
|
+
volumes: value['specs']['volumes']
|
125
|
+
)
|
126
|
+
create_new_droplet = @client.droplets.create_multiple(new_droplet)
|
127
|
+
create_new_droplet.each do |droplet|
|
128
|
+
table << {
|
129
|
+
:id => droplet.id,
|
130
|
+
:name => droplet.name,
|
131
|
+
:region => droplet.region.name,
|
132
|
+
:size => droplet.size,
|
133
|
+
:status => droplet.status
|
134
|
+
}
|
135
|
+
end
|
136
|
+
else
|
137
|
+
new_droplet = DropletKit::Droplet.new(
|
138
|
+
name: value['specs']['name'][0],
|
139
|
+
region: value['specs']['region'],
|
140
|
+
size: value['specs']['size'],
|
141
|
+
image: value['specs']['image'],
|
142
|
+
ipv6: value['specs']['ipv6'],
|
143
|
+
tags: value['specs']['tags'],
|
144
|
+
backups: value['specs']['backups'],
|
145
|
+
ssh_keys: value['specs']['ssh_keys'],
|
146
|
+
private_networking: value['specs']['private_networking'],
|
147
|
+
user_data: user_data,
|
148
|
+
volumes: value['specs']['volumes']
|
149
|
+
)
|
150
|
+
create_new_droplet = @client.droplets.create(new_droplet)
|
151
|
+
table << {
|
152
|
+
:id => create_new_droplet.id,
|
153
|
+
:name => create_new_droplet.name,
|
154
|
+
:region => create_new_droplet.region.name,
|
155
|
+
:size => create_new_droplet.size,
|
156
|
+
:status => create_new_droplet.status
|
157
|
+
}
|
158
|
+
end
|
159
|
+
end
|
160
|
+
puts "Droplets create successfully".red if !table[0][:id].nil?
|
161
|
+
tp table
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
data/lib/docli.rb
CHANGED
@@ -5,122 +5,16 @@ def require_all(path)
|
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
require '
|
8
|
+
require 'rubygems'
|
9
9
|
require 'droplet_kit'
|
10
10
|
require 'colorize'
|
11
11
|
require 'json'
|
12
12
|
require 'table_print'
|
13
|
-
require 'yaml'
|
14
|
-
require 'byebug'
|
15
|
-
require 'fileutils'
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
require 'docli/utils'
|
20
|
-
require 'docli/create'
|
21
|
-
require 'docli/delete'
|
22
|
-
require 'docli/get'
|
23
|
-
|
24
|
-
module Docli
|
25
|
-
|
26
|
-
CONFIG_FILE = ENV['HOME'] + '/.docli/config'
|
27
|
-
|
28
|
-
@@client = nil
|
29
|
-
|
30
|
-
def self.client=(client)
|
31
|
-
@@client = client
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.client
|
35
|
-
@@client
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.debug?
|
39
|
-
true
|
40
|
-
end
|
41
|
-
|
42
|
-
class Main < Thor
|
43
|
-
|
44
|
-
def self.start(*args)
|
45
|
-
super
|
46
|
-
rescue DropletKit::Error => ex
|
47
|
-
puts 'Error occured'.red + ": #{ex.message}"
|
48
|
-
end
|
49
|
-
|
50
|
-
def initialize(args = [], local_options = {}, config = {})
|
51
|
-
require_config! unless %w{help init version config}.include? config[:current_command].name
|
52
|
-
super
|
53
|
-
end
|
54
|
-
|
55
|
-
map %w[--version -v] => :version
|
56
|
-
|
57
|
-
desc 'version', 'Show version information'
|
58
|
-
def version
|
59
|
-
puts "DigitalOcean CommandLine Interface version #{Docli::VERSION}"
|
60
|
-
end
|
61
|
-
|
62
|
-
desc 'config', 'Init or update config'
|
63
|
-
def config
|
64
|
-
access_token = nil
|
65
|
-
current_config = configured? ? read_config : {}
|
66
|
-
current_access_token = current_config[:access_token]
|
67
|
-
new_access_token = ask "Your DigitalOcean access token [#{current_access_token}]: "
|
68
|
-
new_access_token = nil if new_access_token.blank?
|
69
|
-
unless access_token = new_access_token || current_access_token
|
70
|
-
puts 'Failed to config, empty access token !'
|
71
|
-
exit
|
72
|
-
else
|
73
|
-
write_config(:access_token => access_token)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
desc 'create', 'Create a resource by filename or stdin'
|
78
|
-
subcommand 'create', Create
|
79
|
-
|
80
|
-
desc 'get', 'Display one or many resource'
|
81
|
-
subcommand 'get', Get
|
82
|
-
|
83
|
-
desc 'delete', 'Delete resources by filenames, stdin, resources and names, or by resources and label selector'
|
84
|
-
subcommand 'delete', Delete
|
85
|
-
|
86
|
-
private
|
87
|
-
|
88
|
-
def configured?
|
89
|
-
File.exists?(Docli::CONFIG_FILE)
|
90
|
-
end
|
91
|
-
|
92
|
-
def require_config!
|
93
|
-
unless configured?
|
94
|
-
puts "Missing config, run #{'docli config'.yellow} to init your"
|
95
|
-
exit
|
96
|
-
end
|
97
|
-
Docli.client ||= DropletKit::Client.new(access_token: read_config[:access_token])
|
98
|
-
end
|
99
|
-
|
100
|
-
def read_config
|
101
|
-
result = {}
|
102
|
-
File.read(Docli::CONFIG_FILE).split("\n").map do |line|
|
103
|
-
k, v = line.split("=").map(&:strip)
|
104
|
-
result[k.to_sym] = v
|
105
|
-
end
|
106
|
-
result
|
107
|
-
end
|
108
|
-
|
109
|
-
def write_config(config = {})
|
110
|
-
dir = Docli::CONFIG_FILE.split('/')[0..-2].join('/')
|
111
|
-
unless File.directory?(dir)
|
112
|
-
FileUtils::mkdir dir
|
113
|
-
FileUtils.touch Docli::CONFIG_FILE
|
114
|
-
puts 'Create ' + Docli::CONFIG_FILE.green
|
115
|
-
end
|
116
|
-
File.open(Docli::CONFIG_FILE, 'w+') do |file|
|
117
|
-
file.write config.map { |k,v| "#{k} = #{v}" }.join
|
118
|
-
end
|
119
|
-
puts "Config updated !"
|
120
|
-
end
|
121
|
-
end
|
14
|
+
module DoCli
|
15
|
+
require_all 'docli'
|
122
16
|
end
|
123
17
|
|
124
18
|
module Cmd
|
125
|
-
|
126
|
-
end
|
19
|
+
require_all 'cmd'
|
20
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Docli
|
2
|
+
class Droplets
|
3
|
+
def self.create_new_droplets argv
|
4
|
+
|
5
|
+
options = {}
|
6
|
+
|
7
|
+
opt_parser = OptionParser.new do |opt|
|
8
|
+
opt.banner = "Usage: docli droplets create [OPTIONS]"
|
9
|
+
opt.separator ""
|
10
|
+
opt.separator "Commands"
|
11
|
+
opt.separator " create: create new droplets on DigitalOcean"
|
12
|
+
opt.separator ""
|
13
|
+
opt.separator "Options"
|
14
|
+
opt.on("-f", "--file ", "create from YAML config file") do |file|
|
15
|
+
options[:file_config] = file
|
16
|
+
end
|
17
|
+
opt.on( "-n ", "--name ", "droplets name (require for the hostname of droplets" ) do |name|
|
18
|
+
options[:name] = name
|
19
|
+
end
|
20
|
+
opt.on("-r ", "--region ", "define region, default NYC1") do |region|
|
21
|
+
options[:region] = region
|
22
|
+
end
|
23
|
+
opt.on("-s ", "--size ", "define size of droplets, exp: 512mb, 1gb... default 512mb") do |s|
|
24
|
+
options[:size] = s
|
25
|
+
end
|
26
|
+
opt.on("-i ", "--image ", "define image name or image id on DO, default 21669205 - Ubuntu 16x04") do |i|
|
27
|
+
options[:image] = i
|
28
|
+
end
|
29
|
+
opt.on("--ipv6 ", "turn on or off ipv6 on droplets [true or false], default true") do |ipv6|
|
30
|
+
options[:ipv6] = ipv6
|
31
|
+
end
|
32
|
+
opt.on("-v ", "--volumes ", "define block storage will attach to droplets support one per one") do |volumes|
|
33
|
+
options[:volumes] = volumes
|
34
|
+
end
|
35
|
+
opt.on("-m ", "--monitoring ", "true or false: enable monitoring in new droplets") do |monitoring|
|
36
|
+
options[:monitoring] = monitoring
|
37
|
+
end
|
38
|
+
opt.on("-u ", "--user-data ", "Add command or cloud config on first boot droplets") do |user_data|
|
39
|
+
options[:user_data] = user_data
|
40
|
+
end
|
41
|
+
opt.on("-p", "--private-networking", "true or false: enable private network eth") do |priv_network|
|
42
|
+
options[:private_networing] = priv_network
|
43
|
+
end
|
44
|
+
opt.on("-b", "--backups", "true or false: enabled auto backup") do |backups|
|
45
|
+
options[:backups] = backups
|
46
|
+
end
|
47
|
+
opt.on("-t ", "--tags ", Array, "Add tags to droplets") do |tags|
|
48
|
+
options[:tags] = tags
|
49
|
+
end
|
50
|
+
opt.on("-h", "--help", "show help message") do
|
51
|
+
puts opt_parser
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
opt_parser.parse!
|
57
|
+
if options[:name].nil? && options[:file_config].nil?
|
58
|
+
puts "Please specify the name of droplet".red
|
59
|
+
puts opt_parser
|
60
|
+
exit
|
61
|
+
elsif options[:name].nil? && !File.exists?(options[:file_config])
|
62
|
+
puts "Please specify file that you want to use for creation".red
|
63
|
+
puts opt_parser
|
64
|
+
exit
|
65
|
+
end
|
66
|
+
Cmd::NewDroplets.create_new_droplets options
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|