wakame-vdc-agents 10.12.0 → 11.06.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. data/LICENSE +164 -201
  2. data/Rakefile +6 -11
  3. data/bin/hva +11 -1351
  4. data/bin/nsa +5 -9
  5. data/bin/sta +124 -71
  6. data/config/hva.conf.example +12 -0
  7. data/config/initializers/isono.rb +7 -23
  8. data/config/initializers/sequel.rb +11 -2
  9. data/lib/dcmgr.rb +70 -11
  10. data/lib/dcmgr/cli/base.rb +74 -0
  11. data/lib/dcmgr/cli/errors.rb +59 -0
  12. data/lib/dcmgr/cli/group.rb +101 -0
  13. data/lib/dcmgr/cli/host.rb +101 -0
  14. data/lib/dcmgr/cli/image.rb +108 -0
  15. data/lib/dcmgr/cli/keypair.rb +72 -0
  16. data/lib/dcmgr/cli/network.rb +198 -0
  17. data/lib/dcmgr/cli/quota.rb +28 -0
  18. data/lib/dcmgr/cli/spec.rb +82 -0
  19. data/lib/dcmgr/cli/storage.rb +88 -0
  20. data/lib/dcmgr/cli/tag.rb +81 -0
  21. data/lib/dcmgr/cli/vlan.rb +53 -0
  22. data/lib/dcmgr/drivers/hypervisor.rb +33 -0
  23. data/lib/dcmgr/drivers/iijgio_storage.rb +37 -0
  24. data/lib/dcmgr/drivers/kvm.rb +118 -0
  25. data/lib/dcmgr/drivers/lxc.rb +167 -0
  26. data/lib/dcmgr/drivers/s3_storage.rb +39 -0
  27. data/lib/dcmgr/drivers/snapshot_storage.rb +51 -0
  28. data/lib/dcmgr/endpoints/core_api.rb +188 -324
  29. data/lib/dcmgr/endpoints/core_api_mock.rb +52 -3
  30. data/lib/dcmgr/endpoints/errors.rb +73 -32
  31. data/lib/dcmgr/endpoints/metadata.rb +163 -16
  32. data/lib/dcmgr/helpers/cli_helper.rb +1 -1
  33. data/lib/dcmgr/helpers/nic_helper.rb +35 -0
  34. data/lib/dcmgr/logger.rb +5 -1
  35. data/lib/dcmgr/messaging_client.rb +117 -0
  36. data/lib/dcmgr/models/account.rb +27 -3
  37. data/lib/dcmgr/models/base_new.rb +21 -7
  38. data/lib/dcmgr/models/host_pool.rb +27 -7
  39. data/lib/dcmgr/models/image.rb +31 -3
  40. data/lib/dcmgr/models/instance.rb +72 -23
  41. data/lib/dcmgr/models/instance_nic.rb +12 -2
  42. data/lib/dcmgr/models/instance_spec.rb +16 -0
  43. data/lib/dcmgr/models/ip_lease.rb +37 -1
  44. data/lib/dcmgr/models/netfilter_group.rb +7 -7
  45. data/lib/dcmgr/models/network.rb +42 -3
  46. data/lib/dcmgr/models/quota.rb +25 -0
  47. data/lib/dcmgr/models/request_log.rb +26 -11
  48. data/lib/dcmgr/models/ssh_key_pair.rb +14 -1
  49. data/lib/dcmgr/models/storage_pool.rb +19 -72
  50. data/lib/dcmgr/models/tag.rb +5 -0
  51. data/lib/dcmgr/models/vlan_lease.rb +8 -0
  52. data/lib/dcmgr/models/volume.rb +26 -8
  53. data/lib/dcmgr/models/volume_snapshot.rb +37 -0
  54. data/lib/dcmgr/node_modules/hva_collector.rb +56 -36
  55. data/lib/dcmgr/node_modules/instance_ha.rb +1 -1
  56. data/lib/dcmgr/node_modules/instance_monitor.rb +70 -0
  57. data/lib/dcmgr/node_modules/service_netfilter.rb +914 -0
  58. data/lib/dcmgr/node_modules/sta_collector.rb +7 -30
  59. data/lib/dcmgr/rack/request_logger.rb +60 -0
  60. data/lib/dcmgr/rack/run_initializer.rb +42 -0
  61. data/lib/dcmgr/rpc/hva_handler.rb +388 -0
  62. data/lib/dcmgr/rubygems.rb +7 -0
  63. data/lib/dcmgr/storage_service.rb +98 -0
  64. data/lib/dcmgr/tags.rb +2 -2
  65. data/lib/dcmgr/version.rb +8 -0
  66. data/lib/ext/time.rb +8 -0
  67. data/lib/sinatra/respond_to.rb +3 -0
  68. data/lib/sinatra/sequel_transaction.rb +20 -5
  69. metadata +133 -100
  70. data/lib/dcmgr/models/physical_host.rb +0 -67
  71. data/lib/dcmgr/web/base.rb +0 -21
@@ -0,0 +1,72 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr::Cli
4
+ class KeyPair < Base
5
+ namespace :keypair
6
+ M = Dcmgr::Models
7
+
8
+ desc "add [options]", "Register a new key pair."
9
+ method_option :uuid, :type => :string, :aliases => "-u", :desc => "The UUID for the new key pair"
10
+ method_option :account_id, :type => :string, :aliases => "-a", :desc => "The UUID of the account this key pair belongs to", :required => true
11
+ method_option :name, :type => :string, :aliases => "-n", :desc => "The name for this key pair", :required => true
12
+ method_option :public_key, :type => :string, :aliases => "-p", :desc => "The path to the public key", :required => true
13
+ method_option :private_key, :type => :string, :aliases => "-r", :desc => "The path to the private key", :required => true
14
+ def add
15
+ UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
16
+ private_key_path = File.expand_path(options[:private_key])
17
+ public_key_path = File.expand_path(options[:public_key])
18
+ Error.raise "Private key file doesn't exist",100 unless File.exists?(private_key_path)
19
+ Error.raise "Public key file doesn't exist",100 unless File.exists?(public_key_path)
20
+
21
+ fields = options.dup
22
+
23
+ #Get the keys from their respective files.
24
+ fields[:public_key] = File.open(public_key_path) {|f| f.readline}
25
+ fields[:private_key] = File.open(private_key_path) {|f| f.readlines.map.join}
26
+
27
+ #Generate the fingerprint from the public key file
28
+ fields[:finger_print] = %x{ssh-keygen -lf #{options[:public_key]} | cut -d ' ' -f2}.chomp
29
+
30
+ puts super(M::SshKeyPair,fields)
31
+ end
32
+
33
+ desc "modify UUID [options]", "Modify an existing key pair"
34
+ method_option :account_id, :type => :string, :aliases => "-a", :desc => "The UUID of the account this key pair belongs to"
35
+ method_option :name, :type => :string, :aliases => "-n", :desc => "The name for this key pair"
36
+ def modify(uuid)
37
+ UnknownUUIDError.raise(options[:account_id]) if options[:account_id] && M::Account[options[:account_id]].nil?
38
+ super(M::SshKeyPair,uuid,options)
39
+ end
40
+
41
+ desc "del UUID", "Delete an existing keypair"
42
+ def del(uuid)
43
+ super(M::SshKeyPair,uuid)
44
+ end
45
+
46
+ desc "show [UUID] [options]", "Show network(s)"
47
+ def show(uuid=nil)
48
+ if uuid
49
+ keypair = M::SshKeyPair[uuid] || UnknownUUIDError.raise(uuid)
50
+ puts ERB.new(<<__END, nil, '-').result(binding)
51
+ Keypair UUID:
52
+ <%= keypair.canonical_uuid %>
53
+ Account id:
54
+ <%= keypair.account_id %>
55
+ Name:
56
+ <%= keypair.name%>
57
+ Finger print:
58
+ <%= keypair.finger_print %>
59
+ Public Key:
60
+ <%= keypair.public_key%>
61
+ __END
62
+ else
63
+ puts ERB.new(<<__END, nil, '-').result(binding)
64
+ <%- M::SshKeyPair.each { |row| -%>
65
+ <%= row.canonical_uuid %>\t<%= row.account_id %>\t<%= row.name %>\t<%= row.finger_print %>
66
+ <%- } -%>
67
+ __END
68
+ end
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,198 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'ipaddress'
4
+
5
+ module Dcmgr::Cli
6
+ class Network < Base
7
+ namespace :network
8
+ M=Dcmgr::Models
9
+
10
+ desc "add [options]", "Register a new network entry"
11
+ method_option :uuid, :type => :string, :aliases => "-u", :desc => "UUID of the network"
12
+ method_option :ipv4_gw, :type => :string, :aliases => "-g", :required => true, :desc => "Gateway address for IPv4 network"
13
+ method_option :prefix, :type => :numeric, :default=>24, :aliases => "-p", :desc => "IP network mask size (1 < prefix < 32)"
14
+ method_option :domain, :type => :string, :aliases => "-m", :desc => "DNS domain name of the network"
15
+ method_option :dns, :type => :string, :aliases => "-n", :desc => "IP address for DNS server of the network"
16
+ method_option :dhcp, :type => :string, :aliases => "-c", :desc => "IP address for DHCP server of the network"
17
+ method_option :metadata, :type => :string, :aliases => "-t", :desc => "IP address for metadata server of the network"
18
+ method_option :metadata_port, :type => :string, :aliases => "--tp", :desc => "Port for the metadata server of the network"
19
+ method_option :bandwidth, :type => :numeric, :aliases => "-b", :desc => "The maximum bandwidth for the network in Mbit/s"
20
+ method_option :vlan_id, :type => :numeric, :default=>0, :aliases => "-l", :desc => "Tag VLAN (802.1Q) ID of the network. 0 is for no VLAN network"
21
+ method_option :description, :type => :string, :aliases => "-d", :desc => "Description for the network"
22
+ method_option :account_id, :type => :string, :default=>'a-shpool', :aliases => "-a", :desc => "The account ID to own this"
23
+ def add
24
+ vlan_pk = if options[:vlan_id].to_i > 0
25
+ vlan = M::VlanLease.find(:tag_id=>options[:vlan_id]) || Error.raise("Invalid or Unknown VLAN ID: #{options[:vlan_id]}", 100)
26
+ vlan.id
27
+ else
28
+ 0
29
+ end
30
+
31
+ fields = {
32
+ :ipv4_gw => options[:ipv4_gw],
33
+ :prefix => options[:prefix],
34
+ :dns_server => options[:dns],
35
+ :domain_name => options[:domain],
36
+ :dhcp_server => options[:dhcp],
37
+ :metadata_server => options[:metadata],
38
+ :metadata_server_port => options[:metadata_port],
39
+ :description => options[:description],
40
+ :account_id => options[:account_id],
41
+ :bandwidth => options[:bandwidth],
42
+ :vlan_lease_id => vlan_pk,
43
+ }
44
+ fields.merge!({:uuid => options[:uuid]}) unless options[:uuid].nil?
45
+
46
+ puts super(M::Network,fields)
47
+ end
48
+
49
+ desc "del UUID", "Deregister a network entry"
50
+ def del(uuid)
51
+ super(M::Network,uuid)
52
+ end
53
+
54
+ desc "modify UUID [options]", "Update network information"
55
+ method_option :ipv4_gw, :type => :string, :aliases => "-g", :desc => "Gateway address for IPv4 network"
56
+ method_option :prefix, :type => :numeric, :aliases => "-p", :desc => "IP network mask size (1 < prefix < 32)"
57
+ method_option :domain, :type => :string, :aliases => "-m", :desc => "DNS domain name of the network"
58
+ method_option :dns, :type => :string, :aliases => "-n", :desc => "IP address for DNS server of the network"
59
+ method_option :dhcp, :type => :string, :aliases => "-c", :desc => "IP address for DHCP server of the network"
60
+ method_option :metadata, :type => :string, :aliases => "-t", :desc => "IP address for metadata server of the network"
61
+ method_option :metadata_port, :type => :string, :aliases => "--tp", :desc => "Port for the metadata server of the network"
62
+ method_option :vlan_id, :type => :numeric, :aliases => "-l", :desc => "Tag VLAN (802.1Q) ID of the network. 0 is for no VLAN network"
63
+ method_option :bandwidth, :type => :numeric, :aliases => "-b", :desc => "The maximum bandwidth for the network in Mbit/s"
64
+ method_option :description, :type => :string, :aliases => "-d", :desc => "Description for the network"
65
+ method_option :account_id, :type => :string, :aliases => "-a", :desc => "The account ID to own this"
66
+ def modify(uuid)
67
+ vlan_pk = if options[:vlan_id].to_i > 0
68
+ vlan = M::VlanLease.find(:tag_id=>options[:vlan_id]) || Error.raise("Invalid or Unknown VLAN ID: #{options[:vlan_id]}", 100)
69
+ vlan.id
70
+ else
71
+ 0
72
+ end
73
+
74
+ fields = {
75
+ :ipv4_gw => options[:ipv4_gw],
76
+ :prefix => options[:prefix],
77
+ :dns_server => options[:dns],
78
+ :domain_name => options[:domain],
79
+ :dhcp_server => options[:dhcp],
80
+ :metadata_server => options[:metadata],
81
+ :metadata_server_port => options[:metadata_port],
82
+ :description => options[:description],
83
+ :account_id => options[:account_id],
84
+ :bandwidth => options[:bandwidth],
85
+ :vlan_lease_id => vlan_pk,
86
+ }
87
+ super(M::Network,uuid,fields)
88
+ end
89
+
90
+ desc "nat UUID [options]", "Set or clear nat mapping for a network"
91
+ method_option :outside_network_id, :type => :string, :aliases => "-o", :desc => "The network that this network will be natted to"
92
+ method_option :clear, :type => :boolean, :aliases => "-c", :desc => "Clears a previously natted network"
93
+ def nat(uuid)
94
+ in_nw = M::Network[uuid] || Error.raise("Unknown network UUID: #{uuid}", 100)
95
+ ex_nw = M::Network[options[:outside_network_id]] || Error.raise("Unknown network UUID: #{uuid}", 100) unless options[:outside_network_id].nil?
96
+
97
+ if options[:clear] then
98
+ in_nw.set_only({:nat_network_id => nil},:nat_network_id)
99
+ in_nw.save_changes
100
+ else
101
+ in_nw.set_only({:nat_network_id => ex_nw.id},:nat_network_id)
102
+ in_nw.save_changes
103
+ end
104
+ end
105
+
106
+ desc "show [UUID] [options]", "Show network(s)"
107
+ method_option :vlan_id, :type => :numeric, :aliases => "-l", :desc => "Show networks in the VLAN ID"
108
+ method_option :account_id, :type => :string, :aliases => "-a", :desc => "Show networks with the account"
109
+ def show(uuid=nil)
110
+ if uuid
111
+ nw = M::Network[uuid] || Error.raise("Unknown network UUID: #{uuid}", 100)
112
+ puts ERB.new(<<__END, nil, '-').result(binding)
113
+ Network UUID:
114
+ <%= nw.canonical_uuid %>
115
+ Tag VLAN:
116
+ <%= nw.vlan_lease_id == 0 ? 'none' : nw.vlan_lease.tag_id %>
117
+ IPv4:
118
+ Network address: <%= nw.ipaddress.network %>/<%= nw.prefix %>
119
+ Gateway address: <%= nw.ipv4_gw %>
120
+ <%- if nw.nat_network_id -%>
121
+ Outside NAT network address: <%= nw.nat_network.ipaddress.network %>/<%= nw.nat_network.prefix %> (<%= nw.nat_network.canonical_uuid %>)
122
+ <%- end -%>
123
+ DHCP Information:
124
+ DHCP Server: <%= nw.dhcp_server %>
125
+ DNS Server: <%= nw.dns_server %>
126
+ <%- if nw.metadata_server -%>
127
+ Metadata Server: <%= nw.metadata_server %>
128
+ <%- end -%>
129
+ Bandwidth:
130
+ <%- if nw.bandwidth.nil? -%>
131
+ unlimited
132
+ <%- else -%>
133
+ <%= nw.bandwidth %> Mbit/s
134
+ <%- end -%>
135
+ <%- if nw.description -%>
136
+ Description:
137
+ <%= nw.description %>
138
+ <%- end -%>
139
+ __END
140
+ else
141
+ cond = {}
142
+ cond[:account_id]= options[:account_id] if options[:account_id]
143
+ if options[:vlan_id]
144
+ vlan = M::VlanLease.find(:tag_id=>options[:vlan_id]) || abort("Unknown Tag VLAN ID: #{options[:vlan_id]}")
145
+ cond[:vlan_lease_id] = vlan.id
146
+ end
147
+
148
+ nw = M::Network.filter(cond).all
149
+ puts ERB.new(<<__END, nil, '-').result(binding)
150
+ <%- nw.each { |row| -%>
151
+ <%= row.canonical_uuid %>\t<%= row.ipaddress.network %>/<%= row.prefix %>\t<%= (row.vlan_lease && row.vlan_lease.tag_id) %>
152
+ <%- } -%>
153
+ __END
154
+ end
155
+ end
156
+
157
+ desc "leases UUID", "Show IPs used in the network"
158
+ def leases(uuid)
159
+ nw = M::Network[uuid] || Error.raise("Unknown network UUID: #{uuid}", 100)
160
+
161
+ print ERB.new(<<__END, nil, '-').result(binding)
162
+ <%- nw.ip_lease_dataset.order(:ipv4).all.each { |l| -%>
163
+ <%= "%-20s %-15s" % [l.ipv4, M::IpLease::TYPE_MESSAGES[l.alloc_type]] %>
164
+ <%- } -%>
165
+ __END
166
+ end
167
+
168
+ desc "reserve UUID", "Add reserved IP to the network"
169
+ method_option :ipv4, :type => :string, :aliases => "-i", :required => true, :desc => "The ip address to reserve"
170
+ def reserve(uuid)
171
+ nw = M::Network[uuid] || UnknownUUIDError.raise(uuid)
172
+
173
+ if nw.ipaddress.include?(IPAddress(options[:ipv4]))
174
+ nw.ip_lease_dataset.add_reserved(options[:ipv4])
175
+ else
176
+ Error.raise("IP address is out of range: #{options[:ipv4]} => #{nw.ipaddress.network}/#{nw.ipaddress.prefix}",100)
177
+ end
178
+ end
179
+
180
+ desc "release UUID", "Release a reserved IP from the network"
181
+ method_option :ipv4, :type => :string, :aliases => "-i", :required => true, :desc => "The ip address to release"
182
+ def release(uuid)
183
+ nw = M::Network[uuid] || UnknownUUIDError.raise(uuid)
184
+
185
+ if nw.ip_lease_dataset.filter(:ipv4=>options[:ipv4]).delete == 0
186
+ Error.raise("The IP is not reserved in network #{uuid}: #{options[:ipv4]}", 100)
187
+ end
188
+ end
189
+
190
+ no_tasks {
191
+ private
192
+ def find_network(uuid)
193
+ M::Network[uuid] || Error.raise("Unknown network UUID: #{uuid}")
194
+ end
195
+ }
196
+
197
+ end
198
+ end
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr::Cli
4
+ class Quota < Base
5
+ namespace :quota
6
+ M = Dcmgr::Models
7
+
8
+ desc "modify ACCOUNT_UUID [options]", "Modify the quota settings for an account"
9
+ method_option :weight, :type => :numeric, :aliases => "-w", :desc => "The instance total weight for this account's quota"
10
+ method_option :size, :type => :numeric, :aliases => "-s", :desc => "The volume total size for this account's quota"
11
+ def modify(account_uuid)
12
+ acc = M::Account[account_uuid] || UnknownUUIDError.raise(account_uuid)
13
+ super(M::Quota,acc.quota.canonical_uuid,{:instance_total_weight => options[:weight], :volume_total_size => options[:size]})
14
+ end
15
+
16
+ desc "show ACCOUNT_UUID", "Show the quota settings for an account"
17
+ def show(account_uuid)
18
+ acc = M::Account[account_uuid] || raise(Thor::Error, "Unknown Account UUID: #{account_uuid}")
19
+ puts ERB.new(<<__END, nil, '-').result(binding)
20
+ Instance total weight:
21
+ <%= acc.quota.instance_total_weight %>
22
+ Volume total size:
23
+ <%= acc.quota.volume_total_size %>
24
+ __END
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,82 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr::Cli
4
+ class Spec < Base
5
+ namespace :spec
6
+ M = Dcmgr::Models
7
+
8
+ desc "add [options]", "Register a new machine spec"
9
+ method_option :uuid, :type => :string, :aliases => "-u", :desc => "The UUID for the new machine spec"
10
+ method_option :account_id, :type => :string, :aliases => "-a", :required => true, :desc => "The UUID of the account that this machine spec belongs to"
11
+ method_option :arch, :type => :string, :default => 'x86_64', :aliases => "-r", :desc => "The architecture for the new machine image. [#{M::HostPool::SUPPORTED_ARCH.join(', ')}]"
12
+ method_option(:hypervisor, :type => :string, :aliases => "-p", :default => M::HostPool::HYPERVISOR_KVM.to_s,
13
+ :desc => "The hypervisor type for the new instance. [#{M::HostPool::SUPPORTED_HYPERVISOR.join(', ')}]")
14
+ method_option :cpu_cores, :type => :numeric, :aliases => "-c", :default => 1, :desc => "The initial cpu cores for the new instance"
15
+ method_option :memory_size, :type => :numeric, :aliases => "-m", :default => 1024, :desc => "The memory size for the new instance"
16
+ method_option :quota_weight, :type => :numeric, :aliases => "-w", :default => 1.0, :desc => "The cost weight factor for the new instance"
17
+ #method_option :is_public, :type => :boolean, :aliases => "-p", :default => false, :desc => "A flag that determines whether the new machine image is public or not."
18
+ def add
19
+ UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
20
+ UnsupportedArchError.raise(options[:arch]) unless M::HostPool::SUPPORTED_ARCH.member?(options[:arch])
21
+ UnsupportedHypervisorError.raise(options[:hypervisor]) unless M::HostPool::SUPPORTED_HYPERVISOR.member?(options[:hypervisor])
22
+ fields = options.dup
23
+ fields[:config] = {
24
+ }
25
+ puts super(M::InstanceSpec, fields)
26
+ end
27
+
28
+ desc "modify UUID [options]", "Modify an existing machine spec"
29
+ method_option :account_id, :type => :string, :aliases => "-a", :desc => "The UUID of the account that this machine spec belongs to"
30
+ method_option :arch, :type => :string, :aliases => "-r", :desc => "The architecture for the new machine image. [#{M::HostPool::SUPPORTED_ARCH.join(', ')}]"
31
+ method_option(:hypervisor, :type => :string, :aliases => "-p",
32
+ :desc => "The hypervisor type for the new instance. [#{M::HostPool::SUPPORTED_HYPERVISOR.join(', ')}]")
33
+ method_option :cpu_cores, :type => :numeric, :aliases => "-c", :desc => "The initial cpu cores for the new instance"
34
+ method_option :memory_size, :type => :numeric, :aliases => "-m", :desc => "The memory size for the new instance"
35
+ method_option :quota_weight, :type => :numeric, :aliases => "-w", :desc => "The cost weight factor for the new instance"
36
+ def modify(uuid)
37
+ UnknownUUIDError.raise(options[:account_id]) if options[:account_id] && M::Account[options[:account_id]].nil?
38
+ UnsupportedArchError.raise(options[:arch]) unless options[:arch].nil? || M::HostPool::SUPPORTED_ARCH.member?(options[:arch])
39
+ UnsupportedHypervisorError.raise(options[:hypervisor]) unless options[:hypervisor].nil? || M::HostPool::SUPPORTED_HYPERVISOR.member?(options[:hypervisor])
40
+ super(M::InstanceSpec,uuid,options)
41
+ end
42
+
43
+ desc "del UUID", "Delete registered machine spec"
44
+ def del(uuid)
45
+ UnknownUUIDError.raise(uuid) if M::InstanceSpec[uuid].nil?
46
+ super(M::InstanceSpec, uuid)
47
+ end
48
+
49
+ desc "show [UUID]", "Show list of machine spec and details"
50
+ def show(uuid=nil)
51
+ if uuid
52
+ spec = M::InstanceSpec[uuid]
53
+ print ERB.new(<<__END, nil, '-').result(binding)
54
+ UUID:
55
+ <%= spec.canonical_uuid %>
56
+ Account ID:
57
+ <%= spec.account_id %>
58
+ Hypervisor:
59
+ <%= spec.hypervisor %>
60
+ Arch:
61
+ <%= spec.arch %>
62
+ CPU Cores:
63
+ <%= spec.cpu_cores %>
64
+ Memory Size:
65
+ <%= spec.memory_size %>
66
+ Quota Weight:
67
+ <%= spec.quota_weight %>
68
+ Hypervisor Configuration:
69
+ <%= spec.config.inspect %>
70
+ __END
71
+ else
72
+ cond = {}
73
+ specs = M::InstanceSpec.filter(cond).all
74
+ print ERB.new(<<__END, nil, '-').result(binding)
75
+ <%- specs.each { |row| -%>
76
+ <%= "%-20s %-15s %-15s" % [row.canonical_uuid, row.account_id, row.arch] %>
77
+ <%- } -%>
78
+ __END
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,88 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'thor'
4
+ require 'isono'
5
+
6
+ module Dcmgr::Cli
7
+ class Storage < Base
8
+ namespace :storage
9
+ include Dcmgr::Models
10
+
11
+ desc "add NODE_ID [options]", "Register a new storage node"
12
+ method_option :uuid, :type => :string, :aliases => "-u", :desc => "The uuid for the new storage pool."
13
+ method_option :base_path, :type => :string, :aliases => "-b", :required => true, :desc => "Base path to store volume files"
14
+ method_option :snapshot_base_path, :type => :string, :aliases => "-n", :required => true, :desc => "Base path to store snapshot files"
15
+ method_option :disk_space, :type => :numeric, :aliases => "-s", :required => true, :desc => "Amount of disk size to be exported (in MB)."
16
+ method_option :transport_type, :type => :string, :aliases => "-t", :default=>'iscsi', :desc => "Transport type [iscsi]"
17
+ method_option :ipaddr, :type => :string, :aliases => "-i", :required=>true, :desc => "IP address of transport target"
18
+ method_option :storage_type, :type => :string, :aliases => "-o", :default=>'zfs', :desc => "Storage type [zfs]"
19
+ method_option :account_id, :type => :string, :default=>'a-shpool', :aliases => "-a", :desc => "The account ID to own this."
20
+ def add(node_id)
21
+ unless (options[:force] == false && Isono::Models::NodeState.exists?(:node_id=>options[:node_id]))
22
+ abort("Node ID is not registered yet: #{options[:node_id]}")
23
+ end
24
+
25
+ fields = {:node_id=>options[:node_id],
26
+ :offering_disk_space=>options[:disk_space],
27
+ :transport_type=>options[:transport_type],
28
+ :storage_type=>options[:storage_type],
29
+ :export_path=>options[:base_path],
30
+ :snapshot_base_path => options[:snapshot_base_path],
31
+ :ipaddr=>options[:ipaddr],
32
+ :account_id=>options[:account_id],
33
+ }
34
+ fields.merge!({:uuid => options[:uuid]}) unless options[:uuid].nil?
35
+
36
+ puts super(StoragePool,fields)
37
+ end
38
+
39
+ desc "del UUID", "Deregister a storage node"
40
+ def del(uuid)
41
+ super(StoragePool,uuid)
42
+ end
43
+
44
+ desc "show [UUID]", "Show list of storage nodes and details"
45
+ def show(uuid=nil)
46
+ if uuid
47
+ st = StoragePool[uuid]
48
+ puts ERB.new(<<__END, nil, '-').result(binding)
49
+ UUID:
50
+ <%= st.canonical_uuid %>
51
+ Node ID:
52
+ <%= st.node_id %>
53
+ Disk space (offerring):
54
+ <%= st.offering_disk_space %>MB
55
+ Storage:
56
+ <%= st.storage_type %>
57
+ Transport:
58
+ <%= st.transport_type %>
59
+ IP Address:
60
+ <%= st.ipaddr %>
61
+ Export path:
62
+ <%= st.export_path %>
63
+ Snapshot base path:
64
+ <%= st.snapshot_base_path %>
65
+ __END
66
+ else
67
+ cond = {}
68
+ all = StoragePool.filter(cond).all
69
+ puts ERB.new(<<__END, nil, '-').result(binding)
70
+ <%- all.each { |row| -%>
71
+ <%= "%-15s %-20s %-10s" % [row.canonical_uuid, row.node_id, row.status] %>
72
+ <%- } -%>
73
+ __END
74
+ end
75
+ end
76
+
77
+ desc "shownodes", "Show node (agents)"
78
+ def shownodes
79
+ nodes = Isono::Models::NodeState.filter.all
80
+
81
+ puts ERB.new(<<__END, nil, '-').result(binding)
82
+ <%- nodes.each { |row| -%>
83
+ <%= "%-20s %-10s" % [row.node_id, row.state] %>
84
+ <%- } -%>
85
+ __END
86
+ end
87
+ end
88
+ end