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
data/bin/nsa CHANGED
@@ -5,14 +5,11 @@
5
5
  # This agent aims to configure DNS/DHCP daemons or devices to supply
6
6
  # IP address and Hostname for Instances.
7
7
 
8
- begin
9
- require 'rubygems'
10
- require 'bundler'
11
- Bundler.setup(:default)
12
- rescue Exception
13
- end
8
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
14
9
 
15
- require File.expand_path('../../config/path_resolver', __FILE__)
10
+ require 'dcmgr/rubygems'
11
+ require 'dcmgr'
12
+ require 'isono'
16
13
 
17
14
  require 'erb'
18
15
  require 'eventmachine'
@@ -168,8 +165,7 @@ manifest.instance_eval do
168
165
  c.network_name = nil
169
166
  end
170
167
 
171
- config_path File.expand_path('config/nsa.conf', app_root)
172
- load_config
168
+ load_config File.expand_path('config/nsa.conf', app_root)
173
169
  end
174
170
 
175
171
 
data/bin/sta CHANGED
@@ -1,23 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
  # -*- coding: utf-8 -*-
3
3
 
4
- begin
5
- require 'rubygems'
6
- require 'bundler'
7
- Bundler.setup(:default)
8
- rescue Exception
9
- end
4
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
10
5
 
11
- require File.expand_path('../../config/path_resolver', __FILE__)
6
+ require 'dcmgr/rubygems'
7
+ require 'dcmgr'
8
+ require 'isono'
12
9
 
13
10
  include Isono::Runner::RpcServer
14
11
 
15
12
  class ZfsHandler < EndpointBuilder
16
13
  include Dcmgr::Logger
17
-
14
+ include Dcmgr::Helpers::CliHelper
15
+
18
16
  job :create_volume do
19
17
  volume_id = request.args[0]
20
- job = Dcmgr::Stm::VolumeContext.new(volume_id)
18
+ dest = Dcmgr::StorageService.repository(request.args[1])
21
19
  data = rpc.request('sta-collector', 'get_volume', volume_id)
22
20
  raise "Invalid volume state: #{data[:state]}" unless data[:state].to_s == 'registering'
23
21
 
@@ -26,140 +24,195 @@ class ZfsHandler < EndpointBuilder
26
24
  raise "Invalid snapshot state: #{sdata[:state]}" unless sdata[:state].to_s == 'available'
27
25
  end
28
26
  logger.info("creating new volume #{volume_id}")
29
- job.stm.state=data[:state].to_sym
30
- job.stm.on_create
31
27
 
32
- vol_path = "#{data[:storage_pool][:export_path]}/#{data[:export_path]}"
33
- `zfs list #{File.dirname(vol_path)} > /dev/null 2>&1`
28
+ rpc.request('sta-collector', 'update_volume', volume_id, {:state=>:creating, :export_path=>data[:uuid]})
29
+
30
+ vol_path = "#{data[:storage_pool][:export_path]}/#{data[:uuid]}"
31
+ sh("/usr/sbin/zfs list %s > /dev/null 2>&1", [File.dirname(vol_path)])
34
32
  if $?.exitstatus != 0
35
33
  # create parent filesystem
36
- `zfs create -p #{File.dirname(vol_path)}`
34
+ sh("/usr/sbin/zfs create -p %s", [File.dirname(vol_path)])
37
35
  logger.info("create parent filesystem: #{File.dirname(vol_path)}")
38
36
  end
39
37
 
40
38
  if sdata
39
+ zsnap_dir = "#{data[:storage_pool][:snapshot_base_path]}/#{sdata[:account_id]}/"
40
+ zsnap_filename = "#{sdata[:uuid]}.zsnap"
41
+ zsnap_file = File.join(zsnap_dir, zsnap_filename)
42
+
43
+ unless File.exists?(zsnap_file)
44
+ if Dcmgr::StorageService.has_driver?(dest[:driver])
45
+ begin
46
+ storage = Dcmgr::StorageService.new(dest[:driver], dest[:access_key], dest[:secret_key])
47
+ snapshot_file = "#{dest[:path]}#{dest[:filename]}"
48
+ bucket = storage.bucket(dest[:bucket])
49
+ bucket.download(snapshot_file, zsnap_filename, zsnap_dir)
50
+ logger.info("download to #{dest[:driver]}: #{snapshot_file}")
51
+ rescue => e
52
+ logger.error(e.message)
53
+ raise "snapshot not downloaded" if $?.exitstatus != 0
54
+ end
55
+ end
56
+ end
57
+
41
58
  # create volume from snapshot
42
- v = `zfs receive #{vol_path} < #{data[:storage_pool][:snapshot_base_path]}/#{sdata[:account_id]}/#{sdata[:uuid]}.zsnap`
43
- if $?.exitstatus != 0
44
- raise "volume already exists: #{volume_id}"
59
+ if File.exists?(zsnap_file)
60
+ sh("/usr/sbin/zfs receive %s < %s", [vol_path, zsnap_file])
61
+ if $?.exitstatus != 0
62
+ raise "volume already exists: #{volume_id}"
63
+ end
64
+ else
65
+ raise "snapshot file isn't exists: #{zsnap_file}"
45
66
  end
46
67
 
47
- v = `zfs destroy #{vol_path}@#{sdata[:uuid]}`
68
+ sh("/usr/sbin/zfs destroy %s@%s", [vol_path, sdata[:uuid]])
48
69
  if $?.exitstatus != 0
49
70
  raise "volume snapshot has not deleted: #{volume_id}@#{sdata[:uuid]}"
50
71
  end
51
72
 
52
- vl = `zfs list #{vol_path}`
53
- if vl.nil? || $?.exitstatus != 0
73
+ sh("/usr/sbin/zfs list %s", [vol_path])
74
+ if $?.exitstatus != 0
54
75
  raise "volume has not be created: #{volume_id}"
55
76
  end
77
+
78
+ sh("rm -rf %s", ["#{data[:storage_pool][:snapshot_base_path]}/#{sdata[:account_id]}/#{sdata[:uuid]}.zsnap"])
79
+ logger.info("delete file: " + File.join(zsnap_dir, zsnap_file))
80
+
81
+ if $?.exitstatus != 0
82
+ raise "snapshot file cna't deleted"
83
+ end
56
84
  else
57
85
  # create volume
58
- v = `zfs create -p -V #{data[:size]}m #{vol_path}`
86
+ sh("/usr/sbin/zfs create -p -V %s %s", ["#{data[:size]}m", vol_path])
59
87
  if $?.exitstatus != 0
60
88
  raise "volume already exists: #{volume_id}"
61
89
  end
62
- vl = `zfs list #{vol_path}`
63
- if vl.nil? || $?.exitstatus != 0
90
+ sh("/usr/sbin/zfs list %s", [vol_path])
91
+ if $?.exitstatus != 0
64
92
  raise "volume has not be created: #{volume_id}"
65
93
  end
66
94
  end
67
95
 
68
- rpc.request('sta-collector', 'update_volume', job.to_hash(:export_path=>data[:export_path]))
69
96
  logger.info("created new volume: #{volume_id}")
70
97
 
71
- job.stm.on_register
72
- vr = `zfs shareiscsi=on #{data[:storage_pool][:export_path]}/#{data[:uuid]}`
98
+ sh("/usr/sbin/zfs shareiscsi=on %s/%s", [data[:storage_pool][:export_path], data[:uuid]])
73
99
  if $?.exitstatus != 0
74
100
  raise "failed iscsi target request: #{volume_id}"
75
101
  end
76
- il = `iscsitadm list target -v #{data[:storage_pool][:export_path]}/#{data[:uuid]}`
102
+ il = sh("iscsitadm list target -v %s", ["#{data[:storage_pool][:export_path]}/#{data[:uuid]}"])
77
103
  if $?.exitstatus != 0
78
104
  raise "iscsi target has not be created #{volume_id}"
79
105
  end
80
- il = il.downcase.split("\n").select {|row| row.strip!}
106
+ il = il[:stdout].downcase.split("\n").select {|row| row.strip!}
81
107
  # :transport_information => {:iqn => "iqn.1986-03.com.sun:02:787bca42-9639-44e4-f115-f5b06ed31817", :lun => 0}
82
108
  opt = {:iqn => il[0].split(": ").last, :lun=>il[6].split(": ").last.to_i}
83
109
 
84
- rpc.request('sta-collector', 'update_volume', job.to_hash(:transport_information=>opt))
110
+ rpc.request('sta-collector', 'update_volume', volume_id, {:state=>:available, :transport_information=>opt})
85
111
  logger.info("registered iscsi target: #{volume_id}")
86
112
  end
87
113
 
88
114
  job :delete_volume do
89
115
  volume_id = request.args[0]
90
- job = Dcmgr::Stm::VolumeContext.new(volume_id)
91
116
  data = rpc.request('sta-collector', 'get_volume', volume_id)
92
- logger.info("deleting volume: #{volume_id}")
93
- raise "Invalid volume state: #{data[:state]}" unless data[:state].to_s == 'deregistering'
94
- job.stm.state=data[:state].to_sym
95
-
117
+ logger.info("#{volume_id}: start deleting volume.")
118
+ errcount = 0
119
+ if data[:state].to_s == 'deleted'
120
+ raise "#{volume_id}: Invalid volume state: deleted"
121
+ end
122
+ if data[:state].to_s != 'deregistering'
123
+ logger.warn("#{volume_id}: Unexpected volume state but try again: #{data[:state]}")
124
+ end
125
+
96
126
  # deregisterd iscsi target
97
- job.stm.on_delete
98
- vr = `zfs shareiscsi=off #{data[:storage_pool][:export_path]}/#{data[:export_path]}`
99
- il = `iscsitadm list target #{data[:storage_pool][:export_path]}/#{data[:export_path]}`
100
- unless il.empty?
101
- raise "iscsi target has not deleted: #{volume_id} iqn: #{data[:transport_information][:iqn]}"
127
+ begin
128
+ sh("/usr/sbin/zfs shareiscsi=off %s", ["#{data[:storage_pool][:export_path]}/#{data[:uuid]}"])
129
+ rescue => e
130
+ logger.error("#{volume_id}: Failed to delete ISCSI target entry.")
131
+ errcount += 1
102
132
  end
103
-
104
- rpc.request('sta-collector', 'update_volume', job.to_hash)
105
- logger.info("deregistered iscsi target: #{volume_id} iqn: #{data[:transport_information][:iqn]}")
106
-
133
+
134
+ rpc.request('sta-collector', 'update_volume', volume_id, {:state=>:deleting})
135
+
107
136
  # delete volume
108
- job.stm.on_delete
109
- job.on_delete
110
- v = `zfs destroy #{data[:storage_pool][:export_path]}/#{data[:export_path]}`
111
- vl = `zfs list #{data[:storage_pool][:export_path]}/#{data[:export_path]}`
112
- unless vl.empty?
113
- raise "volume has not deleted: #{volume_id}"
137
+ begin
138
+ sh("/usr/sbin/zfs destroy %s", ["#{data[:storage_pool][:export_path]}/#{data[:uuid]}"])
139
+ rescue => e
140
+ logger.error("#{volume_id}: Failed to delete zfs volume: #{data[:storage_pool][:export_path]}/#{data[:uuid]}")
141
+ errcount += 1
114
142
  end
115
143
 
116
- rpc.request('sta-collector', 'update_volume', job.to_hash)
117
- logger.info("deleted volume: #{volume_id}")
144
+ rpc.request('sta-collector', 'update_volume', volume_id, {:state=>:deleted, :deleted_at=>Time.now.utc})
145
+ if errcount > 0
146
+ logger.info("#{volume_id}: Encountered one or more errors during deleting.")
147
+ else
148
+ logger.info("#{volume_id}: Deleted volume successfully.")
149
+ end
118
150
  end
119
151
 
120
152
  job :create_snapshot do
121
153
  snapshot_id = request.args[0]
122
- job = Dcmgr::Stm::SnapshotContext.new(snapshot_id)
154
+ dest = Dcmgr::StorageService.repository(request.args[1])
123
155
  sdata = rpc.request('sta-collector', 'get_snapshot', snapshot_id) unless snapshot_id.nil?
124
156
  data = rpc.request('sta-collector', 'get_volume', sdata[:origin_volume_id])
125
157
  logger.info("create new snapshot: #{snapshot_id}")
126
- raise "Invalid volume state: #{data[:state]}" unless data[:state].to_s == 'available'
127
- job.stm.state=sdata[:state].to_sym
128
- job.stm.on_create
158
+ raise "Invalid volume state: #{data[:state]}" unless data[:state].to_s == 'available' || data[:state].to_s == 'attached'
129
159
 
130
- vol_path = "#{data[:storage_pool][:export_path]}/#{data[:export_path]}"
160
+ vol_path = "#{data[:storage_pool][:export_path]}/#{data[:uuid]}"
131
161
  snap_dir = "#{data[:storage_pool][:snapshot_base_path]}/#{sdata[:account_id]}"
132
162
  unless File.exist?(snap_dir)
133
163
  # create a directory to save snapshot
134
164
  `mkdir -p #{snap_dir}`
135
165
  logger.info("create a directory: #{snap_dir}")
136
166
  end
137
- snap = `zfs snapshot #{vol_path}@#{sdata[:uuid]}`
138
- rpc.request('sta-collector', 'update_snapshot', job.to_hash)
139
- logger.info("creating new snapshot: #{snapshot_id}")
140
-
141
- job.stm.on_create
142
- snap_send = `zfs send #{vol_path}@#{sdata[:uuid]} > #{snap_dir}/#{sdata[:uuid]}.zsnap`
143
- snap_delete = `zfs destroy #{vol_path}@#{sdata[:uuid]}`
167
+ sh("/usr/sbin/zfs snapshot %s@%s", [vol_path, sdata[:uuid]])
168
+ zsnap_file = "#{snap_dir}/#{sdata[:uuid]}.zsnap"
169
+ sh("/usr/sbin/zfs send %s@%s > %s", [vol_path, sdata[:uuid], zsnap_file])
170
+ sh("/usr/sbin/zfs destroy %s@%s", [vol_path, sdata[:uuid]])
171
+
172
+ if Dcmgr::StorageService.has_driver?(dest[:driver])
173
+ begin
174
+ storage = Dcmgr::StorageService.new(dest[:driver], dest[:access_key], dest[:secret_key])
175
+ snapshot_file = "#{dest[:path]}#{dest[:filename]}"
176
+ bucket = storage.bucket(dest[:bucket])
177
+ bucket.upload(snapshot_file, "#{zsnap_file}")
178
+ logger.info("upload to #{dest[:driver]}: #{snapshot_file}")
179
+ rescue => e
180
+ logger.error(e.message)
181
+ raise "snapshot has not be uploaded" if $?.exitstatus != 0
182
+ ensure
183
+ sh("rm -rf %s", ["#{data[:storage_pool][:snapshot_base_path]}/#{sdata[:account_id]}/#{sdata[:uuid]}.zsnap"])
184
+ end
185
+ end
144
186
 
145
- rpc.request('sta-collector', 'update_snapshot', job.to_hash)
187
+ rpc.request('sta-collector', 'update_snapshot', snapshot_id, {:state=>:available})
146
188
  logger.info("created new snapshot: #{snapshot_id}")
147
189
  end
148
190
 
149
191
  job :delete_snapshot do
150
192
  snapshot_id = request.args[0]
151
- job = Dcmgr::Stm::SnapshotContext.new(snapshot_id)
193
+ dest = Dcmgr::StorageService.repository(request.args[1])
152
194
  sdata = rpc.request('sta-collector', 'get_snapshot', snapshot_id)
153
195
  data = rpc.request('sta-collector', 'get_volume', sdata[:origin_volume_id])
154
196
  logger.info("deleting snapshot: #{snapshot_id}")
155
197
  raise "Invalid snapshot state: #{sdata[:state]}" unless sdata[:state].to_s == 'deleting'
156
- job.stm.state=sdata[:state].to_sym
157
- job.stm.on_delete
158
-
159
- system("rm -rf #{data[:storage_pool][:snapshot_base_path]}/#{sdata[:account_id]}/#{sdata[:uuid]}.zsnap")
160
- raise "snapshot has not be deleted" if $?.exitstatus != 0
198
+
199
+ if Dcmgr::StorageService.has_driver?(dest[:driver])
200
+ begin
201
+ storage = Dcmgr::StorageService.new(dest[:driver], dest[:access_key], dest[:secret_key])
202
+ snapshot_file = "#{dest[:path]}#{dest[:filename]}"
203
+ bucket = storage.bucket(dest[:bucket])
204
+ bucket.delete(snapshot_file)
205
+ logger.info("delete sanpshot file from #{dest[:driver]}: #{snapshot_file}")
206
+ rescue => e
207
+ logger.error(e.message)
208
+ raise "snapshot has not be deleted" if $?.exitstatus != 0
209
+ end
210
+ else
211
+ sh("rm -rf %s", ["#{data[:storage_pool][:snapshot_base_path]}/#{sdata[:account_id]}/#{sdata[:uuid]}.zsnap"])
212
+ raise "snapshot has not be deleted" if $?.exitstatus != 0
213
+ end
161
214
 
162
- rpc.request('sta-collector', 'update_snapshot', job.to_hash)
215
+ rpc.request('sta-collector', 'update_snapshot', snapshot_id, {:state=>:deleted, :deleted_at=>Time.now.utc})
163
216
  logger.info("deleted snapshot: #{snapshot_id}")
164
217
  end
165
218
 
@@ -17,3 +17,15 @@ config.bridge_prefix = 'br'
17
17
 
18
18
  # bridge device name novlan
19
19
  config.bridge_novlan = 'br0'
20
+
21
+ # display netfitler commands
22
+ config.verbose_netfilter = false
23
+
24
+ # netfilter log output flag
25
+ config.packet_drop_log = false
26
+
27
+ # debug netfilter
28
+ config.debug_iptables = false
29
+
30
+ # Use ipset for netfilter
31
+ config.use_ipset = false
@@ -5,34 +5,18 @@ require 'eventmachine'
5
5
 
6
6
  Signal.trap('EXIT') { EventMachine.stop }
7
7
 
8
- if defined?(PhusionPassenger)
9
- if PhusionPassenger::VERSION_STRING =~ /^3\.0\./
10
- blk = proc { |forked|
11
- if EventMachine.reactor_running?
12
- EventMachine.stop
13
- Dcmgr.class_eval {
14
- @messaging_client = nil
15
- }
16
- end
17
- Thread.new { EventMachine.epoll; EventMachine.run; }
18
- }
19
- else
20
- blk = proc {
21
- if EventMachine.reactor_running?
22
- EventMachine.stop
23
- Dcmgr.class_eval {
24
- @messaging_client = nil
25
- }
26
- end
27
- Thread.new { EventMachine.epoll; EventMachine.run; }
8
+ def restart_reactor_and_messaging_client
9
+ if EventMachine.reactor_running?
10
+ EventMachine.stop
11
+ Dcmgr.class_eval {
12
+ @messaging_client = nil
28
13
  }
29
14
  end
30
- PhusionPassenger.on_event(:starting_worker_process, &blk)
31
- else
32
- EventMachine.stop if EventMachine.reactor_running?
33
15
  Thread.new { EventMachine.epoll; EventMachine.run; }
34
16
  end
35
17
 
18
+ restart_reactor_and_messaging_client
19
+
36
20
  Dcmgr.class_eval {
37
21
  def self.messaging
38
22
  @messaging_client ||= Isono::MessagingClient.start(conf.amqp_server_uri) do
@@ -1,15 +1,21 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
3
  require 'sequel'
4
- db = Sequel.connect(Dcmgr.conf.database_url)
4
+ if Sequel::DATABASES.first.nil?
5
+ db = Sequel.connect(Dcmgr.conf.database_url)
6
+ else
7
+ db = Sequel::DATABASES.first
8
+ end
9
+
5
10
  #require 'logger'
6
- #db.loggers << Logger.new(STDOUT)
11
+ #db.loggers << Logger.new(STDERR)
7
12
  if db.is_a?(Sequel::MySQL::Database)
8
13
  Sequel::MySQL.default_charset = 'utf8'
9
14
  Sequel::MySQL.default_collate = 'utf8_general_ci'
10
15
  Sequel::MySQL.default_engine = 'InnoDB'
11
16
 
12
17
  db << "SET AUTOCOMMIT=0"
18
+ Dcmgr::Models::BaseNew.default_row_lock_mode = nil
13
19
  end
14
20
 
15
21
  # Disable TEXT to Sequel::SQL::Blob translation.
@@ -19,3 +25,6 @@ end
19
25
  [249, 250, 251, 252].each { |v|
20
26
  Sequel::MySQL::MYSQL_TYPES.delete(v)
21
27
  }
28
+
29
+ # Set timezone to UTC
30
+ Sequel.default_timezone = :utc
data/lib/dcmgr.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # -*- coding: utf-8 -*-
2
2
 
3
+ require 'dcmgr/version'
4
+ require 'ext/time'
5
+
3
6
  module Dcmgr
4
- VERSION='10.12.0'
5
7
 
6
8
  class << self
7
9
  def conf
@@ -28,8 +30,16 @@ module Dcmgr
28
30
  self
29
31
  end
30
32
 
31
- def run_initializers()
33
+ def run_initializers(*files)
32
34
  raise "Complete the configuration prior to run_initializers()." if @conf.nil?
35
+
36
+ @files ||= []
37
+ if files.length == 0
38
+ @files << "*"
39
+ else
40
+ @files = files
41
+ end
42
+
33
43
  initializer_hooks.each { |n|
34
44
  n.call
35
45
  }
@@ -42,29 +52,34 @@ module Dcmgr
42
52
  end
43
53
  @initializer_hooks
44
54
  end
45
-
46
55
  end
47
56
 
48
57
  initializer_hooks {
49
58
  Dcmgr.class_eval {
50
- DCMGR_ROOT = ENV['DCMGR_ROOT'] || File.expand_path('../../', __FILE__)
59
+ unless defined?(DCMGR_ROOT)
60
+ DCMGR_ROOT = ENV['DCMGR_ROOT'] || File.expand_path('../../', __FILE__)
61
+ end
51
62
  }
52
63
  }
53
64
 
54
65
  # Add conf/initializers/*.rb loader
55
66
  initializer_hooks {
56
67
  initializers_root = File.expand_path('config/initializers', DCMGR_ROOT)
57
-
58
- if File.directory?(initializers_root)
59
- Dir.glob("#{initializers_root}/*.rb") { |f|
60
- ::Kernel.load(f)
61
- }
62
- end
68
+
69
+ @files.each { |file|
70
+ if File.directory?(initializers_root)
71
+ Dir.glob("#{initializers_root}/#{file}.rb") { |f|
72
+ ::Kernel.load(f)
73
+ }
74
+ end
75
+ }
63
76
  }
64
77
 
65
78
  autoload :Logger, 'dcmgr/logger'
66
79
 
67
80
  module Models
81
+ class InvalidUUIDError < StandardError; end
82
+ class UUIDPrefixDuplication < StandardError; end
68
83
  autoload :Base, 'dcmgr/models/base'
69
84
 
70
85
  CREATE_TABLE_CLASSES=[:Account,:Tag,:TagMapping,:FrontendSystem,
@@ -74,7 +89,7 @@ module Dcmgr
74
89
  :InstanceNetfilterGroup,
75
90
  :InstanceSpec, :InstanceNic, :Network, :IpLease,
76
91
  :SshKeyPair, :History, :HostnameLease, :MacLease,
77
- :VlanLease,
92
+ :VlanLease, :Quota
78
93
  ].freeze
79
94
  autoload :BaseNew, 'dcmgr/models/base_new'
80
95
  autoload :Account, 'dcmgr/models/account'
@@ -101,6 +116,7 @@ module Dcmgr
101
116
  autoload :HostnameLease, 'dcmgr/models/hostname_lease'
102
117
  autoload :MacLease, 'dcmgr/models/mac_lease'
103
118
  autoload :VlanLease, 'dcmgr/models/vlan_lease'
119
+ autoload :Quota, 'dcmgr/models/quota'
104
120
  end
105
121
 
106
122
  module Endpoints
@@ -112,6 +128,8 @@ module Dcmgr
112
128
  autoload :StaCollector, 'dcmgr/node_modules/sta_collector'
113
129
  autoload :HvaCollector, 'dcmgr/node_modules/hva_collector'
114
130
  autoload :InstanceHA, 'dcmgr/node_modules/instance_ha'
131
+ autoload :ServiceNetfilter, 'dcmgr/node_modules/service_netfilter'
132
+ autoload :InstanceMonitor, 'dcmgr/node_modules/instance_monitor'
115
133
  end
116
134
 
117
135
  module Stm
@@ -122,7 +140,48 @@ module Dcmgr
122
140
 
123
141
  module Helpers
124
142
  autoload :CliHelper, 'dcmgr/helpers/cli_helper'
143
+ autoload :NicHelper, 'dcmgr/helpers/nic_helper'
125
144
  end
126
145
 
127
146
  autoload :Tags, 'dcmgr/tags'
147
+
148
+ module Cli
149
+ require 'dcmgr/cli/errors'
150
+
151
+ autoload :Base, 'dcmgr/cli/base'
152
+ autoload :Network, 'dcmgr/cli/network'
153
+ autoload :Host, 'dcmgr/cli/host'
154
+ autoload :Storage, 'dcmgr/cli/storage'
155
+ autoload :AccountCli, 'dcmgr/cli/account'
156
+ autoload :UsersCli, 'dcmgr/cli/user'
157
+ autoload :Vlan, 'dcmgr/cli/vlan'
158
+ autoload :Image, 'dcmgr/cli/image'
159
+ autoload :KeyPair, 'dcmgr/cli/keypair'
160
+ autoload :Group, 'dcmgr/cli/group'
161
+ autoload :Spec, 'dcmgr/cli/spec'
162
+ autoload :Tag, 'dcmgr/cli/tag'
163
+ autoload :Quota, 'dcmgr/cli/quota'
164
+ end
165
+
166
+ module Rpc
167
+ autoload :HvaHandler, 'dcmgr/rpc/hva_handler'
168
+ autoload :KvmHelper, 'dcmgr/rpc/hva_handler'
169
+ end
170
+
171
+ # namespace for custom Rack HTTP middleware.
172
+ module Rack
173
+ autoload :RequestLogger, 'dcmgr/rack/request_logger'
174
+ autoload :RunInitializer, 'dcmgr/rack/run_initializer'
175
+ end
176
+
177
+ module Drivers
178
+ autoload :SnapshotStorage, 'dcmgr/drivers/snapshot_storage'
179
+ autoload :S3Storage, 'dcmgr/drivers/s3_storage'
180
+ autoload :IIJGIOStorage, 'dcmgr/drivers/iijgio_storage'
181
+ autoload :Hypervisor, 'dcmgr/drivers/hypervisor'
182
+ autoload :Kvm , 'dcmgr/drivers/kvm'
183
+ autoload :Lxc , 'dcmgr/drivers/lxc'
184
+ end
185
+
186
+ autoload :StorageService, 'dcmgr/storage_service'
128
187
  end