smartos-manager 0.0.2 → 1.0.0

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: 620dd7b315db17d02cf399969475a2f39ef226cc
4
- data.tar.gz: 746c327581c49a14e9eb609b09031aaa69018ee3
3
+ metadata.gz: 37214f80056c5a2ba2bd25ecf36ead002011ec77
4
+ data.tar.gz: 9b7b0d614a7f81c5a9ed370c31fe411c1ed4be51
5
5
  SHA512:
6
- metadata.gz: a71832d7decd80a3847c3f154fbd3c3840bc73668bc34ab001141b9a0bc3507cd288b4392f10ba1b99152a9928104b3bf004b8b17ec9e6cfe4524b00a0ded201
7
- data.tar.gz: 2c91b17d667280f50191a65e5d868f2aea0be061136df3e475727dc3bba6807d9c2b6507747b857b9de226a86728ed268afdd1fc7b680e5d54b1319a84a31927
6
+ metadata.gz: a5797b5b333c33bb34db357f29aaaa9a369cf20f051b0754d11ba21d76a832884baec693dd933fc58e9034fe3fbbf6fc17c0defb7f452bf6a360082559713dcb
7
+ data.tar.gz: 3465b613e2e8f7a159e0cad40c99ff1f3b1068c15990a883f753f209cf405ac9dc672f8c8baf2491c69670f3eeb68dfdabc5742b43d82b7e6fdbce3f15a7f58e
data/README.md CHANGED
@@ -14,6 +14,10 @@ a command line tool to manage SmartOS hosts.
14
14
  first you need to create a config file to define your environment:
15
15
 
16
16
  ```toml
17
+ # show custom properties in the list
18
+ [user_columns]
19
+ some_property = "customer_metadata.some_property"
20
+
17
21
  [global]
18
22
  # gateway_user = "root"
19
23
  gateway = "x.x.x.x"
@@ -11,7 +11,9 @@ class AppCLI < Thor
11
11
 
12
12
  sysinfos = registry.sysinfo()
13
13
 
14
- p_vm_list("Memory", "Name", "Type", "UUID", "State", "Admin IP")
14
+ user_columns = registry.user_columns.keys.map{|s| humanize(s) }
15
+
16
+ p_vm_list("Memory", "Name", "Type", "UUID", "State", "Admin IP", *user_columns)
15
17
 
16
18
  ret.each do |host, vms|
17
19
  mem = sysinfos[host][:memory]
@@ -22,7 +24,8 @@ class AppCLI < Thor
22
24
 
23
25
  puts "\n#{host.name} (#{host.address}) (#{vms.size} vms) (Total RAM: #{mem.human_size(1).green}, Avail: #{avail.human_size(1).magenta})"
24
26
  vms.each do |vm|
25
- p_vm_list(vm.memory.human_size(1), vm.name, vm.type, vm.uid, printable_state(vm.state), vm.admin_ip)
27
+ user_columns = registry.user_columns.values.map{|key| vm[key] }
28
+ p_vm_list(vm.memory.human_size(1), vm.name, vm.type, vm.uuid, printable_state(vm.state), vm.admin_ip, *user_columns)
26
29
  end
27
30
 
28
31
  if vms.empty?
@@ -38,8 +41,14 @@ class AppCLI < Thor
38
41
 
39
42
  no_tasks do
40
43
 
41
- def p_vm_list(size, name, type, uuid, state, admin_ip)
42
- puts " [ #{size.rjust(6)} #{name.rjust(15)} - #{uuid.ljust(37)}][ #{admin_ip.ljust(15).cyan} ][ #{state} ]"
44
+ def humanize(str)
45
+ str.split("_").map(&:capitalize).join(' ')
46
+ end
47
+
48
+
49
+ def p_vm_list(size, name, type, uuid, state, admin_ip, *user_columns)
50
+ tmp = user_columns.map{|val| "[ #{val.to_s.ljust(15).cyan} ]" }.join('')
51
+ puts " [ #{size.rjust(6)} #{name.rjust(15)} - #{uuid.ljust(37)}][ #{admin_ip.ljust(15).cyan} ]#{tmp}[ #{state} ]"
43
52
  end
44
53
 
45
54
  def printable_state(state)
@@ -41,44 +41,31 @@ class SSHHost
41
41
  @gateway_user || user
42
42
  end
43
43
 
44
- # private
45
- # def connection
46
- # unless @connection
47
- # if @gateway
48
- # @gateway_obj = Net::SSH::Gateway.new(@gateway, @user)
49
- # @connection = @gateway_obj.ssh(@address, @gateway_user || @user, SSH_OPTIONS)
50
-
51
- # else
52
- # @connection = Net::SSH.start(@address, @user, SSH_OPTIONS)
53
-
54
- # end
55
-
56
- # end
57
-
58
- # @connection
59
- # end
60
44
  end
61
45
 
62
46
 
63
47
  class VirtualMachine
64
- attr_reader :uid, :type, :memory, :state, :name, :admin_ip
65
-
66
- def initialize(uid, type, memory, state, name, admin_ip)
67
- @uid = uid
68
- @type = type
69
- @memory = memory.to_i.megabytes
70
- @state = state
71
- @name = name
72
- @admin_ip = admin_ip
48
+ attr_reader :uuid, :type, :memory, :state, :name, :admin_ip
49
+
50
+ def initialize(data = {})
51
+ @uuid = data.delete('uuid')
52
+ @type = data.delete('type')
53
+ @memory = data.delete('ram').to_i.megabytes
54
+ @state = data.delete('state')
55
+ @name = data.delete('alias')
56
+ @admin_ip = data.delete('nics.0.ip')
57
+
58
+ @user_data = data
73
59
  end
74
60
 
75
- # 4c1ae27f-a986-4189-a2b7-5c5e6d2e26ef:OS:300:running:backup
76
- def self.from_line(line)
77
- new(*line.split(':'))
61
+ def [](key)
62
+ @user_data[key]
78
63
  end
79
64
  end
80
65
 
81
66
  class HostRegistry
67
+ attr_reader :user_columns
68
+
82
69
  def initialize(path)
83
70
  @registry = {}
84
71
  @gateways = {}
@@ -86,11 +73,10 @@ class HostRegistry
86
73
 
87
74
  @connection = Net::SSH::Multi.start()
88
75
 
89
- # data = Psych.load_file(path)
90
- # data = TOML::Parser.new( File.read(path) ).parsed
91
76
  data = TOML.load_file(path)
92
77
 
93
78
  global_data = data.delete('global')
79
+ user_columns = data.delete('user_columns') || {}
94
80
 
95
81
  data.each do |name, opts|
96
82
  host = SSHHost.from_hash(name, opts, global_data)
@@ -103,6 +89,9 @@ class HostRegistry
103
89
  user: host.user,
104
90
  compression: false
105
91
  )
92
+
93
+ # user defined columns
94
+ @user_columns = user_columns
106
95
  end
107
96
 
108
97
  end
@@ -124,12 +113,28 @@ class HostRegistry
124
113
  ret
125
114
  end
126
115
 
116
+ LIST_COLUMNS = %w(
117
+ uuid
118
+ type
119
+ ram
120
+ state
121
+ alias
122
+ nics.0.ip
123
+ )
124
+
127
125
  def list_vms
128
- vms = run_on_all("vmadm list -o uuid,type,ram,state,alias,nics.0.ip -p")
126
+ columns = LIST_COLUMNS + @user_columns.values
127
+
128
+ vms = run_on_all("vmadm list -o #{columns.join(',')} -p")
129
129
  vms.each do |host, data|
130
130
  if data
131
131
  vms[host] = data.split("\n").map! do |line|
132
- VirtualMachine.from_line(line)
132
+ data = {}
133
+ line.split(':', 20).each.with_index do |val, n|
134
+ data[columns[n]] = val
135
+ end
136
+
137
+ VirtualMachine.new(data)
133
138
  end
134
139
  else
135
140
  vms[host] = []
@@ -1,3 +1,3 @@
1
1
  module SmartosManager
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartos-manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julien Ammous
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-27 00:00:00.000000000 Z
11
+ date: 2014-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: toml-rb
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubyforge_project:
152
- rubygems_version: 2.2.0
152
+ rubygems_version: 2.2.1
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: "... ."