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
@@ -24,3 +24,54 @@ create_volume_min_size 10
24
24
  # Default account quota limit
25
25
  account_instance_total_weight 100.0
26
26
  account_volume_total_size 100000 # 100GB
27
+
28
+ stopped_instance_usage_factor 1.0
29
+
30
+ recent_terminated_instance_period 900
31
+
32
+ mac_address_vendor_id nil
33
+
34
+ # Scheduling Algorithms
35
+ #host_node_scheduler :FindFirst
36
+ host_node_scheduler {
37
+ scheduler :LeastUsage
38
+ }
39
+
40
+ #storage_node_scheduler :FindFirst
41
+ storage_node_scheduler {
42
+ scheduler :LeastUsage
43
+ }
44
+ #network_scheduler :FlatSingle
45
+ network_scheduler {
46
+ scheduler :PerInstance
47
+ options {
48
+ default {
49
+ scheduler :FlatSingle
50
+ }
51
+ nat {
52
+ scheduler :NatOneToOne
53
+ options {
54
+ network_id 'nw-demo1'
55
+ nat_network_id 'nw-demo2'
56
+ }
57
+ }
58
+ vif3type1 {
59
+ scheduler :VifTemplate
60
+ options( {
61
+ 'eth0' => 'nw-demo1',
62
+ 'eth1' => 'nw-demo2',
63
+ 'eth2' => 'nw-demo3',
64
+ })
65
+ }
66
+ vif3type2 {
67
+ scheduler :VifTemplate
68
+ options( {
69
+ 'eth0' => 'nw-demo1',
70
+ 'eth1' => 'nw-demo4',
71
+ 'eth2' => 'nw-demo5',
72
+ })
73
+ }
74
+ }
75
+ }
76
+
77
+ mac_address_vendor_id '525400'
@@ -82,15 +82,6 @@ module Dcmgr
82
82
  class UUIDPrefixDuplication < StandardError; end
83
83
  autoload :Base, 'dcmgr/models/base'
84
84
 
85
- CREATE_TABLE_CLASSES=[:Account,:Tag,:TagMapping,:FrontendSystem,
86
- :Image,:HostPool,:RequestLog,:Instance,
87
- :NetfilterGroup, :NetfilterRule,
88
- :StoragePool,:Volume,:VolumeSnapshot,
89
- :InstanceNetfilterGroup,
90
- :InstanceSpec, :InstanceNic, :Network, :IpLease,
91
- :SshKeyPair, :History, :HostnameLease, :MacLease,
92
- :VlanLease, :Quota
93
- ].freeze
94
85
  autoload :BaseNew, 'dcmgr/models/base_new'
95
86
  autoload :Account, 'dcmgr/models/account'
96
87
  autoload :Tag, 'dcmgr/models/tag'
@@ -98,49 +89,50 @@ module Dcmgr
98
89
  autoload :AccountResource, 'dcmgr/models/account_resource'
99
90
  autoload :Instance, 'dcmgr/models/instance'
100
91
  autoload :Image, 'dcmgr/models/image'
101
- autoload :HostPool, 'dcmgr/models/host_pool'
92
+ autoload :HostNode, 'dcmgr/models/host_node'
102
93
  autoload :RequestLog, 'dcmgr/models/request_log'
103
94
  autoload :FrontendSystem, 'dcmgr/models/frontend_system'
104
- autoload :StoragePool, 'dcmgr/models/storage_pool'
95
+ autoload :StorageNode, 'dcmgr/models/storage_node'
105
96
  autoload :Volume, 'dcmgr/models/volume'
106
97
  autoload :VolumeSnapshot, 'dcmgr/models/volume_snapshot'
107
- autoload :NetfilterGroup, 'dcmgr/models/netfilter_group'
108
- autoload :NetfilterRule, 'dcmgr/models/netfilter_rule'
98
+ autoload :SecurityGroup, 'dcmgr/models/security_group'
99
+ autoload :SecurityGroupRule, 'dcmgr/models/security_group_rule'
109
100
  autoload :InstanceSpec, 'dcmgr/models/instance_spec'
110
101
  autoload :InstanceNic, 'dcmgr/models/instance_nic'
111
102
  autoload :Network, 'dcmgr/models/network'
112
103
  autoload :IpLease, 'dcmgr/models/ip_lease'
113
- autoload :InstanceNetfilterGroup, 'dcmgr/models/instance_netfilter_group'
104
+ autoload :InstanceSecurityGroup, 'dcmgr/models/instance_security_group'
114
105
  autoload :SshKeyPair, 'dcmgr/models/ssh_key_pair'
115
106
  autoload :History, 'dcmgr/models/history'
116
107
  autoload :HostnameLease, 'dcmgr/models/hostname_lease'
117
108
  autoload :MacLease, 'dcmgr/models/mac_lease'
118
109
  autoload :VlanLease, 'dcmgr/models/vlan_lease'
119
110
  autoload :Quota, 'dcmgr/models/quota'
111
+ autoload :DhcpRange, 'dcmgr/models/dhcp_range'
112
+ autoload :PhysicalNetwork, 'dcmgr/models/physical_network'
120
113
  end
121
114
 
122
115
  module Endpoints
123
116
  autoload :CoreAPI, 'dcmgr/endpoints/core_api'
124
- autoload :Metadata, 'dcmgr/endpoints/metadata'
117
+ autoload :Ec2Metadata, 'dcmgr/endpoints/metadata'
125
118
  end
126
119
 
127
120
  module NodeModules
128
121
  autoload :StaCollector, 'dcmgr/node_modules/sta_collector'
122
+ autoload :StaTgtInitializer, 'dcmgr/node_modules/sta_tgt_initializer'
129
123
  autoload :HvaCollector, 'dcmgr/node_modules/hva_collector'
130
124
  autoload :InstanceHA, 'dcmgr/node_modules/instance_ha'
125
+ autoload :OpenFlowController, 'dcmgr/node_modules/openflow_controller'
131
126
  autoload :ServiceNetfilter, 'dcmgr/node_modules/service_netfilter'
127
+ autoload :ServiceOpenFlow, 'dcmgr/node_modules/service_openflow'
132
128
  autoload :InstanceMonitor, 'dcmgr/node_modules/instance_monitor'
133
- end
134
-
135
- module Stm
136
- autoload :VolumeContext, 'dcmgr/stm/volume_context'
137
- autoload :SnapshotContext, 'dcmgr/stm/snapshot_context'
138
- autoload :Instance, 'dcmgr/stm/instance'
129
+ autoload :Scheduler, 'dcmgr/node_modules/scheduler'
139
130
  end
140
131
 
141
132
  module Helpers
142
133
  autoload :CliHelper, 'dcmgr/helpers/cli_helper'
143
134
  autoload :NicHelper, 'dcmgr/helpers/nic_helper'
135
+ autoload :SnapshotStorageHelper, 'dcmgr/helpers/snapshot_storage_helper'
144
136
  end
145
137
 
146
138
  autoload :Tags, 'dcmgr/tags'
@@ -157,7 +149,7 @@ module Dcmgr
157
149
  autoload :Vlan, 'dcmgr/cli/vlan'
158
150
  autoload :Image, 'dcmgr/cli/image'
159
151
  autoload :KeyPair, 'dcmgr/cli/keypair'
160
- autoload :Group, 'dcmgr/cli/group'
152
+ autoload :SecurityGroup, 'dcmgr/cli/security_group'
161
153
  autoload :Spec, 'dcmgr/cli/spec'
162
154
  autoload :Tag, 'dcmgr/cli/tag'
163
155
  autoload :Quota, 'dcmgr/cli/quota'
@@ -165,6 +157,7 @@ module Dcmgr
165
157
 
166
158
  module Rpc
167
159
  autoload :HvaHandler, 'dcmgr/rpc/hva_handler'
160
+ autoload :StaHandler, 'dcmgr/rpc/sta_handler'
168
161
  autoload :KvmHelper, 'dcmgr/rpc/hva_handler'
169
162
  end
170
163
 
@@ -176,12 +169,96 @@ module Dcmgr
176
169
 
177
170
  module Drivers
178
171
  autoload :SnapshotStorage, 'dcmgr/drivers/snapshot_storage'
172
+ autoload :LocalStorage, 'dcmgr/drivers/local_storage'
179
173
  autoload :S3Storage, 'dcmgr/drivers/s3_storage'
180
174
  autoload :IIJGIOStorage, 'dcmgr/drivers/iijgio_storage'
181
175
  autoload :Hypervisor, 'dcmgr/drivers/hypervisor'
182
176
  autoload :Kvm , 'dcmgr/drivers/kvm'
183
177
  autoload :Lxc , 'dcmgr/drivers/lxc'
178
+ autoload :BackingStore, 'dcmgr/drivers/backing_store'
179
+ autoload :Zfs, 'dcmgr/drivers/zfs'
180
+ autoload :Raw, 'dcmgr/drivers/raw'
181
+ autoload :IscsiTarget, 'dcmgr/drivers/iscsi_target'
182
+ autoload :SunIscsi, 'dcmgr/drivers/sun_iscsi'
183
+ autoload :LinuxIscsi, 'dcmgr/drivers/linux_iscsi'
184
+ autoload :Comstar, 'dcmgr/drivers/comstar'
184
185
  end
185
186
 
186
187
  autoload :StorageService, 'dcmgr/storage_service'
188
+
189
+ require 'dcmgr/scheduler'
190
+ module Scheduler
191
+ module StorageNode
192
+ autoload :FindFirst, 'dcmgr/scheduler/storage_node/find_first'
193
+ autoload :LeastUsage, 'dcmgr/scheduler/storage_node/least_usage'
194
+ end
195
+ module HostNode
196
+ autoload :FindFirst, 'dcmgr/scheduler/host_node/find_first'
197
+ autoload :LeastUsage, 'dcmgr/scheduler/host_node/least_usage'
198
+ autoload :ExcludeSame, 'dcmgr/scheduler/host_node/exclude_same'
199
+ autoload :SpecifyNode, 'dcmgr/scheduler/host_node/specify_node'
200
+ end
201
+ module Network
202
+ autoload :FlatSingle, 'dcmgr/scheduler/network/flat_single'
203
+ autoload :NatOneToOne, 'dcmgr/scheduler/network/nat_one_to_one'
204
+ autoload :VifTemplate, 'dcmgr/scheduler/network/vif_template'
205
+ autoload :PerInstance, 'dcmgr/scheduler/network/per_instance'
206
+ end
207
+ end
208
+
209
+ require 'dcmgr/vnet'
210
+ module VNet
211
+ autoload :ControllerFactory, 'dcmgr/vnet/factories'
212
+ autoload :IsolatorFactory, 'dcmgr/vnet/factories'
213
+ autoload :TaskFactory, 'dcmgr/vnet/factories'
214
+ autoload :TaskManagerFactory, 'dcmgr/vnet/factories'
215
+
216
+ module Netfilter
217
+ autoload :NetfilterCache, 'dcmgr/vnet/netfilter/cache'
218
+ autoload :NetfilterController, 'dcmgr/vnet/netfilter/controller'
219
+ autoload :Chain, 'dcmgr/vnet/netfilter/chain'
220
+ autoload :IptablesChain, 'dcmgr/vnet/netfilter/chain'
221
+ autoload :EbtablesChain, 'dcmgr/vnet/netfilter/chain'
222
+ autoload :EbtablesRule, 'dcmgr/vnet/netfilter/ebtables_rule'
223
+ autoload :IptablesRule, 'dcmgr/vnet/netfilter/iptables_rule'
224
+ autoload :NetfilterTaskManager, 'dcmgr/vnet/netfilter/task_manager'
225
+ autoload :VNicProtocolTaskManager, 'dcmgr/vnet/netfilter/task_manager'
226
+ end
227
+
228
+ module Tasks
229
+ autoload :AcceptAllDNS, 'dcmgr/vnet/tasks/accept_all_dns'
230
+ autoload :AcceptArpBroadcast, 'dcmgr/vnet/tasks/accept_arp_broadcast'
231
+ autoload :AcceptARPFromFriends, 'dcmgr/vnet/tasks/accept_arp_from_friends'
232
+ autoload :AcceptARPFromGateway, 'dcmgr/vnet/tasks/accept_arp_from_gateway'
233
+ autoload :AcceptARPToHost, 'dcmgr/vnet/tasks/accept_arp_to_host'
234
+ autoload :AcceptIpFromFriends, 'dcmgr/vnet/tasks/accept_ip_from_friends'
235
+ autoload :AcceptIpFromGateway, 'dcmgr/vnet/tasks/accept_ip_from_gateway'
236
+ autoload :AcceptIpToAnywhere, 'dcmgr/vnet/tasks/accept_ip_to_anywhere'
237
+ autoload :AcceptRelatedEstablished, 'dcmgr/vnet/tasks/accept_related_established'
238
+ autoload :AcceptTcpRelatedEstablished, 'dcmgr/vnet/tasks/accept_related_established'
239
+ autoload :AcceptUdpEstablished, 'dcmgr/vnet/tasks/accept_related_established'
240
+ autoload :AcceptIcmpRelatedEstablished, 'dcmgr/vnet/tasks/accept_related_established'
241
+ autoload :AcceptWakameDHCPOnly, 'dcmgr/vnet/tasks/accept_wakame_dhcp_only'
242
+ autoload :AcceptWakameDNSOnly, 'dcmgr/vnet/tasks/accept_wakame_dns_only'
243
+ autoload :DebugIptables, 'dcmgr/vnet/tasks/debug_iptables'
244
+ autoload :DropArpForwarding, 'dcmgr/vnet/tasks/drop_arp_forwarding'
245
+ autoload :DropArpToHost, 'dcmgr/vnet/tasks/drop_arp_to_host'
246
+ autoload :DropIpFromAnywhere, 'dcmgr/vnet/tasks/drop_ip_from_anywhere'
247
+ autoload :DropIpSpoofing, 'dcmgr/vnet/tasks/drop_ip_spoofing'
248
+ autoload :DropMacSpoofing, 'dcmgr/vnet/tasks/drop_mac_spoofing'
249
+ autoload :ExcludeFromNat, 'dcmgr/vnet/tasks/exclude_from_nat'
250
+ autoload :ExcludeFromNatIpSet, 'dcmgr/vnet/tasks/exclude_from_nat'
251
+ autoload :SecurityGroup, 'dcmgr/vnet/tasks/security_group'
252
+ autoload :StaticNat, 'dcmgr/vnet/tasks/static_nat'
253
+ autoload :StaticNatLog, 'dcmgr/vnet/tasks/static_nat'
254
+ autoload :TranslateMetadataAddress, 'dcmgr/vnet/tasks/translate_metadata_address'
255
+ end
256
+
257
+ module Isolators
258
+ autoload :BySecurityGroup, 'dcmgr/vnet/isolators/by_securitygroup'
259
+ autoload :DummyIsolator, 'dcmgr/vnet/isolators/dummy'
260
+ end
261
+
262
+ end
263
+
187
264
  end
@@ -27,6 +27,40 @@ module Dcmgr::Cli
27
27
  def after_task
28
28
  end
29
29
  }
30
+
31
+ no_tasks {
32
+ class MapperDSL
33
+ attr_reader :defs
34
+
35
+ def initialize()
36
+ @defs = {}
37
+ end
38
+
39
+ def option(key, map_key=nil, &blk)
40
+ map_key ||= key
41
+ @defs[key]=proc { |h,v| h[map_key]=blk.call(v) }
42
+ end
43
+
44
+ def map(key, map_key)
45
+ @defs[key]=proc { |h, v| h[map_key] = v}
46
+ end
47
+ end
48
+
49
+ public
50
+ def optmap(h, &blk)
51
+ ret = {}
52
+ d = MapperDSL.new
53
+ blk.call(d)
54
+ h.each { |k, v|
55
+ if d.defs.has_key?(k.to_sym)
56
+ d.defs[k.to_sym].call(ret, v)
57
+ else
58
+ ret[k.to_sym] = v
59
+ end
60
+ }
61
+ ret
62
+ end
63
+ }
30
64
 
31
65
  def add(model,options)
32
66
  raise ArgumentError unless options.is_a? Hash
@@ -67,7 +101,6 @@ module Dcmgr::Cli
67
101
  fields_nonil.delete_if {|key,value| value.nil?}
68
102
 
69
103
  to_modify.set(fields_nonil)
70
- to_modify.updated_at = Time.now.utc.iso8601 if to_modify.with_timestamps?
71
104
  to_modify.save_changes
72
105
  end
73
106
  end
@@ -9,23 +9,25 @@ class Host < Base
9
9
  include Dcmgr::Models
10
10
 
11
11
  desc "add NODE_ID [options]", "Register a new host node"
12
- method_option :uuid, :type => :string, :aliases => "-u", :desc => "The UUID for the new host pool"
13
- #method_option :force, :type => :boolean, :aliases => "-f", :default=>false, :desc => "Force to create new entry"
14
- method_option :cpu_cores, :type => :numeric, :aliases => "-c", :default=>1, :desc => "Number of cpu cores to be offered"
15
- method_option :memory_size, :type => :numeric, :aliases => "-m", :default=>1024, :desc => "Amount of memory to be offered (in MB)"
16
- method_option :hypervisor, :type => :string, :aliases => "-p", :default=>'kvm', :desc => "The hypervisor name. [#{HostPool::SUPPORTED_HYPERVISOR.join(', ')}]"
17
- method_option :arch, :type => :string, :aliases => "-r", :default=>'x86_64', :desc => "The CPU architecture type. [#{HostPool::SUPPORTED_ARCH.join(', ')}]"
18
- 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 host node"
13
+ method_option :name, :type => :string, :size => 255, :desc => "The name for the new host node"
14
+ method_option :force, :type => :boolean, :default=>false, :desc => "Force new entry creation"
15
+ method_option :cpu_cores, :type => :numeric, :default=>1, :desc => "Number of cpu cores to be offered"
16
+ method_option :memory_size, :type => :numeric, :default=>1024, :desc => "Amount of memory to be offered (in MB)"
17
+ method_option :hypervisor, :type => :string, :default=>'kvm', :desc => "The hypervisor name. [#{HostNode::SUPPORTED_HYPERVISOR.join(', ')}]"
18
+ method_option :arch, :type => :string, :default=>'x86_64', :desc => "The CPU architecture type. [#{HostNode::SUPPORTED_ARCH.join(', ')}]"
19
+ method_option :account_id, :type => :string, :default=>'a-shpoolxx', :desc => "The account ID to own this"
19
20
  def add(node_id)
20
21
  UnknownUUIDError.raise(options[:account_id]) if Account[options[:account_id]].nil?
21
- UnsupportedArchError.raise(options[:arch]) unless HostPool::SUPPORTED_ARCH.member?(options[:arch])
22
- UnsupportedHypervisorError.raise(options[:hypervisor]) unless HostPool::SUPPORTED_HYPERVISOR.member?(options[:hypervisor])
22
+ UnsupportedArchError.raise(options[:arch]) unless HostNode::SUPPORTED_ARCH.member?(options[:arch])
23
+ UnsupportedHypervisorError.raise(options[:hypervisor]) unless HostNode::SUPPORTED_HYPERVISOR.member?(options[:hypervisor])
23
24
 
24
- if (options[:force] == false && Isono::Models::NodeState.filter(:node_id=>node_id).first == nil)
25
+ unless (options[:force] || Isono::Models::NodeState.find(:node_id=>node_id))
25
26
  abort("Node ID is not registered yet: #{node_id}")
26
27
  end
27
28
 
28
29
  fields = {
30
+ :name=>options[:name],
29
31
  :node_id=>node_id,
30
32
  :offering_cpu_cores=>options[:cpu_cores],
31
33
  :offering_memory_size=>options[:memory_size],
@@ -34,35 +36,37 @@ class Host < Base
34
36
  :account_id=>options[:account_id],
35
37
  }
36
38
  fields.merge!({:uuid => options[:uuid]}) unless options[:uuid].nil?
37
- puts super(HostPool,fields)
39
+ puts super(HostNode,fields)
38
40
  end
39
41
 
40
42
  desc "modify UUID [options]", "Modify a registered host node"
41
- method_option :cpu_cores, :type => :numeric, :aliases => "-c", :desc => "Number of cpu cores to be offered"
42
- method_option :account_id, :type => :string, :aliases => "-a", :desc => "The account ID to own this"
43
- method_option :memory_size, :type => :numeric, :aliases => "-m", :desc => "Amount of memory to be offered (in MB)"
44
- method_option :hypervisor, :type => :string, :aliases => "-p", :desc => "The hypervisor name. [#{HostPool::SUPPORTED_HYPERVISOR.join(', ')}]"
43
+ method_option :name, :type => :string, :size => 255, :desc => "The name for the new host node"
44
+ method_option :cpu_cores, :type => :numeric, :desc => "Number of cpu cores to be offered"
45
+ method_option :account_id, :type => :string, :desc => "The account ID to own this"
46
+ method_option :memory_size, :type => :numeric, :desc => "Amount of memory to be offered (in MB)"
47
+ method_option :hypervisor, :type => :string, :desc => "The hypervisor name. [#{HostNode::SUPPORTED_HYPERVISOR.join(', ')}]"
45
48
  def modify(uuid)
46
49
  UnknownUUIDError.raise(options[:account_id]) if options[:account_id] && Account[options[:account_id]].nil?
47
- UnsupportedHypervisorError.raise(options[:hypervisor]) unless options[:hypervisor].nil? || HostPool::SUPPORTED_HYPERVISOR.member?(options[:hypervisor])
50
+ UnsupportedHypervisorError.raise(options[:hypervisor]) unless options[:hypervisor].nil? || HostNode::SUPPORTED_HYPERVISOR.member?(options[:hypervisor])
48
51
  fields = {
52
+ :name=>options[:name],
49
53
  :offering_memory_size=>options[:memory_size],
50
54
  :offering_cpu_cores=>options[:cpu_cores],
51
55
  :account_id=>options[:account_id],
52
56
  :hypervisor=>options[:hypervisor]
53
57
  }
54
- super(HostPool,uuid,fields)
58
+ super(HostNode,uuid,fields)
55
59
  end
56
60
 
57
61
  desc "del UUID", "Deregister a host node"
58
62
  def del(uuid)
59
- super(HostPool,uuid)
63
+ super(HostNode,uuid)
60
64
  end
61
65
 
62
66
  desc "show [UUID]", "Show list of host nodes and details"
63
67
  def show(uuid=nil)
64
68
  if uuid
65
- host = HostPool[uuid]
69
+ host = HostNode[uuid] || UnknownUUIDError.raise(uuid)
66
70
  puts ERB.new(<<__END, nil, '-').result(binding)
67
71
  Host UUID:
68
72
  <%= host.canonical_uuid %>
@@ -77,7 +81,7 @@ Hypervisor:
77
81
  __END
78
82
  else
79
83
  cond = {}
80
- all = HostPool.filter(cond).all
84
+ all = HostNode.filter(cond).all
81
85
  puts ERB.new(<<__END, nil, '-').result(binding)
82
86
  <%- all.each { |row| -%>
83
87
  <%= "%-15s %-20s %-10s" % [row.canonical_uuid, row.node_id, row.status] %>
@@ -10,15 +10,16 @@ module Dcmgr::Cli
10
10
  namespace :add
11
11
 
12
12
  desc "local IMAGE_LOCATION [options]", "Register local store machine image"
13
- method_option :uuid, :type => :string, :aliases => "-u", :desc => "The UUID for the new machine image"
14
- method_option :account_id, :type => :string, :aliases => "-a", :required => true, :desc => "The UUID of the account that this machine image belongs to"
15
- method_option :arch, :type => :string, :default => 'x86_64', :aliases => "-r", :desc => "The architecture for the new machine image. [#{M::HostPool::SUPPORTED_ARCH.join(', ')}]"
16
- method_option :is_public, :type => :boolean, :aliases => "-p", :default => false, :desc => "A flag that determines whether the new machine image is public or not"
17
- method_option :description, :type => :string, :aliases => "-d", :desc => "An arbitrary description of the new machine image"
18
- method_option :state, :type => :string, :aliases => "-s", :default => "init", :desc => "The state for the new machine image"
13
+ method_option :uuid, :type => :string, :desc => "The UUID for the new machine image"
14
+ method_option :account_id, :type => :string, :required => true, :desc => "The UUID of the account that this machine image belongs to"
15
+ method_option :arch, :type => :string, :default => 'x86_64', :desc => "The architecture for the new machine image. [#{M::HostNode::SUPPORTED_ARCH.join(', ')}]"
16
+ method_option :is_public, :type => :boolean, :default => false, :desc => "A flag that determines whether the new machine image is public or not"
17
+ method_option :md5sum, :type => :string, :required => true, :desc => "The md5 checksum of the image you are registering."
18
+ method_option :description, :type => :string, :desc => "An arbitrary description of the new machine image"
19
+ #method_option :state, :type => :string, :default => "init", :desc => "The state for the new machine image"
19
20
  def local(location)
20
21
  UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
21
- UnsupportedArchError.raise(options[:arch]) unless M::HostPool::SUPPORTED_ARCH.member?(options[:arch])
22
+ UnsupportedArchError.raise(options[:arch]) unless M::HostNode::SUPPORTED_ARCH.member?(options[:arch])
22
23
 
23
24
  full_path = File.expand_path(location)
24
25
  File.exists?(full_path) || Error.raise("File not found: #{full_path}",100)
@@ -33,15 +34,16 @@ module Dcmgr::Cli
33
34
  end
34
35
 
35
36
  desc "volume snapshot_id [options]", "Register volume store machine image."
36
- method_option :uuid, :type => :string, :aliases => "-u", :desc => "The UUID for the new machine image."
37
- method_option :account_id, :type => :string, :aliases => "-a", :required => true, :desc => "The UUID of the account that this machine image belongs to."
38
- method_option :arch, :type => :string, :default => 'x86_64', :aliases => "-r", :desc => "The architecture for the new machine image. [#{M::HostPool::SUPPORTED_ARCH.join(', ')}]"
39
- method_option :is_public, :type => :boolean, :aliases => "-p", :default => false, :desc => "A flag that determines whether the new machine image is public or not."
40
- method_option :description, :type => :string, :aliases => "-d", :desc => "An arbitrary description of the new machine image"
41
- method_option :state, :type => :string, :aliases => "-s", :default => "init", :desc => "The state for the new machine image"
37
+ method_option :uuid, :type => :string, :desc => "The UUID for the new machine image."
38
+ method_option :account_id, :type => :string, :required => true, :desc => "The UUID of the account that this machine image belongs to."
39
+ method_option :arch, :type => :string, :default => 'x86_64', :desc => "The architecture for the new machine image. [#{M::HostNode::SUPPORTED_ARCH.join(', ')}]"
40
+ method_option :is_public, :type => :boolean, :default => false, :desc => "A flag that determines whether the new machine image is public or not."
41
+ method_option :md5sum, :type => :string, :required => true, :desc => "The md5 checksum of the image you are registering."
42
+ method_option :description, :type => :string, :desc => "An arbitrary description of the new machine image"
43
+ #method_option :state, :type => :string, :default => "init", :desc => "The state for the new machine image"
42
44
  def volume(snapshot_id)
43
45
  UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
44
- UnsupportedArchError.raise(options[:arch]) unless M::HostPool::SUPPORTED_ARCH.member?(options[:arch])
46
+ UnsupportedArchError.raise(options[:arch]) unless M::HostNode::SUPPORTED_ARCH.member?(options[:arch])
45
47
  UnknownUUIDError.raise(snapshot_id) if M::VolumeSnapshot[snapshot_id].nil?
46
48
  #TODO: Check if :state is a valid state
47
49
  fields = options.dup
@@ -61,8 +63,8 @@ module Dcmgr::Cli
61
63
  register AddOperation, 'add', "add IMAGE_TYPE [options]", "Add image metadata [#{AddOperation.tasks.keys.join(', ')}]"
62
64
 
63
65
  desc "modify UUID [options]", "Modify a registered machine image"
64
- method_option :description, :type => :string, :aliases => "-d", :desc => "An arbitrary description of the machine image"
65
- method_option :state, :type => :string, :aliases => "-s", :default => "init", :desc => "The state for the machine image"
66
+ method_option :description, :type => :string, :desc => "An arbitrary description of the machine image"
67
+ method_option :state, :type => :string, :default => "init", :desc => "The state for the machine image"
66
68
  def modify(uuid)
67
69
  #TODO: Check if state is valid here too
68
70
  super(M::Image,uuid,options)
@@ -77,15 +79,17 @@ module Dcmgr::Cli
77
79
  desc "show [IMAGE_ID]", "Show list of machine image and details"
78
80
  def show(uuid=nil)
79
81
  if uuid
80
- img = M::Image[uuid]
82
+ img = M::Image[uuid] || UnknownUUIDError.raise(uuid)
81
83
  print ERB.new(<<__END, nil, '-').result(binding)
82
84
  UUID:
83
85
  <%= img.canonical_uuid %>
84
86
  Boot Type:
85
- <%= img.boot_dev_type %>
87
+ <%= img.boot_dev_type == M::Image::BOOT_DEV_LOCAL ? 'local' : 'volume'%>
86
88
  Arch:
87
89
  <%= img.arch %>
88
90
  <%- if img.description -%>
91
+ MD5 Sum:
92
+ <%= img.md5sum %>
89
93
  Description:
90
94
  <%= img.description %>
91
95
  <%- end -%>
@@ -93,16 +97,31 @@ Is Public:
93
97
  <%= img.is_public %>
94
98
  State:
95
99
  <%= img.state %>
100
+ Features:
101
+ <%= img.features %>
96
102
  __END
97
103
  else
98
104
  cond = {}
99
105
  imgs = M::Image.filter(cond).all
100
106
  print ERB.new(<<__END, nil, '-').result(binding)
101
107
  <%- imgs.each { |row| -%>
102
- <%= "%-20s %-15s %-15s" % [row.canonical_uuid, row.boot_dev_type, row.arch] %>
108
+ <%= row.canonical_uuid %>\t<%= row.boot_dev_type == M::Image::BOOT_DEV_LOCAL ? 'local' : 'volume'%>\t<%= row.arch %>
103
109
  <%- } -%>
104
110
  __END
105
111
  end
106
112
  end
113
+
114
+ desc "features IMAGE_ID", "Set features attribute to the image"
115
+ method_option :virtio, :type => :boolean, :desc => "Virtio ready image."
116
+ def features(uuid)
117
+ img = M::Image[uuid]
118
+ UnknownUUIDError.raise(uuid) if img.nil?
119
+
120
+ if options[:virtio]
121
+ img.set_feature(:virtio, options[:virtio])
122
+ end
123
+ img.save_changes
124
+ end
125
+
107
126
  end
108
127
  end