wakame-vdc-dcmgr 11.06.0 → 11.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +19 -31
- data/bin/collector +6 -1
- data/config/db/migrations/0001_v1110_origin.rb +446 -0
- data/config/dcmgr.conf.example +51 -0
- data/lib/dcmgr.rb +99 -22
- data/lib/dcmgr/cli/base.rb +34 -1
- data/lib/dcmgr/cli/host.rb +24 -20
- data/lib/dcmgr/cli/image.rb +38 -19
- data/lib/dcmgr/cli/keypair.rb +16 -12
- data/lib/dcmgr/cli/network.rb +189 -81
- data/lib/dcmgr/cli/quota.rb +2 -2
- data/lib/dcmgr/cli/security_group.rb +106 -0
- data/lib/dcmgr/cli/spec.rb +144 -39
- data/lib/dcmgr/cli/storage.rb +16 -15
- data/lib/dcmgr/cli/tag.rb +20 -14
- data/lib/dcmgr/cli/vlan.rb +5 -5
- data/lib/dcmgr/drivers/backing_store.rb +32 -0
- data/lib/dcmgr/drivers/comstar.rb +81 -0
- data/lib/dcmgr/drivers/iijgio_storage.rb +9 -19
- data/lib/dcmgr/drivers/iscsi_target.rb +41 -0
- data/lib/dcmgr/drivers/kvm.rb +161 -28
- data/lib/dcmgr/drivers/linux_iscsi.rb +60 -0
- data/lib/dcmgr/drivers/local_storage.rb +24 -0
- data/lib/dcmgr/drivers/lxc.rb +167 -125
- data/lib/dcmgr/drivers/raw.rb +74 -0
- data/lib/dcmgr/drivers/s3_storage.rb +7 -19
- data/lib/dcmgr/drivers/snapshot_storage.rb +18 -28
- data/lib/dcmgr/drivers/storage_initiator.rb +28 -0
- data/lib/dcmgr/drivers/sun_iscsi.rb +32 -0
- data/lib/dcmgr/drivers/zfs.rb +77 -0
- data/lib/dcmgr/endpoints/core_api.rb +315 -263
- data/lib/dcmgr/endpoints/errors.rb +21 -10
- data/lib/dcmgr/endpoints/metadata.rb +360 -23
- data/lib/dcmgr/helpers/cli_helper.rb +6 -3
- data/lib/dcmgr/helpers/ec2_metadata_helper.rb +9 -0
- data/lib/dcmgr/helpers/nic_helper.rb +11 -0
- data/lib/dcmgr/helpers/snapshot_storage_helper.rb +34 -0
- data/lib/dcmgr/models/account.rb +0 -6
- data/lib/dcmgr/models/account_resource.rb +0 -4
- data/lib/dcmgr/models/base_new.rb +14 -2
- data/lib/dcmgr/models/dhcp_range.rb +38 -0
- data/lib/dcmgr/models/frontend_system.rb +0 -6
- data/lib/dcmgr/models/history.rb +0 -11
- data/lib/dcmgr/models/host_node.rb +131 -0
- data/lib/dcmgr/models/hostname_lease.rb +0 -8
- data/lib/dcmgr/models/image.rb +31 -18
- data/lib/dcmgr/models/instance.rb +137 -143
- data/lib/dcmgr/models/instance_nic.rb +52 -29
- data/lib/dcmgr/models/instance_security_group.rb +9 -0
- data/lib/dcmgr/models/instance_spec.rb +163 -31
- data/lib/dcmgr/models/ip_lease.rb +10 -21
- data/lib/dcmgr/models/mac_lease.rb +30 -11
- data/lib/dcmgr/models/network.rb +148 -27
- data/lib/dcmgr/models/physical_network.rb +18 -0
- data/lib/dcmgr/models/quota.rb +0 -10
- data/lib/dcmgr/models/request_log.rb +3 -18
- data/lib/dcmgr/models/security_group.rb +66 -0
- data/lib/dcmgr/models/security_group_rule.rb +145 -0
- data/lib/dcmgr/models/ssh_key_pair.rb +16 -19
- data/lib/dcmgr/models/{storage_pool.rb → storage_node.rb} +35 -25
- data/lib/dcmgr/models/tag.rb +0 -14
- data/lib/dcmgr/models/tag_mapping.rb +1 -7
- data/lib/dcmgr/models/vlan_lease.rb +2 -8
- data/lib/dcmgr/models/volume.rb +49 -37
- data/lib/dcmgr/models/volume_snapshot.rb +15 -17
- data/lib/dcmgr/node_modules/hva_collector.rb +69 -28
- data/lib/dcmgr/node_modules/instance_ha.rb +23 -12
- data/lib/dcmgr/node_modules/instance_monitor.rb +16 -2
- data/lib/dcmgr/node_modules/openflow_controller.rb +784 -0
- data/lib/dcmgr/node_modules/scheduler.rb +189 -0
- data/lib/dcmgr/node_modules/service_netfilter.rb +452 -227
- data/lib/dcmgr/node_modules/service_openflow.rb +731 -0
- data/lib/dcmgr/node_modules/sta_collector.rb +20 -0
- data/lib/dcmgr/node_modules/sta_tgt_initializer.rb +35 -0
- data/lib/dcmgr/rack/request_logger.rb +11 -6
- data/lib/dcmgr/rpc/hva_handler.rb +256 -110
- data/lib/dcmgr/rpc/sta_handler.rb +244 -0
- data/lib/dcmgr/scheduler.rb +122 -8
- data/lib/dcmgr/scheduler/host_node/exclude_same.rb +24 -0
- data/lib/dcmgr/scheduler/host_node/find_first.rb +12 -0
- data/lib/dcmgr/scheduler/host_node/least_usage.rb +28 -0
- data/lib/dcmgr/scheduler/host_node/per_instance.rb +18 -0
- data/lib/dcmgr/scheduler/host_node/specify_node.rb +26 -0
- data/lib/dcmgr/scheduler/network/flat_single.rb +23 -0
- data/lib/dcmgr/scheduler/network/nat_one_to_one.rb +23 -0
- data/lib/dcmgr/scheduler/network/per_instance.rb +39 -0
- data/lib/dcmgr/scheduler/network/vif_template.rb +19 -0
- data/lib/dcmgr/scheduler/storage_node/find_first.rb +13 -0
- data/lib/dcmgr/scheduler/storage_node/least_usage.rb +23 -0
- data/lib/dcmgr/storage_service.rb +39 -40
- data/lib/dcmgr/tags.rb +3 -3
- data/lib/dcmgr/version.rb +1 -1
- data/lib/dcmgr/vnet.rb +105 -0
- data/lib/dcmgr/vnet/factories.rb +141 -0
- data/lib/dcmgr/vnet/isolators/by_securitygroup.rb +21 -0
- data/lib/dcmgr/vnet/isolators/dummy.rb +17 -0
- data/lib/dcmgr/vnet/netfilter/cache.rb +51 -0
- data/lib/dcmgr/vnet/netfilter/chain.rb +66 -0
- data/lib/dcmgr/vnet/netfilter/controller.rb +193 -0
- data/lib/dcmgr/vnet/netfilter/ebtables_rule.rb +53 -0
- data/lib/dcmgr/vnet/netfilter/iptables_rule.rb +45 -0
- data/lib/dcmgr/vnet/netfilter/task_manager.rb +459 -0
- data/lib/dcmgr/vnet/tasks/accept_all_dns.rb +19 -0
- data/lib/dcmgr/vnet/tasks/accept_arp_broadcast.rb +24 -0
- data/lib/dcmgr/vnet/tasks/accept_arp_from_friends.rb +34 -0
- data/lib/dcmgr/vnet/tasks/accept_arp_from_gateway.rb +21 -0
- data/lib/dcmgr/vnet/tasks/accept_arp_to_host.rb +30 -0
- data/lib/dcmgr/vnet/tasks/accept_ip_from_friends.rb +26 -0
- data/lib/dcmgr/vnet/tasks/accept_ip_from_gateway.rb +23 -0
- data/lib/dcmgr/vnet/tasks/accept_ip_to_anywhere.rb +18 -0
- data/lib/dcmgr/vnet/tasks/accept_related_established.rb +45 -0
- data/lib/dcmgr/vnet/tasks/accept_wakame_dhcp_only.rb +33 -0
- data/lib/dcmgr/vnet/tasks/accept_wakame_dns_only.rb +33 -0
- data/lib/dcmgr/vnet/tasks/debug_iptables.rb +21 -0
- data/lib/dcmgr/vnet/tasks/drop_arp_forwarding.rb +27 -0
- data/lib/dcmgr/vnet/tasks/drop_arp_to_host.rb +24 -0
- data/lib/dcmgr/vnet/tasks/drop_ip_from_anywhere.rb +18 -0
- data/lib/dcmgr/vnet/tasks/drop_ip_spoofing.rb +34 -0
- data/lib/dcmgr/vnet/tasks/drop_mac_spoofing.rb +33 -0
- data/lib/dcmgr/vnet/tasks/exclude_from_nat.rb +47 -0
- data/lib/dcmgr/vnet/tasks/security_group.rb +37 -0
- data/lib/dcmgr/vnet/tasks/static_nat.rb +54 -0
- data/lib/dcmgr/vnet/tasks/translate_metadata_address.rb +32 -0
- data/web/metadata/config.ru +1 -1
- metadata +174 -89
- data/lib/dcmgr/cli/group.rb +0 -101
- data/lib/dcmgr/endpoints/core_api_mock.rb +0 -865
- data/lib/dcmgr/models/host_pool.rb +0 -122
- data/lib/dcmgr/models/instance_netfilter_group.rb +0 -16
- data/lib/dcmgr/models/netfilter_group.rb +0 -89
- data/lib/dcmgr/models/netfilter_rule.rb +0 -21
- data/lib/dcmgr/scheduler/find_last.rb +0 -16
- data/lib/dcmgr/scheduler/find_random.rb +0 -16
- data/lib/dcmgr/stm/instance.rb +0 -25
- data/lib/dcmgr/stm/snapshot_context.rb +0 -33
- data/lib/dcmgr/stm/volume_context.rb +0 -65
data/lib/dcmgr/models/quota.rb
CHANGED
@@ -3,16 +3,6 @@
|
|
3
3
|
module Dcmgr::Models
|
4
4
|
# Per account quota limit for the VDC resources.
|
5
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
6
|
|
17
7
|
def before_validation
|
18
8
|
# sets default quota values from dcmgr.conf.
|
@@ -3,23 +3,8 @@
|
|
3
3
|
module Dcmgr::Models
|
4
4
|
class RequestLog < BaseNew
|
5
5
|
|
6
|
-
|
7
|
-
|
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
|
13
|
-
String :api_path, :null=>false
|
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
|
22
|
-
end
|
6
|
+
plugin :serialization
|
7
|
+
serialize_attributes :yaml, :params
|
23
8
|
|
24
9
|
def after_initialize
|
25
10
|
super
|
@@ -30,10 +15,10 @@ module Dcmgr::Models
|
|
30
15
|
end
|
31
16
|
|
32
17
|
def before_create
|
33
|
-
super
|
34
18
|
t = Time.now
|
35
19
|
self[:responded_at] = t
|
36
20
|
self[:responded_at_usec] = t.usec
|
21
|
+
super
|
37
22
|
end
|
38
23
|
|
39
24
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Dcmgr::Models
|
4
|
+
class SecurityGroup < AccountResource
|
5
|
+
taggable 'sg'
|
6
|
+
|
7
|
+
one_to_many :security_group_rules
|
8
|
+
many_to_many :instances,:join_table => :instance_security_groups
|
9
|
+
|
10
|
+
def to_hash
|
11
|
+
super.merge({
|
12
|
+
:rule => rule.to_s,
|
13
|
+
:rules => security_group_rules.map { |rule| rule.to_hash },
|
14
|
+
})
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_api_document
|
18
|
+
super.merge({
|
19
|
+
:rule => rule.to_s,
|
20
|
+
:rules => security_group_rules.map { |rule| rule.to_hash },
|
21
|
+
})
|
22
|
+
end
|
23
|
+
|
24
|
+
def after_save
|
25
|
+
super
|
26
|
+
self.rebuild_rule
|
27
|
+
end
|
28
|
+
|
29
|
+
def flush_rule
|
30
|
+
SecurityGroupRule.filter(:security_group_id => self.id).destroy
|
31
|
+
end
|
32
|
+
|
33
|
+
def before_destroy
|
34
|
+
return false if self.instances.size > 0
|
35
|
+
|
36
|
+
self.flush_rule
|
37
|
+
super
|
38
|
+
end
|
39
|
+
alias :destroy_group :destroy
|
40
|
+
|
41
|
+
def rebuild_rule
|
42
|
+
self.flush_rule
|
43
|
+
self.build_rule
|
44
|
+
end
|
45
|
+
|
46
|
+
def build_rule
|
47
|
+
return if self.rule.nil?
|
48
|
+
|
49
|
+
self.rule.split("\n").each { |permission|
|
50
|
+
# [ToDo]
|
51
|
+
# to make strong parser
|
52
|
+
next if permission =~ /\A#/
|
53
|
+
next if permission.length == 0
|
54
|
+
|
55
|
+
# [format] protocol,source,destination
|
56
|
+
# - protocol: tcp|udp|icmp
|
57
|
+
# - source: IPAddr|CIDR|Owner:Group
|
58
|
+
# - destination: port|icmp-type
|
59
|
+
SecurityGroupRule.create(:security_group_id => self.id,
|
60
|
+
:permission => permission)
|
61
|
+
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
require 'strscan'
|
4
|
+
require 'ipaddress'
|
5
|
+
|
6
|
+
module Dcmgr::Models
|
7
|
+
class SecurityGroupRule < BaseNew
|
8
|
+
|
9
|
+
many_to_one :security_group
|
10
|
+
|
11
|
+
def to_hash
|
12
|
+
{
|
13
|
+
:permission => permission,
|
14
|
+
|
15
|
+
}.merge(self.class.parse_rule(self.permission))
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def validate
|
20
|
+
super
|
21
|
+
|
22
|
+
self.class.parse_rule(self.permission)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse_rule(rule)
|
26
|
+
rule = rule.strip.gsub(/[\s\t]+/, '')
|
27
|
+
from_group = false
|
28
|
+
|
29
|
+
# ex.
|
30
|
+
# "tcp:22,22,ip4:0.0.0.0"
|
31
|
+
# "udp:53,53,ip4:0.0.0.0"
|
32
|
+
# "icmp:-1,-1,ip4:0.0.0.0"
|
33
|
+
|
34
|
+
# 1st phase
|
35
|
+
# ip_tport : tcp,udp? 1 - 16bit, icmp: -1
|
36
|
+
# id_port has been separeted in first phase.
|
37
|
+
from_pair, ip_tport, source_pair = rule.split(',')
|
38
|
+
|
39
|
+
next if from_pair.nil?
|
40
|
+
next if ip_tport.nil?
|
41
|
+
next if source_pair.nil?
|
42
|
+
|
43
|
+
# 2nd phase
|
44
|
+
# ip_protocol : [ tcp | udp | icmp ]
|
45
|
+
# ip_fport : tcp,udp? 1 - 16bit, icmp: -1
|
46
|
+
ip_protocol, ip_fport = from_pair.split(':')
|
47
|
+
|
48
|
+
# protocol : [ ip4 | ip6 | security_group_uuid ]
|
49
|
+
# ip_source : ip4? xxx.xxx.xxx.xxx./[0-32], ip6? (not yet supprted)
|
50
|
+
protocol, ip_source = source_pair.split(':')
|
51
|
+
|
52
|
+
s = StringScanner.new(protocol)
|
53
|
+
until s.eos?
|
54
|
+
case
|
55
|
+
when s.scan(/ip6/)
|
56
|
+
# TODO#FUTURE: support IPv6 address format
|
57
|
+
next
|
58
|
+
when s.scan(/ip4/)
|
59
|
+
# IPAddress doesn't support prefix '0'.
|
60
|
+
ip_addr, prefix = ip_source.split('/', 2)
|
61
|
+
if prefix.to_i == 0
|
62
|
+
ip_source = ip_addr
|
63
|
+
end
|
64
|
+
when s.scan(/sg-\w+/)
|
65
|
+
from_group = true
|
66
|
+
else
|
67
|
+
raise "Unexpected protocol '#{s.peep(20)}'"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if from_group == false
|
72
|
+
#p "from_group:(#{from_group}) ip_source -> #{ip_source}"
|
73
|
+
ip = IPAddress(ip_source)
|
74
|
+
ip_source = case ip.u32
|
75
|
+
when 0
|
76
|
+
"#{ip.address}/0"
|
77
|
+
else
|
78
|
+
"#{ip.address}/#{ip.prefix}"
|
79
|
+
end
|
80
|
+
else
|
81
|
+
ip_source = protocol
|
82
|
+
protocol = nil
|
83
|
+
end
|
84
|
+
|
85
|
+
case ip_protocol
|
86
|
+
when 'tcp', 'udp'
|
87
|
+
ip_fport = ip_fport.to_i
|
88
|
+
ip_tport = ip_tport.to_i
|
89
|
+
|
90
|
+
# validate port range
|
91
|
+
[ ip_fport, ip_tport ].each do |port|
|
92
|
+
raise "Out of range port number: #{port}" unless port >= 1 && port <= 65535
|
93
|
+
end
|
94
|
+
|
95
|
+
if !(ip_fport <= ip_tport)
|
96
|
+
raise "Invalid IP port range: #{ip_fport} <= #{ip_tport}"
|
97
|
+
end
|
98
|
+
|
99
|
+
{
|
100
|
+
:ip_protocol => ip_protocol,
|
101
|
+
:ip_fport => ip_fport,
|
102
|
+
:ip_tport => ip_tport,
|
103
|
+
:protocol => protocol,
|
104
|
+
:ip_source => ip_source,
|
105
|
+
}
|
106
|
+
when 'icmp'
|
107
|
+
# via http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/
|
108
|
+
#
|
109
|
+
# For the ICMP protocol, the ICMP type and code must be specified.
|
110
|
+
# This must be specified in the format type:code where both are integers.
|
111
|
+
# Type, code, or both can be specified as -1, which is a wildcard.
|
112
|
+
|
113
|
+
icmp_type = ip_fport.to_i
|
114
|
+
icmp_code = ip_tport.to_i
|
115
|
+
|
116
|
+
# icmp_type
|
117
|
+
case icmp_type
|
118
|
+
when -1
|
119
|
+
when 0, 3, 5, 8, 11, 12, 13, 14, 15, 16, 17, 18
|
120
|
+
else
|
121
|
+
raise "Unsupported ICMP type number: #{icmp_type}"
|
122
|
+
end
|
123
|
+
|
124
|
+
# icmp_code
|
125
|
+
case icmp_code
|
126
|
+
when -1
|
127
|
+
when 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
128
|
+
# when icmp_type equals -1 icmp_code must equal -1.
|
129
|
+
next if icmp_type == -1
|
130
|
+
else
|
131
|
+
raise "Unsupported ICMP code number: #{icmp_code}"
|
132
|
+
end
|
133
|
+
|
134
|
+
{
|
135
|
+
:ip_protocol => ip_protocol,
|
136
|
+
:icmp_type => ip_tport.to_i, # ip_tport.to_i, # -1 or 0, 3, 5, 8, 11, 12, 13, 14, 15, 16, 17, 18
|
137
|
+
:icmp_code => ip_fport.to_i, # ip_fport.to_i, # -1 or 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
138
|
+
:protocol => protocol,
|
139
|
+
:ip_source => ip_source,
|
140
|
+
}
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
@@ -7,32 +7,20 @@ module Dcmgr::Models
|
|
7
7
|
class SshKeyPair < AccountResource
|
8
8
|
taggable 'ssh'
|
9
9
|
|
10
|
-
inheritable_schema do
|
11
|
-
String :name, :size=>100, :null=>false
|
12
|
-
String :finger_print, :size=>100, :null=>false
|
13
|
-
Text :public_key, :null=>false
|
14
|
-
Text :private_key, :null=>true
|
15
|
-
|
16
|
-
index [:account_id, :name], {:unique=>true}
|
17
|
-
end
|
18
|
-
with_timestamps
|
19
|
-
|
20
|
-
def validate
|
21
|
-
end
|
22
|
-
|
23
10
|
def before_destroy
|
24
11
|
# TODO: check running instances which are associated to ssh key
|
25
12
|
# pairs. reject deletion if exist.
|
13
|
+
super
|
26
14
|
end
|
27
15
|
|
28
|
-
#
|
16
|
+
#
|
29
17
|
# @return [Hash] {:private_key=>'pkey string',
|
30
18
|
# :public_key=>'pubkey string'}
|
31
|
-
def self.generate_key_pair()
|
19
|
+
def self.generate_key_pair(name)
|
32
20
|
pkey = File.expand_path(randstr, Dir.tmpdir)
|
33
21
|
pubkey = pkey + '.pub'
|
34
22
|
begin
|
35
|
-
system("ssh-keygen -q -t rsa -C '' -N '' -f %s >/dev/null" % [pkey])
|
23
|
+
system("ssh-keygen -q -t rsa -C '%s' -N '' -f %s >/dev/null" % [name, pkey])
|
36
24
|
unless $?.exitstatus == 0
|
37
25
|
raise "Failed to run ssh-keygen: exitcode=#{$?.exitstatus}"
|
38
26
|
end
|
@@ -43,7 +31,7 @@ module Dcmgr::Models
|
|
43
31
|
raise "Failed to collect finger print value"
|
44
32
|
end
|
45
33
|
fp = fp.split(/\s+/)[1]
|
46
|
-
|
34
|
+
|
47
35
|
{:private_key=>IO.read(pkey),
|
48
36
|
:public_key=>IO.read(pubkey),
|
49
37
|
:finger_print => fp}
|
@@ -56,13 +44,22 @@ module Dcmgr::Models
|
|
56
44
|
end
|
57
45
|
|
58
46
|
def to_api_document
|
59
|
-
|
47
|
+
super
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.entry_new(account, &blk)
|
51
|
+
raise ArgurmentError unless account.is_a?(Account)
|
52
|
+
|
53
|
+
ssh = self.new &blk
|
54
|
+
ssh.account_id = account.canonical_uuid
|
55
|
+
|
56
|
+
ssh
|
60
57
|
end
|
61
58
|
|
62
59
|
private
|
63
60
|
def self.randstr
|
64
61
|
Array.new(10) { (('a'..'z').to_a + (0..9).to_a)[rand(36)] }.join
|
65
62
|
end
|
66
|
-
|
63
|
+
|
67
64
|
end
|
68
65
|
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
+
require 'isono/models/node_state'
|
4
|
+
|
3
5
|
module Dcmgr::Models
|
4
|
-
class
|
5
|
-
taggable '
|
6
|
+
class StorageNode < AccountResource
|
7
|
+
taggable 'sn'
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
String :export_path, :null=>false
|
10
|
-
Fixnum :offering_disk_space, :null=>false, :unsigned=>true
|
11
|
-
String :transport_type, :null=>false
|
12
|
-
String :storage_type, :null=>false
|
13
|
-
String :ipaddr, :null=>false
|
14
|
-
String :snapshot_base_path, :null=>false
|
9
|
+
BACKINGSTORE_ZFS = 'zfs'
|
10
|
+
BACKINGSTORE_RAW = 'raw'
|
15
11
|
|
16
|
-
|
17
|
-
end
|
18
|
-
with_timestamps
|
12
|
+
SUPPORTED_BACKINGSTORE = [BACKINGSTORE_ZFS, BACKINGSTORE_RAW]
|
19
13
|
|
20
14
|
one_to_many :volumes
|
21
15
|
one_to_many :volume_snapshots
|
22
16
|
|
23
17
|
many_to_one :node, :class=>Isono::Models::NodeState, :key=>:node_id, :primary_key=>:node_id
|
18
|
+
|
19
|
+
def_dataset_method(:online_nodes) do
|
20
|
+
# SELECT * FROM `storage_nodes` WHERE ('node_id' IN (SELECT `node_id` FROM `node_states` WHERE (`state` = 'online')))
|
21
|
+
r = Isono::Models::NodeState.filter(:state => 'online').select(:node_id)
|
22
|
+
filter(:node_id => r)
|
23
|
+
end
|
24
24
|
|
25
25
|
def before_validation
|
26
26
|
export_path = self.export_path
|
@@ -29,6 +29,7 @@ module Dcmgr::Models
|
|
29
29
|
export_path.shift
|
30
30
|
self.export_path = export_path.join('/')
|
31
31
|
end
|
32
|
+
super
|
32
33
|
end
|
33
34
|
|
34
35
|
def self.create_pool(params)
|
@@ -48,17 +49,6 @@ module Dcmgr::Models
|
|
48
49
|
}
|
49
50
|
end
|
50
51
|
|
51
|
-
# def find_private_pool(account_id, uuid)
|
52
|
-
# sp = self.dataset.where(:account_id=>account_id).where(:uuid=>uuid)
|
53
|
-
# end
|
54
|
-
|
55
|
-
def create_volume(account_id, size, snapshot_id=nil)
|
56
|
-
v = Volume.create(:account_id => account_id,
|
57
|
-
:storage_pool_id => self.id,
|
58
|
-
:snapshot_id => snapshot_id,
|
59
|
-
:size =>size)
|
60
|
-
end
|
61
|
-
|
62
52
|
# Show status of the agent.
|
63
53
|
def status
|
64
54
|
node.nil? ? :offline : node.state
|
@@ -69,9 +59,29 @@ module Dcmgr::Models
|
|
69
59
|
end
|
70
60
|
|
71
61
|
def to_api_document
|
72
|
-
h =
|
62
|
+
h = super()
|
63
|
+
h.merge!(:status=>self.status)
|
73
64
|
h.delete(:node_id)
|
74
65
|
h
|
75
66
|
end
|
67
|
+
|
68
|
+
# Returns total disk usage of associated volumes.
|
69
|
+
def disk_usage
|
70
|
+
volumes_dataset.lives.sum(:size).to_i
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns available space of the storage node.
|
74
|
+
def free_disk_space
|
75
|
+
self.offering_disk_space - self.disk_usage
|
76
|
+
end
|
77
|
+
|
78
|
+
# Check the free resource capacity across entire local VDC domain.
|
79
|
+
def self.check_domain_capacity?(size, num=1)
|
80
|
+
alives_size = Volume.dataset.lives.filter.sum(:size).to_i
|
81
|
+
avail_size = self.online_nodes.sum(:offering_disk_space).to_i - alives_size
|
82
|
+
|
83
|
+
(avail_size >= size * num.to_i)
|
84
|
+
end
|
85
|
+
|
76
86
|
end
|
77
87
|
end
|