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.
Files changed (136) hide show
  1. data/Rakefile +19 -31
  2. data/bin/collector +6 -1
  3. data/config/db/migrations/0001_v1110_origin.rb +446 -0
  4. data/config/dcmgr.conf.example +51 -0
  5. data/lib/dcmgr.rb +99 -22
  6. data/lib/dcmgr/cli/base.rb +34 -1
  7. data/lib/dcmgr/cli/host.rb +24 -20
  8. data/lib/dcmgr/cli/image.rb +38 -19
  9. data/lib/dcmgr/cli/keypair.rb +16 -12
  10. data/lib/dcmgr/cli/network.rb +189 -81
  11. data/lib/dcmgr/cli/quota.rb +2 -2
  12. data/lib/dcmgr/cli/security_group.rb +106 -0
  13. data/lib/dcmgr/cli/spec.rb +144 -39
  14. data/lib/dcmgr/cli/storage.rb +16 -15
  15. data/lib/dcmgr/cli/tag.rb +20 -14
  16. data/lib/dcmgr/cli/vlan.rb +5 -5
  17. data/lib/dcmgr/drivers/backing_store.rb +32 -0
  18. data/lib/dcmgr/drivers/comstar.rb +81 -0
  19. data/lib/dcmgr/drivers/iijgio_storage.rb +9 -19
  20. data/lib/dcmgr/drivers/iscsi_target.rb +41 -0
  21. data/lib/dcmgr/drivers/kvm.rb +161 -28
  22. data/lib/dcmgr/drivers/linux_iscsi.rb +60 -0
  23. data/lib/dcmgr/drivers/local_storage.rb +24 -0
  24. data/lib/dcmgr/drivers/lxc.rb +167 -125
  25. data/lib/dcmgr/drivers/raw.rb +74 -0
  26. data/lib/dcmgr/drivers/s3_storage.rb +7 -19
  27. data/lib/dcmgr/drivers/snapshot_storage.rb +18 -28
  28. data/lib/dcmgr/drivers/storage_initiator.rb +28 -0
  29. data/lib/dcmgr/drivers/sun_iscsi.rb +32 -0
  30. data/lib/dcmgr/drivers/zfs.rb +77 -0
  31. data/lib/dcmgr/endpoints/core_api.rb +315 -263
  32. data/lib/dcmgr/endpoints/errors.rb +21 -10
  33. data/lib/dcmgr/endpoints/metadata.rb +360 -23
  34. data/lib/dcmgr/helpers/cli_helper.rb +6 -3
  35. data/lib/dcmgr/helpers/ec2_metadata_helper.rb +9 -0
  36. data/lib/dcmgr/helpers/nic_helper.rb +11 -0
  37. data/lib/dcmgr/helpers/snapshot_storage_helper.rb +34 -0
  38. data/lib/dcmgr/models/account.rb +0 -6
  39. data/lib/dcmgr/models/account_resource.rb +0 -4
  40. data/lib/dcmgr/models/base_new.rb +14 -2
  41. data/lib/dcmgr/models/dhcp_range.rb +38 -0
  42. data/lib/dcmgr/models/frontend_system.rb +0 -6
  43. data/lib/dcmgr/models/history.rb +0 -11
  44. data/lib/dcmgr/models/host_node.rb +131 -0
  45. data/lib/dcmgr/models/hostname_lease.rb +0 -8
  46. data/lib/dcmgr/models/image.rb +31 -18
  47. data/lib/dcmgr/models/instance.rb +137 -143
  48. data/lib/dcmgr/models/instance_nic.rb +52 -29
  49. data/lib/dcmgr/models/instance_security_group.rb +9 -0
  50. data/lib/dcmgr/models/instance_spec.rb +163 -31
  51. data/lib/dcmgr/models/ip_lease.rb +10 -21
  52. data/lib/dcmgr/models/mac_lease.rb +30 -11
  53. data/lib/dcmgr/models/network.rb +148 -27
  54. data/lib/dcmgr/models/physical_network.rb +18 -0
  55. data/lib/dcmgr/models/quota.rb +0 -10
  56. data/lib/dcmgr/models/request_log.rb +3 -18
  57. data/lib/dcmgr/models/security_group.rb +66 -0
  58. data/lib/dcmgr/models/security_group_rule.rb +145 -0
  59. data/lib/dcmgr/models/ssh_key_pair.rb +16 -19
  60. data/lib/dcmgr/models/{storage_pool.rb → storage_node.rb} +35 -25
  61. data/lib/dcmgr/models/tag.rb +0 -14
  62. data/lib/dcmgr/models/tag_mapping.rb +1 -7
  63. data/lib/dcmgr/models/vlan_lease.rb +2 -8
  64. data/lib/dcmgr/models/volume.rb +49 -37
  65. data/lib/dcmgr/models/volume_snapshot.rb +15 -17
  66. data/lib/dcmgr/node_modules/hva_collector.rb +69 -28
  67. data/lib/dcmgr/node_modules/instance_ha.rb +23 -12
  68. data/lib/dcmgr/node_modules/instance_monitor.rb +16 -2
  69. data/lib/dcmgr/node_modules/openflow_controller.rb +784 -0
  70. data/lib/dcmgr/node_modules/scheduler.rb +189 -0
  71. data/lib/dcmgr/node_modules/service_netfilter.rb +452 -227
  72. data/lib/dcmgr/node_modules/service_openflow.rb +731 -0
  73. data/lib/dcmgr/node_modules/sta_collector.rb +20 -0
  74. data/lib/dcmgr/node_modules/sta_tgt_initializer.rb +35 -0
  75. data/lib/dcmgr/rack/request_logger.rb +11 -6
  76. data/lib/dcmgr/rpc/hva_handler.rb +256 -110
  77. data/lib/dcmgr/rpc/sta_handler.rb +244 -0
  78. data/lib/dcmgr/scheduler.rb +122 -8
  79. data/lib/dcmgr/scheduler/host_node/exclude_same.rb +24 -0
  80. data/lib/dcmgr/scheduler/host_node/find_first.rb +12 -0
  81. data/lib/dcmgr/scheduler/host_node/least_usage.rb +28 -0
  82. data/lib/dcmgr/scheduler/host_node/per_instance.rb +18 -0
  83. data/lib/dcmgr/scheduler/host_node/specify_node.rb +26 -0
  84. data/lib/dcmgr/scheduler/network/flat_single.rb +23 -0
  85. data/lib/dcmgr/scheduler/network/nat_one_to_one.rb +23 -0
  86. data/lib/dcmgr/scheduler/network/per_instance.rb +39 -0
  87. data/lib/dcmgr/scheduler/network/vif_template.rb +19 -0
  88. data/lib/dcmgr/scheduler/storage_node/find_first.rb +13 -0
  89. data/lib/dcmgr/scheduler/storage_node/least_usage.rb +23 -0
  90. data/lib/dcmgr/storage_service.rb +39 -40
  91. data/lib/dcmgr/tags.rb +3 -3
  92. data/lib/dcmgr/version.rb +1 -1
  93. data/lib/dcmgr/vnet.rb +105 -0
  94. data/lib/dcmgr/vnet/factories.rb +141 -0
  95. data/lib/dcmgr/vnet/isolators/by_securitygroup.rb +21 -0
  96. data/lib/dcmgr/vnet/isolators/dummy.rb +17 -0
  97. data/lib/dcmgr/vnet/netfilter/cache.rb +51 -0
  98. data/lib/dcmgr/vnet/netfilter/chain.rb +66 -0
  99. data/lib/dcmgr/vnet/netfilter/controller.rb +193 -0
  100. data/lib/dcmgr/vnet/netfilter/ebtables_rule.rb +53 -0
  101. data/lib/dcmgr/vnet/netfilter/iptables_rule.rb +45 -0
  102. data/lib/dcmgr/vnet/netfilter/task_manager.rb +459 -0
  103. data/lib/dcmgr/vnet/tasks/accept_all_dns.rb +19 -0
  104. data/lib/dcmgr/vnet/tasks/accept_arp_broadcast.rb +24 -0
  105. data/lib/dcmgr/vnet/tasks/accept_arp_from_friends.rb +34 -0
  106. data/lib/dcmgr/vnet/tasks/accept_arp_from_gateway.rb +21 -0
  107. data/lib/dcmgr/vnet/tasks/accept_arp_to_host.rb +30 -0
  108. data/lib/dcmgr/vnet/tasks/accept_ip_from_friends.rb +26 -0
  109. data/lib/dcmgr/vnet/tasks/accept_ip_from_gateway.rb +23 -0
  110. data/lib/dcmgr/vnet/tasks/accept_ip_to_anywhere.rb +18 -0
  111. data/lib/dcmgr/vnet/tasks/accept_related_established.rb +45 -0
  112. data/lib/dcmgr/vnet/tasks/accept_wakame_dhcp_only.rb +33 -0
  113. data/lib/dcmgr/vnet/tasks/accept_wakame_dns_only.rb +33 -0
  114. data/lib/dcmgr/vnet/tasks/debug_iptables.rb +21 -0
  115. data/lib/dcmgr/vnet/tasks/drop_arp_forwarding.rb +27 -0
  116. data/lib/dcmgr/vnet/tasks/drop_arp_to_host.rb +24 -0
  117. data/lib/dcmgr/vnet/tasks/drop_ip_from_anywhere.rb +18 -0
  118. data/lib/dcmgr/vnet/tasks/drop_ip_spoofing.rb +34 -0
  119. data/lib/dcmgr/vnet/tasks/drop_mac_spoofing.rb +33 -0
  120. data/lib/dcmgr/vnet/tasks/exclude_from_nat.rb +47 -0
  121. data/lib/dcmgr/vnet/tasks/security_group.rb +37 -0
  122. data/lib/dcmgr/vnet/tasks/static_nat.rb +54 -0
  123. data/lib/dcmgr/vnet/tasks/translate_metadata_address.rb +32 -0
  124. data/web/metadata/config.ru +1 -1
  125. metadata +174 -89
  126. data/lib/dcmgr/cli/group.rb +0 -101
  127. data/lib/dcmgr/endpoints/core_api_mock.rb +0 -865
  128. data/lib/dcmgr/models/host_pool.rb +0 -122
  129. data/lib/dcmgr/models/instance_netfilter_group.rb +0 -16
  130. data/lib/dcmgr/models/netfilter_group.rb +0 -89
  131. data/lib/dcmgr/models/netfilter_rule.rb +0 -21
  132. data/lib/dcmgr/scheduler/find_last.rb +0 -16
  133. data/lib/dcmgr/scheduler/find_random.rb +0 -16
  134. data/lib/dcmgr/stm/instance.rb +0 -25
  135. data/lib/dcmgr/stm/snapshot_context.rb +0 -33
  136. data/lib/dcmgr/stm/volume_context.rb +0 -65
@@ -6,37 +6,37 @@ module Dcmgr::Cli
6
6
  M = Dcmgr::Models
7
7
 
8
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."
9
+ method_option :uuid, :type => :string, :desc => "The UUID for the new machine spec"
10
+ method_option :account_id, :type => :string, :required => true, :desc => "The UUID of the account that this machine spec belongs to"
11
+ method_option :arch, :type => :string, :default => 'x86_64', :desc => "The architecture for the new machine image. [#{M::HostNode::SUPPORTED_ARCH.join(', ')}]"
12
+ method_option(:hypervisor, :type => :string, :default => M::HostNode::HYPERVISOR_KVM.to_s,
13
+ :desc => "The hypervisor type for the new instance. [#{M::HostNode::SUPPORTED_HYPERVISOR.join(', ')}]")
14
+ method_option :cpu_cores, :type => :numeric, :default => 1, :desc => "The initial cpu cores for the new instance"
15
+ method_option :memory_size, :type => :numeric, :default => 1024, :desc => "The memory size for the new instance"
16
+ method_option :quota_weight, :type => :numeric, :default => 1.0, :desc => "The cost weight factor for the new instance"
18
17
  def add
19
18
  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)
19
+ UnsupportedArchError.raise(options[:arch]) unless M::HostNode::SUPPORTED_ARCH.member?(options[:arch])
20
+ UnsupportedHypervisorError.raise(options[:hypervisor]) unless M::HostNode::SUPPORTED_HYPERVISOR.member?(options[:hypervisor])
21
+ uuid = super(M::InstanceSpec,options)
22
+ # add one interface as default
23
+ invoke("addvif", [uuid, 'eth0'])
24
+ invoke("adddrive", [uuid, 'local', 'ephemeral1'])
25
+ puts uuid
26
26
  end
27
27
 
28
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"
29
+ method_option :account_id, :type => :string, :desc => "The UUID of the account that this machine spec belongs to"
30
+ method_option :arch, :type => :string, :desc => "The architecture for the new machine image. [#{M::HostNode::SUPPORTED_ARCH.join(', ')}]"
31
+ method_option(:hypervisor, :type => :string,
32
+ :desc => "The hypervisor type for the new instance. [#{M::HostNode::SUPPORTED_HYPERVISOR.join(', ')}]")
33
+ method_option :cpu_cores, :type => :numeric, :desc => "The initial cpu cores for the new instance"
34
+ method_option :memory_size, :type => :numeric, :desc => "The memory size for the new instance"
35
+ method_option :quota_weight, :type => :numeric, :desc => "The cost weight factor for the new instance"
36
36
  def modify(uuid)
37
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])
38
+ UnsupportedArchError.raise(options[:arch]) unless options[:arch].nil? || M::HostNode::SUPPORTED_ARCH.member?(options[:arch])
39
+ UnsupportedHypervisorError.raise(options[:hypervisor]) unless options[:hypervisor].nil? || M::HostNode::SUPPORTED_HYPERVISOR.member?(options[:hypervisor])
40
40
  super(M::InstanceSpec,uuid,options)
41
41
  end
42
42
 
@@ -49,24 +49,38 @@ module Dcmgr::Cli
49
49
  desc "show [UUID]", "Show list of machine spec and details"
50
50
  def show(uuid=nil)
51
51
  if uuid
52
- spec = M::InstanceSpec[uuid]
52
+ spec = M::InstanceSpec[uuid] || UnknownUUIDError.raise(uuid)
53
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 %>
54
+ UUID: <%= spec.canonical_uuid %>
55
+ Account ID: <%= spec.account_id %>
56
+ Hypervisor: <%= spec.hypervisor %>
57
+ Arch: <%= spec.arch %>
58
+ CPU Cores: <%= spec.cpu_cores %>
59
+ Memory Size: <%= spec.memory_size %>
60
+ Quota Weight: <%= spec.quota_weight %>
61
+ <%- unless spec.vifs.empty? -%>
62
+ Interfaces:
63
+ <%- spec.vifs.each { |name, i| -%>
64
+ [<%= i[:index] %>] <%= name %>:
65
+ Bandwidth: <%= i[:bandwidth] %> kbps
66
+ <%- } -%>
67
+ <%- end -%>
68
+ <%- unless spec.drives.empty? -%>
69
+ Drives:
70
+ <%- spec.drives.each { |name, i| -%>
71
+ [<%= i[:index] %>] <%= name %>:
72
+ Type: <%= i[:type] %>
73
+ <%- if i[:size] -%>
74
+ Size: <%= i[:size] %> MB
75
+ <%- else -%>
76
+ Snapshot ID: <%= i[:snapshot_id] %>
77
+ <%- end -%>
78
+ <%- } -%>
79
+ <%- end -%>
80
+ <%- unless spec.config.empty? -%>
68
81
  Hypervisor Configuration:
69
82
  <%= spec.config.inspect %>
83
+ <%- end -%>
70
84
  __END
71
85
  else
72
86
  cond = {}
@@ -78,5 +92,96 @@ __END
78
92
  __END
79
93
  end
80
94
  end
95
+
96
+ desc "addvif UUID name", "Add interfance"
97
+ method_option :index, :type => :numeric, :desc => "The index value for the interface. (>=0)"
98
+ method_option :bandwidth, :type => :numeric, :default=>100000, :desc => "The bandwidth (kbps) of the interface"
99
+ def addvif(uuid, name)
100
+ spec = M::InstanceSpec[uuid]
101
+
102
+ index = if options[:index].nil?
103
+ # find max index value.
104
+ index = spec.vifs.values.map { |i| i[:index] }.max
105
+ index.nil? ? 0 : (index + 1)
106
+ else
107
+ options[:index].to_i
108
+ end
109
+
110
+ spec.add_vif(name, index.to_i, options[:bandwidth].to_i)
111
+ spec.save
112
+ end
113
+
114
+ desc "delvif UUID name", "Delete interfance"
115
+ def delvif(uuid, name)
116
+ spec = M::InstanceSpec[uuid]
117
+ spec.remove_vif(name)
118
+ spec.save
119
+ end
120
+
121
+ desc "modifyvif UUID name [options]", "Modify interfance parameters"
122
+ method_option :index, :type => :numeric, :desc => "The index value for the interface"
123
+ method_option :bandwidth, :type => :numeric, :desc => "The bandwidth (kbps) of the interface"
124
+ def modifyvif(uuid, name)
125
+ spec = M::InstanceSpec[uuid]
126
+ if options[:index]
127
+ spec.update_vif_index(name, options[:index].to_i)
128
+ end
129
+ if options[:bandwidth]
130
+ spec.update_vif_bandwidth(name, options[:bandwidth].to_i)
131
+ end
132
+ spec.save
133
+ end
134
+
135
+ desc "adddrive UUID TYPE NAME", "Add drive (TYPE=local,volume)"
136
+ method_option :index, :type => :numeric, :desc => "The index value for the interface. (>=0)"
137
+ method_option :size, :type => :numeric, :default=>100, :desc => "Size of the drive. (MB)"
138
+ def adddrive(uuid, type, name)
139
+ spec = M::InstanceSpec[uuid]
140
+
141
+ index = if options[:index].nil?
142
+ # find max index value.
143
+ index = spec.drives.values.map { |i| i[:index] }.max
144
+ index.nil? ? 0 : (index + 1)
145
+ else
146
+ options[:index].to_i
147
+ end
148
+
149
+ case type
150
+ when 'local'
151
+ spec.add_local_drive(name, index, options[:size].to_i)
152
+ when 'volume'
153
+ spec.add_volume_drive(name, index, options[:size].to_i)
154
+ else
155
+ raise "Unknown drive type: #{type}"
156
+ end
157
+
158
+ spec.save
159
+ end
160
+
161
+ desc "deldrive UUID name", "Delete drive"
162
+ def deldrive(uuid, name)
163
+ spec = M::InstanceSpec[uuid]
164
+ spec.remove_drive(name)
165
+ spec.save
166
+ end
167
+
168
+ desc "modifydrive UUID name [options]", "Modify drive parameters"
169
+ method_option :index, :type => :numeric, :desc => "The index value for the interface"
170
+ method_option :size, :type => :numeric, :desc => "Size of the drive. (MB)"
171
+ method_option :snapshot_id, :type => :string, :desc => "Snapshot ID to copy the content for new drive. Only for "
172
+ def modifydrive(uuid, name)
173
+ spec = M::InstanceSpec[uuid]
174
+ if options[:index]
175
+ spec.update_drive_index(name, options[:index].to_i)
176
+ end
177
+ if options[:size]
178
+ spec.update_drive_size(name, options[:size].to_i)
179
+ end
180
+ if options[:snapshot_id]
181
+ spec.update_drive_snapshot_id(name, options[:snapshot_id])
182
+ end
183
+ spec.save
184
+ end
185
+
81
186
  end
82
187
  end
@@ -9,20 +9,21 @@ class Storage < Base
9
9
  include Dcmgr::Models
10
10
 
11
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."
12
+ method_option :uuid, :type => :string, :desc => "The uuid for the new storage node"
13
+ method_option :base_path, :type => :string, :required => true, :desc => "Base path to store volume files"
14
+ method_option :snapshot_base_path, :type => :string, :required => true, :desc => "Base path to store snapshot files"
15
+ method_option :disk_space, :type => :numeric, :required => true, :desc => "Amount of disk size to be exported (in MB)"
16
+ method_option :force, :type => :boolean, :default=>false, :desc => "Force new entry creation"
17
+ method_option :transport_type, :type => :string, :default=>'iscsi', :desc => "Transport type [iscsi]"
18
+ method_option :ipaddr, :type => :string, :required=>true, :desc => "IP address of transport target"
19
+ method_option :storage_type, :type => :string, :default=>'zfs', :desc => "Storage type [#{StorageNode::SUPPORTED_BACKINGSTORE.join(', ')}]"
20
+ method_option :account_id, :type => :string, :default=>'a-shpoolxx', :desc => "The account ID to own this"
20
21
  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]}")
22
+ unless (options[:force] || Isono::Models::NodeState.find(:node_id=>node_id))
23
+ abort("Node ID is not registered yet: #{node_id}")
23
24
  end
24
25
 
25
- fields = {:node_id=>options[:node_id],
26
+ fields = {:node_id=>node_id,
26
27
  :offering_disk_space=>options[:disk_space],
27
28
  :transport_type=>options[:transport_type],
28
29
  :storage_type=>options[:storage_type],
@@ -33,18 +34,18 @@ class Storage < Base
33
34
  }
34
35
  fields.merge!({:uuid => options[:uuid]}) unless options[:uuid].nil?
35
36
 
36
- puts super(StoragePool,fields)
37
+ puts super(StorageNode,fields)
37
38
  end
38
39
 
39
40
  desc "del UUID", "Deregister a storage node"
40
41
  def del(uuid)
41
- super(StoragePool,uuid)
42
+ super(StorageNode,uuid)
42
43
  end
43
44
 
44
45
  desc "show [UUID]", "Show list of storage nodes and details"
45
46
  def show(uuid=nil)
46
47
  if uuid
47
- st = StoragePool[uuid]
48
+ st = StorageNode[uuid] || UnknownUUIDError.raise(uuid)
48
49
  puts ERB.new(<<__END, nil, '-').result(binding)
49
50
  UUID:
50
51
  <%= st.canonical_uuid %>
@@ -65,7 +66,7 @@ Snapshot base path:
65
66
  __END
66
67
  else
67
68
  cond = {}
68
- all = StoragePool.filter(cond).all
69
+ all = StorageNode.filter(cond).all
69
70
  puts ERB.new(<<__END, nil, '-').result(binding)
70
71
  <%- all.each { |row| -%>
71
72
  <%= "%-15s %-20s %-10s" % [row.canonical_uuid, row.node_id, row.status] %>
@@ -6,11 +6,11 @@ module Dcmgr::Cli
6
6
  M = Dcmgr::Models
7
7
 
8
8
  desc "add [options]", "Create a new tag"
9
- method_option :uuid, :type => :string, :aliases => "-u", :desc => "The UUID for the new tag"
10
- method_option :account_id, :type => :string, :aliases => "-a", :desc => "The UUID of the account that this tag belongs to", :required => true
11
- method_option :type_id, :type => :numeric, :aliases => "-t", :desc => "The type for the new tag. Valid types are '#{Dcmgr::Tags::KEY_MAP.keys.join(", ")}'", :required => true
12
- method_option :name, :type => :string, :aliases => "-n", :desc => "The name for the new tag", :required => true
13
- method_option :attributes, :type => :string, :aliases => "-b", :desc => "The attributes for the new tag"
9
+ method_option :uuid, :type => :string, :desc => "The UUID for the new tag"
10
+ method_option :account_id, :type => :string, :desc => "The UUID of the account that this tag belongs to", :required => true
11
+ method_option :type_id, :type => :numeric, :desc => "The type for the new tag. Valid types are '#{Dcmgr::Tags::KEY_MAP.keys.join(", ")}'", :required => true
12
+ method_option :name, :type => :string, :desc => "The name for the new tag", :required => true
13
+ method_option :attributes, :type => :string, :desc => "The attributes for the new tag"
14
14
  def add
15
15
  UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
16
16
  Error.raise("Invalid type_id: '#{options[:type_id]}'. Valid types are '#{Dcmgr::Tags::KEY_MAP.keys.join(", ")}'.",100) unless Dcmgr::Tags::KEY_MAP.member? options[:type_id]
@@ -19,10 +19,10 @@ module Dcmgr::Cli
19
19
  end
20
20
 
21
21
  desc "modify UUID [options]", "Modify an existing tag"
22
- method_option :account_id, :type => :string, :aliases => "-a", :desc => "The UUID of the account that this tag belongs to"
23
- method_option :type_id, :type => :numeric, :aliases => "-t", :desc => "The type for the new tag. Valid types are '#{Dcmgr::Tags::KEY_MAP.keys.join(", ")}'"
24
- method_option :name, :type => :string, :aliases => "-n", :desc => "The name for the new tag"
25
- method_option :attributes, :type => :string, :aliases => "-b", :desc => "The attributes for the new tag"
22
+ method_option :account_id, :type => :string, :desc => "The UUID of the account that this tag belongs to"
23
+ method_option :type_id, :type => :numeric, :desc => "The type for the new tag. Valid types are '#{Dcmgr::Tags::KEY_MAP.keys.join(", ")}'"
24
+ method_option :name, :type => :string, :desc => "The name for the new tag"
25
+ method_option :attributes, :type => :string, :desc => "The attributes for the new tag"
26
26
  def modify(uuid)
27
27
  UnknownUUIDError.raise(options[:account_id]) if options[:account_id] && M::Account[options[:account_id]].nil?
28
28
  Error.raise("Invalid type_id: '#{options[:type_id]}'. Valid types are '#{Dcmgr::Tags::KEY_MAP.keys.join(", ")}'.",100) unless options[:type_id].nil? || Dcmgr::Tags::KEY_MAP.member?(options[:type_id])
@@ -59,17 +59,23 @@ __END
59
59
  super(M::Tag,uuid)
60
60
  end
61
61
 
62
- desc "map UUID [options]", "Map a tag to a taggable object"
63
- method_option :object_id, :type => :string, :aliases => "-o", :desc => "The canonical UUID for the object to map this tag to.", :required => true
64
- def map(uuid)
62
+ desc "map UUID OBJECT_UUID", "Map a tag to a taggable object"
63
+ long_desc <<__DESC
64
+ Map a tag to a taggable object.
65
+
66
+ UUID: Tag canonical UUID.
67
+ OBJECT_UUID: The canonical UUID represents the object to label this tag.
68
+ __DESC
69
+ #method_option :object_id, :type => :string, :desc => "The canonical UUID for the object to map this tag to.", :required => true
70
+ def map(uuid, object_uuid)
65
71
  #Quick hack to get all models in Dcmgr::Models loaded in Taggable.uuid_prefix_collection
66
72
  #This is so the Taggable.find method can be used to determine the Model class based on canonical uuid
67
73
  M.constants.each {|c| eval("M::#{c}")}
68
74
 
69
- object = M::Taggable.find(options[:object_id])
75
+ object = M::Taggable.find(object_uuid)
70
76
 
71
77
  UnknownUUIDError.raise(uuid) if M::Tag[uuid].nil?
72
- UnknownUUIDError.raise(options[:object_id]) if object.nil?
78
+ UnknownUUIDError.raise(object_uuid) if object.nil?
73
79
  Error.raise("Tag '#{uuid}' can not be mapped to a '#{object.class}'.",100) unless M::Tag[uuid].accept_mapping?(object)
74
80
 
75
81
  M::TagMapping.create(
@@ -6,9 +6,9 @@ module Dcmgr::Cli
6
6
  M = Dcmgr::Models
7
7
 
8
8
  desc "add [options]", "Create a new vlan lease"
9
- method_option :uuid, :type => :string, :aliases => "-u", :desc => "The UUID for the new vlan lease"
10
- method_option :account_id, :type => :string, :aliases => "-a", :desc => "The UUID of the account for this vlan lease"
11
- method_option :tag_id, :type => :numeric, :aliases => "-t", :desc => "The ethernet tag for this vlan lease"
9
+ method_option :uuid, :type => :string, :desc => "The UUID for the new vlan lease"
10
+ method_option :account_id, :type => :string, :desc => "The UUID of the account for this vlan lease"
11
+ method_option :tag_id, :type => :numeric, :desc => "The ethernet tag for this vlan lease"
12
12
  def add
13
13
  UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
14
14
  Error.raise("Tag_id already exists",100) unless M::VlanLease.find(:tag_id => options[:tag_id]).nil?
@@ -22,8 +22,8 @@ module Dcmgr::Cli
22
22
  end
23
23
 
24
24
  desc "modify UUID [options]", "Modify an existing vlan lease"
25
- method_option :account_id, :type => :string, :aliases => "-a", :desc => "The UUID of the account for this vlan lease"
26
- method_option :tag_id, :type => :numeric, :aliases => "-t", :desc => "The ethernet tag for this vlan lease"
25
+ method_option :account_id, :type => :string, :desc => "The UUID of the account for this vlan lease"
26
+ method_option :tag_id, :type => :numeric, :desc => "The ethernet tag for this vlan lease"
27
27
  def modify(uuid)
28
28
  UnknownUUIDError.raise(options[:account_id]) if options[:account_id] && M::Account[options[:account_id]].nil?
29
29
  super(M::VlanLease,uuid,options)
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr
4
+ module Drivers
5
+ class BackingStore
6
+
7
+ def create_volume(ctx, snapshot_file=nil)
8
+ end
9
+
10
+ def delete_volume(ctx)
11
+ end
12
+
13
+ def create_snapshot(ctx, snapshot_file)
14
+ end
15
+
16
+ def delete_snapshot(ctx, snapshot_file)
17
+ end
18
+
19
+ def self.select_backing_store(backing_store)
20
+ case backing_store
21
+ when "raw"
22
+ bs = Dcmgr::Drivers::Raw.new
23
+ when "zfs"
24
+ bs = Dcmgr::Drivers::Zfs.new
25
+ else
26
+ raise "Unknown backing_store type: #{backing_store}"
27
+ end
28
+ bs
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,81 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr
4
+ module Drivers
5
+ class Comstar < IscsiTarget
6
+ include Dcmgr::Logger
7
+ include Dcmgr::Helpers::CliHelper
8
+
9
+ # ref: http://nkjmkzk.net/?p=2022
10
+ def create(ctx)
11
+ @volume = ctx.volume.dup
12
+
13
+ # $ man itadm
14
+ #
15
+ # target_node_name
16
+ # An iSCSI Initiator Node Context is identified by
17
+ # its Initiator Node Name, formatted in either IQN or EUI for-
18
+ # mat (see RFC 3720). For example:
19
+ # iqn.1986-03.com.sun:01:e00000000000.47d55444
20
+ # eui.02004567A425678D
21
+ #
22
+ # [TODO]
23
+ iqn_prefix = "iqn.2010-09.jp.wakame"
24
+ target_node = "#{iqn_prefix}:#{@volume[:account_id]}.#{@volume[:uuid]}"
25
+
26
+ # target
27
+ sh("itadm create-target -n %s", [target_node])
28
+
29
+ # # target group
30
+ # target_group = "tg:#{@volume[:account_id]}.#{@volume[:uuid]}"
31
+ # # target must be offline.
32
+ # # $ stmfadm create-tg a-shpoolxx.vol-chgqqw21
33
+ # # => stmfadm: STMF target must be offline
34
+ # #
35
+ sh("stmfadm offline-target %s", [target_node])
36
+ # sh("stmfadm create-tg %s", [target_group])
37
+ # sh("stmfadm add-tg-member -g %s %s", [target_group, target_node])
38
+ sh("stmfadm online-target %s", [target_node])
39
+
40
+ sh("itadm list-target -v %s", [target_node])
41
+
42
+ # # host group
43
+ # host_group = "hg:#{@volume[:account_id]}.#{@volume[:uuid]}"
44
+ # sh("stmfadm create-hg %s", [host_group])
45
+ # sh("stmfadm add-hg-member -g %s %s", [host_group, target_node])
46
+
47
+ # zvol has already created by backing storep
48
+ zvol_path = "/dev/zvol/rdsk/#{@volume[:storage_node][:export_path]}/#{@volume[:uuid]}"
49
+
50
+ # logical_unit
51
+ logical_unit = sh("sbdadm create-lu %s | /usr/gnu/bin/grep -w %s", [zvol_path, zvol_path])
52
+ guid = logical_unit[:stdout].split(' ')[0]
53
+
54
+ # view
55
+ # sh("stmfadm add-view -t %s -h %s %s", [target_group, host_group, guid])
56
+ sh("stmfadm add-view %s", [guid])
57
+ logical_unit = sh("stmfadm list-view -l %s", [guid])
58
+ logical_unit = logical_unit[:stdout].downcase.split("\n").select {|row| row.strip!}
59
+
60
+ # opt = {:iqn => target_node, :lun=>logical_unit[2].split(": ").last, :guid => guid, :hg => host_group, :tg => target_group}
61
+ opt = {:iqn => target_node, :lun=>logical_unit[2].split(": ").last, :guid => guid}
62
+ end
63
+
64
+ def delete(ctx)
65
+ @volume = ctx.volume
66
+
67
+ guid = @volume[:transport_information][:guid]
68
+ iqn = @volume[:transport_information][:iqn]
69
+ target_group = @volume[:transport_information][:tg]
70
+ host_group = @volume[:transport_information][:hg]
71
+
72
+ sh("stmfadm offline-target %s", [iqn])
73
+ sh("itadm delete-target %s", [iqn])
74
+
75
+ sh("stmfadm delete-lu %s", [guid])
76
+ # sh("stmfadm delete-tg %s", [target_group])
77
+ # sh("stmfadm delete-hg %s", [host_group])
78
+ end
79
+ end
80
+ end
81
+ end