dimension_shell 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -4
- data/README.md +21 -3
- data/lib/dimension_shell/cli.rb +52 -18
- data/lib/dimension_shell/cloud_control.rb +12 -7
- data/lib/dimension_shell/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a3649b982ea2c25c35ca9c4ab65b595cc591312
|
4
|
+
data.tar.gz: e2758771f3f09bab789316d94449899c4c343f43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b115091ff58261551a0aefeece15826d36e02c9a1458643e9fab25709403b9acf7bd77d63c2dd83d30378ff1086b186ea922bb999bdba004ca78f9eff550653
|
7
|
+
data.tar.gz: a5b491b8d1fba2bbc9ec355aeec1630af1f5bbdc394593237672dcabf977db57d43304a89e9545a89afb3c653755fdb381c0cc320404d25a4a052c86b20b405f
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
- 0.3.0 Added `list` command
|
4
|
+
- Added `list` command, which lists the first 250 servers for the given region.
|
5
|
+
- Added ssh-username to establishing connection-announcement.
|
6
|
+
- Internal improvements
|
7
|
+
- 0.2.3 Linked gem-home to Github-repo, added example to README
|
8
|
+
- 0.2.2 Initial commit
|
9
|
+
- Hooray! :candy:
|
data/README.md
CHANGED
@@ -11,21 +11,38 @@ root@2a00:33a0:47c0:110:1211:468:ac2d:62de:191f's password: *
|
|
11
11
|
|
12
12
|
## Usage
|
13
13
|
|
14
|
+
### Connect
|
15
|
+
|
14
16
|
```
|
15
17
|
$ dsh connect SERVERNAME -r REGION -o ORGANIZATION -u USERNAME -p PASSWORD -s SHELL_USER
|
16
18
|
```
|
17
19
|
|
18
|
-
Connects to the
|
20
|
+
Connects to the DimensionData-API at the specified REGION with the ORGANIZATION-id, USERNAME and PASSWORD to fetch all servers matching to SERVERNAME.
|
19
21
|
|
20
22
|
If a matching server is found, its primary ipv6-address is taken to open a ssh-connection with the provided SHELL_USER.
|
21
23
|
|
22
24
|
If the SHELL_USER is omitted, the connection will be established as `root`.
|
23
25
|
|
24
|
-
###
|
26
|
+
### list
|
27
|
+
|
28
|
+
```
|
29
|
+
$ dsh list -r REGION -o ORGANIZATION -u USERNAME -p PASSWORD
|
30
|
+
```
|
31
|
+
|
32
|
+
Connects to the DimensionData-API at the specified Region with the ORGANIZATION-id, USERNAME and PASSWORD to fetch a list of all servers at the given region.
|
33
|
+
|
34
|
+
If the API-call is successful the returned servernames will be printed, followed by their operating system and their current state:
|
35
|
+
|
36
|
+
``
|
37
|
+
super-server (UBUNTU12/64) - NORMAL
|
38
|
+
1 server/s in total.
|
39
|
+
``
|
40
|
+
|
41
|
+
#### Region
|
25
42
|
|
26
43
|
The region-code is expanded to the subdomain `api-REGION`, f.e. the region-code `eu` is expanded to `https://api-eu.dimensiondata.com`.
|
27
44
|
|
28
|
-
According to the API-documentation the following region-codes
|
45
|
+
According to the API-documentation the following region-codes will be accepted by the API:
|
29
46
|
|
30
47
|
```
|
31
48
|
na: North America
|
@@ -60,6 +77,7 @@ Install it via Rubygems.org:
|
|
60
77
|
```
|
61
78
|
$ gem install dimension_shell
|
62
79
|
```
|
80
|
+
|
63
81
|
# Help
|
64
82
|
|
65
83
|
File an issue - pull-requests are welcome.
|
data/lib/dimension_shell/cli.rb
CHANGED
@@ -7,35 +7,51 @@ require 'dimension_shell/cloud_control'
|
|
7
7
|
|
8
8
|
module DimensionShell
|
9
9
|
class Cli < Thor
|
10
|
+
default_options = {
|
11
|
+
%w(region -r) => :string,
|
12
|
+
%w(organization -o) => :string,
|
13
|
+
%w(username -u) => :string,
|
14
|
+
%w(password -p) => :string,
|
15
|
+
}
|
10
16
|
|
11
|
-
desc 'connect SERVERNAME', '
|
12
|
-
|
13
|
-
option :
|
14
|
-
option :username, type: :string, aliases: :u
|
15
|
-
option :password, type: :string, aliases: :p
|
16
|
-
option :shell_user, type: :string, aliases: :s
|
17
|
+
desc 'connect SERVERNAME', 'connects to the server called SERVERNAME'
|
18
|
+
options default_options
|
19
|
+
option :shell_user, type: :string, aliases: '-s'
|
17
20
|
def connect(servername)
|
18
|
-
|
21
|
+
_init_command(options)
|
19
22
|
shell_user = options[:shell_user] || configatron.shell_user || 'root'
|
20
|
-
|
21
|
-
region: options[:region] || configatron.region,
|
22
|
-
organization: options[:organization] || configatron.organization,
|
23
|
-
username: options[:username] || configatron.username,
|
24
|
-
password: options[:password] || configatron.password
|
25
|
-
})
|
23
|
+
|
26
24
|
result = @cloud_control.get_server servername
|
27
|
-
|
28
|
-
|
25
|
+
|
26
|
+
if result[:failure] then
|
27
|
+
_api_access_failed result
|
29
28
|
elsif result['totalCount'] != 1 then
|
30
|
-
|
29
|
+
_puts %Q(No servername matched to "#{servername}".)
|
31
30
|
else
|
32
31
|
server = result['server'].first
|
33
32
|
primary_ipv6 = server['networkInfo']['primaryNic']['ipv6']
|
34
|
-
puts "
|
33
|
+
puts "Server \"#{servername}\" found, opening secure shell to #{shell_user}@#{primary_ipv6}."
|
35
34
|
Kernel.exec("ssh #{shell_user}@#{primary_ipv6}")
|
36
35
|
end
|
37
36
|
end
|
38
37
|
|
38
|
+
desc 'list', 'lists all server available in the given region'
|
39
|
+
options default_options
|
40
|
+
def list
|
41
|
+
_init_command(options)
|
42
|
+
|
43
|
+
result = @cloud_control.get_server_list
|
44
|
+
|
45
|
+
if result[:failure] then
|
46
|
+
_api_access_failed result
|
47
|
+
else
|
48
|
+
result['server'].each { |server|
|
49
|
+
puts "#{server['name']} (#{server['operatingSystem']['displayName']}) - #{server['state']}"
|
50
|
+
}
|
51
|
+
puts %Q(#{result['totalCount']} server/s in total.)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
39
55
|
private
|
40
56
|
def _get_config_path
|
41
57
|
File.join(Dir.home, 'dsh.yml')
|
@@ -49,9 +65,27 @@ module DimensionShell
|
|
49
65
|
end
|
50
66
|
end
|
51
67
|
|
52
|
-
def
|
68
|
+
def _init_configuration
|
53
69
|
configatron.configure_from_hash(_load_config_hash)
|
54
70
|
end
|
71
|
+
|
72
|
+
def _init_command(options)
|
73
|
+
_init_configuration
|
74
|
+
@cloud_control = CloudControl.new({
|
75
|
+
region: options[:region] || configatron.region,
|
76
|
+
organization: options[:organization] || configatron.organization,
|
77
|
+
username: options[:username] || configatron.username,
|
78
|
+
password: options[:password] || configatron.password
|
79
|
+
})
|
80
|
+
end
|
81
|
+
|
82
|
+
def _puts(*args)
|
83
|
+
puts args.unshift('dsh: ').join()
|
84
|
+
end
|
85
|
+
|
86
|
+
def _api_access_failed(result)
|
87
|
+
_puts %Q(API access failed: #{result[:failure]})
|
88
|
+
end
|
55
89
|
end
|
56
90
|
|
57
91
|
DimensionShell::Cli.start
|
@@ -12,12 +12,11 @@ module DimensionShell
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def get_server(servername)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
15
|
+
_invoke_get path: 'server/server', query: { name: servername }
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_server_list
|
19
|
+
_invoke_get path: 'server/server'
|
21
20
|
end
|
22
21
|
|
23
22
|
private
|
@@ -46,7 +45,13 @@ module DimensionShell
|
|
46
45
|
client = HTTPClient.new(default_header: header, force_basic_auth: true)
|
47
46
|
client.set_auth _api_base_uri, @username, @password
|
48
47
|
#puts "Fetching url \"#{_api_domain(options[:path])}\""
|
49
|
-
client.get(_api_domain(options[:path]), :query => options[:query])
|
48
|
+
response = client.get(_api_domain(options[:path]), :query => options[:query])
|
49
|
+
|
50
|
+
if response.ok? then
|
51
|
+
JSON.parse(response.body)
|
52
|
+
else
|
53
|
+
{ failure: "#{response.status.to_s} - #{response.reason.to_s}" }
|
54
|
+
end
|
50
55
|
end
|
51
56
|
end
|
52
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dimension_shell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Breisch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
53
|
requirements:
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version:
|
56
|
+
version: 1.9.0
|
57
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|