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
@@ -8,15 +8,25 @@ module Dcmgr::Models
8
8
  inheritable_schema do
9
9
  Fixnum :instance_id, :null=>false
10
10
  Fixnum :network_id, :null=>false
11
+ Fixnum :nat_network_id
12
+ Fixnum :bandwidth_group_id
11
13
  String :mac_addr, :null=>false, :size=>12
12
14
 
13
15
  index :mac_addr
14
16
  end
15
17
  with_timestamps
16
18
 
19
+ many_to_one :bandwidth_group
17
20
  many_to_one :instance
21
+ many_to_one :nat_network, :key => :nat_network_id, :class => Network
18
22
  many_to_one :network
19
- one_to_one :ip, :class=>IpLease
23
+ one_to_many :ip, :class=>IpLease
24
+ one_to_many(:direct_ip_lease, :class=>IpLease, :read_only=>true) do |ds|
25
+ ds.where(:network_id=>self.network_id)
26
+ end
27
+ one_to_many(:nat_ip_lease, :class=>IpLease, :read_only=>true) do |ds|
28
+ ds.where(:network_id=>self.nat_network_id)
29
+ end
20
30
 
21
31
  def to_hash
22
32
  h = values.dup.merge(super)
@@ -43,7 +53,7 @@ module Dcmgr::Models
43
53
 
44
54
  def before_destroy
45
55
  MacLease.find(:mac_addr=>self.mac_addr).destroy
46
- ip && ip.destroy
56
+ ip_dataset.destroy
47
57
  super
48
58
  end
49
59
 
@@ -5,12 +5,17 @@ module Dcmgr::Models
5
5
  taggable 'is'
6
6
 
7
7
  inheritable_schema do
8
+ String :name, :null=>false
8
9
  String :hypervisor, :null=>false
9
10
  String :arch, :null=>false
10
11
 
11
12
  Fixnum :cpu_cores, :null=>false, :unsigned=>true
12
13
  Fixnum :memory_size, :null=>false, :unsigned=>true
14
+ Float :quota_weight, :null=>false, :default=>1.0
13
15
  Text :config, :null=>false, :default=>''
16
+ Text :storage, :null=>false, :default=>''
17
+
18
+ index [:account_id, :name], {:unique=>true}
14
19
  end
15
20
  with_timestamps
16
21
 
@@ -21,6 +26,10 @@ module Dcmgr::Models
21
26
  # {:block_driver=>'virtio', :nic_driver=>'virtio'}
22
27
  plugin :serialization
23
28
  serialize_attributes :yaml, :config
29
+ # hypervisor=kvm:
30
+ # { 'sdc' => {:type=>:vdcvol, :size=>100, :dev=>'/dev/sdc'},
31
+ # 'eph1' => {:type=>:ephemeral, :size=>1000, :dev=>'/dev/sdb'}}
32
+ serialize_attributes :yaml, :storage
24
33
 
25
34
  def before_validate
26
35
  default_config =
@@ -35,7 +44,14 @@ module Dcmgr::Models
35
44
 
36
45
  def to_hash
37
46
  super.merge({:config=>self.config, # yaml -> Hash
47
+ :storage => self.storage, # yaml -> Hash
38
48
  })
39
49
  end
50
+
51
+ def to_api_document
52
+ doc = to_hash
53
+ doc.delete(:config)
54
+ doc
55
+ end
40
56
  end
41
57
  end
@@ -8,15 +8,22 @@ module Dcmgr::Models
8
8
  TYPE_AUTO=0
9
9
  TYPE_RESERVED=1
10
10
  TYPE_MANUAL=2
11
+
12
+ TYPE_MESSAGES={
13
+ TYPE_AUTO=>'auto',
14
+ TYPE_RESERVED=>'reserved',
15
+ TYPE_MANUAL=>'manual'
16
+ }
11
17
 
12
18
  inheritable_schema do
13
19
  Fixnum :instance_nic_id
14
20
  Fixnum :network_id, :null=>false
15
21
  String :ipv4, :size=>50
16
- Fixnum :type, :null=>false, :default=>TYPE_AUTO
22
+ Fixnum :alloc_type, :null=>false, :default=>TYPE_AUTO
17
23
  Text :description
18
24
 
19
25
  index [:network_id, :ipv4], {:unique=>true}
26
+ index [:instance_nic_id, :network_id]
20
27
  end
21
28
  with_timestamps
22
29
 
@@ -36,6 +43,35 @@ module Dcmgr::Models
36
43
  end
37
44
  end
38
45
 
46
+ # check if the current lease is for NAT outside address lease.
47
+ # @return [TrueClass,FalseClass] return true if the lease is for NAT outside.
48
+ def is_natted?
49
+ instance_nic.network_id != network_id
50
+ end
51
+
52
+ # get the lease of NAT outside network.
53
+ # @return [IpLease,nil]
54
+ # if the IpLease has a pair NAT address it will return
55
+ # outside IpLease.
56
+ def nat_outside_lease
57
+ if self.network.nat_network_id
58
+ self.class.find(:instance_nic_id=>self.instance_nic.id, :network_id=>self.network.nat_network_id)
59
+ else
60
+ nil
61
+ end
62
+ end
63
+
64
+ # get the lease of NAT inside network.
65
+ # @return [IpLease,nil] IpLease (outside) will return inside
66
+ # IpLease.
67
+ def nat_inside_lease
68
+ if self.network.nat_network_id.nil?
69
+ self.class.find(:instance_nic_id=>self.instance_nic.id, :network_id=>nil)
70
+ else
71
+ nil
72
+ end
73
+ end
74
+
39
75
  def self.lease(instance_nic, network)
40
76
  raise TypeError unless instance_nic.is_a?(InstanceNic)
41
77
  raise TypeError unless network.is_a?(Network)
@@ -13,7 +13,7 @@ module Dcmgr::Models
13
13
  end
14
14
 
15
15
  one_to_many :netfilter_rules
16
- one_to_many :instance_netfilter_groups
16
+ many_to_many :instances,:join_table => :instance_netfilter_groups
17
17
 
18
18
  def to_hash
19
19
  h = super
@@ -28,6 +28,10 @@ module Dcmgr::Models
28
28
  #:rules => netfilter_rules.map { |rule| rule.to_hash },
29
29
  #}
30
30
  end
31
+
32
+ def to_api_document
33
+ to_hash
34
+ end
31
35
 
32
36
  def to_tiny_hash
33
37
  {
@@ -50,6 +54,8 @@ module Dcmgr::Models
50
54
  end
51
55
 
52
56
  def before_destroy
57
+ return false if self.instances.size > 0
58
+
53
59
  self.flush_rule
54
60
  super
55
61
  end
@@ -79,11 +85,5 @@ module Dcmgr::Models
79
85
  }
80
86
  end
81
87
 
82
- def instances
83
- self.instance_netfilter_groups.map { |instance_netfilter_group|
84
- instance_netfilter_group.instance
85
- }
86
- end
87
-
88
88
  end
89
89
  end
@@ -14,13 +14,28 @@ module Dcmgr::Models
14
14
  String :dns_server
15
15
  String :dhcp_server
16
16
  String :metadata_server
17
- Fixnum :vlan_lease_id, :null=>false
17
+ Fixnum :metadata_server_port
18
+ Fixnum :bandwidth #in Mbit/s
19
+ Fixnum :vlan_lease_id, :null=>false, :default=>0
20
+ Fixnum :nat_network_id
18
21
  Text :description
22
+ index :nat_network_id
19
23
  end
20
24
  with_timestamps
21
25
 
22
- one_to_many :ip_lease
26
+ module IpLeaseMethods
27
+ def add_reserved(ipaddr, description=nil)
28
+ model.create(:network_id=>model_object.id,
29
+ :ipv4=>ipaddr,
30
+ :alloc_type=>IpLease::TYPE_RESERVED,
31
+ :description=>description)
32
+ end
33
+ end
34
+ one_to_many :ip_lease, :extend=>IpLeaseMethods
23
35
  many_to_one :vlan_lease
36
+
37
+ many_to_one :nat_network, :key => :nat_network_id, :class => self
38
+ one_to_many :inside_networks, :key => :nat_network_id, :class => self
24
39
 
25
40
  def validate
26
41
  super
@@ -41,11 +56,35 @@ module Dcmgr::Models
41
56
  h = super
42
57
  h.delete(:vlan_lease_id)
43
58
  h.merge({
59
+ :bandwidth_mark=>self[:id],
44
60
  :description=>description.to_s,
45
- :vlan_id => vlan_lease.tag_id,
61
+ :vlan_id => vlan_lease.nil? ? 0 : vlan_lease.tag_id,
46
62
  })
47
63
  end
48
64
 
65
+ def before_destroy
66
+ #Make sure no other networks are natted to this one
67
+ Network.filter(:nat_network_id => self[:id]).each { |n|
68
+ n.nat_network_id = nil
69
+ n.save
70
+ }
71
+
72
+ #Delete all reserved ipleases in this network
73
+ self.ip_lease_dataset.filter(:alloc_type => IpLease::TYPE_RESERVED).each { |i|
74
+ i.destroy
75
+ }
76
+
77
+ super
78
+ end
79
+
80
+ def to_api_document
81
+ to_hash
82
+ end
83
+
84
+ def nat_network
85
+ Network.find(:id => self.nat_network_id)
86
+ end
87
+
49
88
  def ipaddress
50
89
  IPAddress::IPv4.new("#{self.ipv4_gw}/#{self.prefix}")
51
90
  end
@@ -0,0 +1,25 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr::Models
4
+ # Per account quota limit for the VDC resources.
5
+ class Quota < BaseNew
6
+ taggable 'q'
7
+
8
+ inheritable_schema do
9
+ Fixnum :account_id, :null=>false
10
+ Float :instance_total_weight
11
+ Fixnum :volume_total_size
12
+
13
+ index :account_id
14
+ end
15
+ with_timestamps
16
+
17
+ def before_validation
18
+ # sets default quota values from dcmgr.conf.
19
+ self.instance_total_weight ||= Dcmgr.conf.account_instance_total_weight
20
+ self.volume_total_size ||= Dcmgr.conf.account_volume_total_size
21
+ super
22
+ end
23
+ end
24
+ end
25
+
@@ -5,21 +5,36 @@ module Dcmgr::Models
5
5
 
6
6
  inheritable_schema do
7
7
  String :request_id, :null=>false, :size=>40, :unique=>true
8
- Fixnum :frontend_system_id, :null=>false
9
- Fixnum :account_id, :null=>false
10
- String :requester_symbol, :null=>false, :size=>100
11
- # HTTP Response Code
12
- Fixnum :response_status, :null=>false
13
- String :response_msg
8
+ String :frontend_system_id, :null=>false, :size=>40
9
+ String :account_id, :null=>false, :size=>40
10
+ String :requester_token, :null=>true, :size=>100
11
+ # HTTP Request Content
12
+ String :request_method, :null=>false, :size=>10
14
13
  String :api_path, :null=>false
15
- String :params, :null=>false
16
- Time :requested_at
17
- Time :responsed_at
14
+ Text :params, :null=>false
15
+ # HTTP Response Content
16
+ Fixnum :response_status, :null=>false
17
+ Text :response_msg, :null=>true
18
+ Time :requested_at, :null=>false
19
+ Fixnum :requested_at_usec, :null=>false, :unsigned=>true
20
+ Time :responded_at, :null=>false
21
+ Fixnum :responded_at_usec, :null=>false, :unsigned=>true
18
22
  end
19
23
 
20
24
  def after_initialize
21
- self[:request_id] #
25
+ super
26
+ self[:request_id] ||= Isono::Util.gen_id
27
+ t = Time.now
28
+ self[:requested_at] = t
29
+ self[:requested_at_usec] = t.usec
22
30
  end
23
-
31
+
32
+ def before_create
33
+ super
34
+ t = Time.now
35
+ self[:responded_at] = t
36
+ self[:responded_at_usec] = t.usec
37
+ end
38
+
24
39
  end
25
40
  end
@@ -9,6 +9,7 @@ module Dcmgr::Models
9
9
 
10
10
  inheritable_schema do
11
11
  String :name, :size=>100, :null=>false
12
+ String :finger_print, :size=>100, :null=>false
12
13
  Text :public_key, :null=>false
13
14
  Text :private_key, :null=>true
14
15
 
@@ -35,9 +36,17 @@ module Dcmgr::Models
35
36
  unless $?.exitstatus == 0
36
37
  raise "Failed to run ssh-keygen: exitcode=#{$?.exitstatus}"
37
38
  end
39
+
40
+ # get finger print of pkey file
41
+ fp = `ssh-keygen -l -f #{pkey}`
42
+ unless $?.exitstatus == 0
43
+ raise "Failed to collect finger print value"
44
+ end
45
+ fp = fp.split(/\s+/)[1]
38
46
 
39
47
  {:private_key=>IO.read(pkey),
40
- :public_key=>IO.read(pubkey)}
48
+ :public_key=>IO.read(pubkey),
49
+ :finger_print => fp}
41
50
  rescue
42
51
  # clean up tmp key files
43
52
  [pkey, pubkey].each { |i|
@@ -46,6 +55,10 @@ module Dcmgr::Models
46
55
  end
47
56
  end
48
57
 
58
+ def to_api_document
59
+ to_hash
60
+ end
61
+
49
62
  private
50
63
  def self.randstr
51
64
  Array.new(10) { (('a'..'z').to_a + (0..9).to_a)[rand(36)] }.join
@@ -1,30 +1,13 @@
1
1
  # -*- coding: utf-8 -*-
2
- require 'statemachine'
3
2
 
4
3
  module Dcmgr::Models
5
4
  class StoragePool < AccountResource
6
5
  taggable 'sp'
7
- with_timestamps
8
-
9
- STATAS_TYPE_REGISTERING = "registering"
10
- STATAS_TYPE_ONLINE = "online"
11
- STATAS_TYPE_DEGRADE = "degrade"
12
- STATAS_TYPE_FAILED = "failed"
13
- STATAS_TYPE_DEREGISTERED = "deregistered"
14
6
 
15
- STATUS_MSGS = {
16
- STATAS_TYPE_REGISTERING => :registering,
17
- STATAS_TYPE_ONLINE => :online,
18
- STATAS_TYPE_DEGRADE => :degrade,
19
- STATAS_TYPE_FAILED => :failed,
20
- STATAS_TYPE_DEREGISTERED => :deregistered
21
- }
22
-
23
7
  inheritable_schema do
24
8
  String :node_id, :null=>false
25
9
  String :export_path, :null=>false
26
- String :status, :null=>false, :default=>STATAS_TYPE_REGISTERING
27
- Fixnum :offerring_disk_space, :null=>false, :unsigned=>true
10
+ Fixnum :offering_disk_space, :null=>false, :unsigned=>true
28
11
  String :transport_type, :null=>false
29
12
  String :storage_type, :null=>false
30
13
  String :ipaddr, :null=>false
@@ -32,11 +15,12 @@ module Dcmgr::Models
32
15
 
33
16
  index :node_id
34
17
  end
18
+ with_timestamps
35
19
 
36
20
  one_to_many :volumes
37
21
  one_to_many :volume_snapshots
38
22
 
39
- many_to_one :storage_agents
23
+ many_to_one :node, :class=>Isono::Models::NodeState, :key=>:node_id, :primary_key=>:node_id
40
24
 
41
25
  def before_validation
42
26
  export_path = self.export_path
@@ -47,62 +31,10 @@ module Dcmgr::Models
47
31
  end
48
32
  end
49
33
 
50
- def state_machine
51
- model = self
52
- st = Statemachine.build do
53
- superstate :storage_condition do
54
- trans :registering, :on_success, :online
55
- trans :registering, :on_error, :degrade
56
- trans :online, :on_success, :online
57
- trans :online, :on_error, :degrade
58
- trans :degrade, :on_success, :online
59
- trans :degrade, :on_error, :degrade
60
-
61
- event :on_fail, :failed
62
- event :on_deregistered, :deregistered
63
- end
64
-
65
- trans :failed, :on_success, :online
66
- trans :failed, :on_error, :degrade
67
- trans :failed, :on_deregistered, :deregistered
68
-
69
- on_entry_of :registering, proc {
70
- model.status = STATAS_TYPE_REGISTERING
71
- }
72
-
73
- on_entry_of :online, proc {
74
- model.status = STATAS_TYPE_ONLINE
75
- }
76
-
77
- on_entry_of :degrade, proc {
78
- model.status = STATAS_TYPE_DEGRADE
79
- }
80
-
81
- on_entry_of :failed, proc {
82
- model.status = STATAS_TYPE_FAILED
83
- }
84
-
85
- on_entry_of :deregistered, proc {
86
- model.status = STATAS_TYPE_DEREGISTERED
87
- }
88
- end
89
-
90
- if self[:status]
91
- if st.has_state(STATUS_MSGS[self[:status]].to_sym)
92
- st.state = STATUS_MSGS[self[:status]].to_sym
93
- else
94
- raise "Unknown state: #{self[:status]}"
95
- end
96
- else
97
- st.reset
98
- end
99
- st
100
- end
101
-
102
34
  def self.create_pool(params)
103
35
  self.create(:account_id => params[:account_id],
104
36
  :node_id => params[:node_id],
105
- :offerring_disk_space => params[:offerring_disk_space],
37
+ :offering_disk_space => params[:offering_disk_space],
106
38
  :transport_type => params[:transport_type],
107
39
  :storage_type => params[:storage_type],
108
40
  :export_path => params[:export_path],
@@ -126,5 +58,20 @@ module Dcmgr::Models
126
58
  :snapshot_id => snapshot_id,
127
59
  :size =>size)
128
60
  end
61
+
62
+ # Show status of the agent.
63
+ def status
64
+ node.nil? ? :offline : node.state
65
+ end
66
+
67
+ def to_hash
68
+ super.merge({:status=>self.status})
69
+ end
70
+
71
+ def to_api_document
72
+ h = to_hash
73
+ h.delete(:node_id)
74
+ h
75
+ end
129
76
  end
130
77
  end