wakame-vdc-agents 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/hva +15 -5
- data/bin/nsa +15 -5
- data/bin/sta +9 -222
- data/config/db/migrations/0001_v1110_origin.rb +446 -0
- data/config/hva.conf.example +19 -11
- data/config/nsa.conf.example +1 -1
- 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
- metadata +105 -68
- 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/cli/keypair.rb
CHANGED
@@ -4,18 +4,19 @@ module Dcmgr::Cli
|
|
4
4
|
class KeyPair < Base
|
5
5
|
namespace :keypair
|
6
6
|
M = Dcmgr::Models
|
7
|
+
include Dcmgr::Helpers::CliHelper
|
7
8
|
|
8
9
|
desc "add [options]", "Register a new key pair."
|
9
|
-
method_option :uuid, :type => :string, :
|
10
|
-
method_option :account_id, :type => :string, :
|
11
|
-
method_option :
|
12
|
-
method_option :
|
13
|
-
method_option :
|
10
|
+
method_option :uuid, :type => :string, :desc => "The UUID for the new key pair"
|
11
|
+
method_option :account_id, :type => :string, :desc => "The UUID of the account this key pair belongs to", :required => true
|
12
|
+
method_option :public_key, :type => :string, :desc => "The path to the public key", :required => true
|
13
|
+
method_option :private_key, :type => :string, :desc => "The path to the private key"
|
14
|
+
method_option :description, :type => :string, :desc => "Description for this key pair"
|
14
15
|
def add
|
15
16
|
UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
|
16
17
|
private_key_path = File.expand_path(options[:private_key])
|
17
18
|
public_key_path = File.expand_path(options[:public_key])
|
18
|
-
Error.raise "Private key file doesn't exist",100 unless File.exists?(private_key_path)
|
19
|
+
Error.raise "Private key file doesn't exist",100 unless File.exists?(private_key_path) || options[:private_key]
|
19
20
|
Error.raise "Public key file doesn't exist",100 unless File.exists?(public_key_path)
|
20
21
|
|
21
22
|
fields = options.dup
|
@@ -25,14 +26,15 @@ module Dcmgr::Cli
|
|
25
26
|
fields[:private_key] = File.open(private_key_path) {|f| f.readlines.map.join}
|
26
27
|
|
27
28
|
#Generate the fingerprint from the public key file
|
28
|
-
|
29
|
+
res = sh("ssh-keygen -lf #{options[:public_key]}")
|
30
|
+
fields[:finger_print] = res[:stdout].split(' ')[1]
|
29
31
|
|
30
32
|
puts super(M::SshKeyPair,fields)
|
31
33
|
end
|
32
34
|
|
33
35
|
desc "modify UUID [options]", "Modify an existing key pair"
|
34
|
-
method_option :account_id, :type => :string, :
|
35
|
-
method_option :
|
36
|
+
method_option :account_id, :type => :string, :desc => "The UUID of the account this key pair belongs to"
|
37
|
+
method_option :description, :type => :string, :desc => "Description for this key pair"
|
36
38
|
def modify(uuid)
|
37
39
|
UnknownUUIDError.raise(options[:account_id]) if options[:account_id] && M::Account[options[:account_id]].nil?
|
38
40
|
super(M::SshKeyPair,uuid,options)
|
@@ -52,17 +54,19 @@ Keypair UUID:
|
|
52
54
|
<%= keypair.canonical_uuid %>
|
53
55
|
Account id:
|
54
56
|
<%= keypair.account_id %>
|
55
|
-
Name:
|
56
|
-
<%= keypair.name%>
|
57
57
|
Finger print:
|
58
58
|
<%= keypair.finger_print %>
|
59
59
|
Public Key:
|
60
60
|
<%= keypair.public_key%>
|
61
|
+
<%- if keypair.description -%>
|
62
|
+
Description:
|
63
|
+
<%= keypair.description %>
|
64
|
+
<%- end -%>
|
61
65
|
__END
|
62
66
|
else
|
63
67
|
puts ERB.new(<<__END, nil, '-').result(binding)
|
64
68
|
<%- M::SshKeyPair.each { |row| -%>
|
65
|
-
<%= row.canonical_uuid %>\t<%= row.account_id %>\t<%= row.
|
69
|
+
<%= row.canonical_uuid %>\t<%= row.account_id %>\t<%= row.finger_print %>
|
66
70
|
<%- } -%>
|
67
71
|
__END
|
68
72
|
end
|
data/lib/dcmgr/cli/network.rb
CHANGED
@@ -6,42 +6,65 @@ module Dcmgr::Cli
|
|
6
6
|
class Network < Base
|
7
7
|
namespace :network
|
8
8
|
M=Dcmgr::Models
|
9
|
+
|
10
|
+
no_tasks {
|
11
|
+
def validate_ipv4_range
|
12
|
+
@network_addr = IPAddress::IPv4.new("#{options[:ipv4_network]}/#{options[:prefix]}").network
|
13
|
+
if options[:ipv4_gw] && !@network_addr.include?(IPAddress::IPv4.new(options[:ipv4_gw]))
|
14
|
+
Error.raise("ipv4_gw #{options[:ipv4_gw]} is out of range from network address: #{@network_addr}")
|
15
|
+
end
|
16
|
+
# DHCP IP address has to be in same IP network.
|
17
|
+
if options[:dhcp] && !@network_addr.include?(IPAddress::IPv4.new(options[:dhcp]))
|
18
|
+
Error.raise("dhcp server address #{options[:dhcp]} is out of range from network address: #{@network_addr}")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
private :validate_ipv4_range
|
22
|
+
|
23
|
+
def map_network_params
|
24
|
+
optmap(options) { |c|
|
25
|
+
c.option(:ipv4_network) {
|
26
|
+
@network_addr.to_s
|
27
|
+
}
|
28
|
+
c.map(:domain, :domain_name)
|
29
|
+
c.map(:dhcp, :dhcp_server)
|
30
|
+
c.map(:dns, :dns_server)
|
31
|
+
c.map(:metadata, :metadata_server)
|
32
|
+
c.map(:metadata_port, :metadata_server_port)
|
33
|
+
c.option(:vlan_id, :vlan_lease_id) {
|
34
|
+
@vlan_pk
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
private :map_network_params
|
39
|
+
}
|
9
40
|
|
10
41
|
desc "add [options]", "Register a new network entry"
|
11
|
-
method_option :uuid, :type => :string, :
|
12
|
-
method_option :
|
13
|
-
method_option :
|
14
|
-
method_option :
|
15
|
-
method_option :
|
16
|
-
method_option :
|
17
|
-
method_option :
|
18
|
-
method_option :
|
19
|
-
method_option :
|
20
|
-
method_option :
|
21
|
-
method_option :
|
22
|
-
method_option :
|
42
|
+
method_option :uuid, :type => :string, :desc => "UUID of the network"
|
43
|
+
method_option :ipv4_network, :type => :string, :required=>true, :desc => "IPv4 network address"
|
44
|
+
method_option :ipv4_gw, :type => :string, :desc => "Gateway address for IPv4 network"
|
45
|
+
method_option :prefix, :type => :numeric, :required => true, :desc => "IP network mask size (1 < prefix < 32)"
|
46
|
+
method_option :domain, :type => :string, :desc => "DNS domain name of the network"
|
47
|
+
method_option :dns, :type => :string, :desc => "IP address for DNS server of the network"
|
48
|
+
method_option :dhcp, :type => :string, :desc => "IP address for DHCP server of the network"
|
49
|
+
method_option :metadata, :type => :string, :desc => "IP address for metadata server of the network"
|
50
|
+
method_option :metadata_port, :type => :string, :desc => "Port for the metadata server of the network"
|
51
|
+
method_option :bandwidth, :type => :numeric, :desc => "The maximum bandwidth for the network in Mbit/s"
|
52
|
+
method_option :vlan_id, :type => :numeric, :default=>0, :desc => "Tag VLAN (802.1Q) ID of the network. 0 is for no VLAN network"
|
53
|
+
method_option :link_interface, :type => :string, :desc => "Link interface name from virtual interfaces"
|
54
|
+
method_option :description, :type => :string, :desc => "Description for the network"
|
55
|
+
method_option :account_id, :type => :string, :default=>'a-shpoolxx', :required => true, :desc => "The account ID to own this"
|
56
|
+
method_option :metric, :type => :numeric, :default=>100, :desc => "Routing priority order of this network segment"
|
23
57
|
def add
|
24
|
-
vlan_pk = if options[:vlan_id].to_i > 0
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
:dns_server => options[:dns],
|
35
|
-
:domain_name => options[:domain],
|
36
|
-
:dhcp_server => options[:dhcp],
|
37
|
-
:metadata_server => options[:metadata],
|
38
|
-
:metadata_server_port => options[:metadata_port],
|
39
|
-
:description => options[:description],
|
40
|
-
:account_id => options[:account_id],
|
41
|
-
:bandwidth => options[:bandwidth],
|
42
|
-
:vlan_lease_id => vlan_pk,
|
43
|
-
}
|
44
|
-
fields.merge!({:uuid => options[:uuid]}) unless options[:uuid].nil?
|
58
|
+
@vlan_pk = if options[:vlan_id].to_i > 0
|
59
|
+
vlan = M::VlanLease.find(:tag_id=>options[:vlan_id]) || Error.raise("Invalid or Unknown VLAN ID: #{options[:vlan_id]}", 100)
|
60
|
+
vlan.id
|
61
|
+
else
|
62
|
+
0
|
63
|
+
end
|
64
|
+
|
65
|
+
validate_ipv4_range
|
66
|
+
|
67
|
+
fields = map_network_params
|
45
68
|
|
46
69
|
puts super(M::Network,fields)
|
47
70
|
end
|
@@ -52,44 +75,37 @@ class Network < Base
|
|
52
75
|
end
|
53
76
|
|
54
77
|
desc "modify UUID [options]", "Update network information"
|
55
|
-
method_option :
|
56
|
-
method_option :
|
57
|
-
method_option :
|
58
|
-
method_option :
|
59
|
-
method_option :
|
60
|
-
method_option :
|
61
|
-
method_option :
|
62
|
-
method_option :
|
63
|
-
method_option :
|
64
|
-
method_option :
|
65
|
-
method_option :
|
78
|
+
method_option :ipv4_network, :type => :string, :required=>true, :desc => "IPv4 network address"
|
79
|
+
method_option :ipv4_gw, :type => :string, :desc => "Gateway address for IPv4 network"
|
80
|
+
method_option :prefix, :type => :numeric, :desc => "IP network mask size (1 < prefix < 32)"
|
81
|
+
method_option :domain, :type => :string, :desc => "DNS domain name of the network"
|
82
|
+
method_option :dns, :type => :string, :desc => "IP address for DNS server of the network"
|
83
|
+
method_option :dhcp, :type => :string, :desc => "IP address for DHCP server of the network"
|
84
|
+
method_option :metadata, :type => :string, :desc => "IP address for metadata server of the network"
|
85
|
+
method_option :metadata_port, :type => :string, :desc => "Port for the metadata server of the network"
|
86
|
+
method_option :vlan_id, :type => :numeric, :desc => "Tag VLAN (802.1Q) ID of the network. 0 is for no VLAN network"
|
87
|
+
method_option :link_interface, :type => :string, :desc => "Link interface name from virtual interfaces"
|
88
|
+
method_option :bandwidth, :type => :numeric, :desc => "The maximum bandwidth for the network in Mbit/s"
|
89
|
+
method_option :description, :type => :string, :desc => "Description for the network"
|
90
|
+
method_option :account_id, :type => :string, :desc => "The account ID to own this"
|
66
91
|
def modify(uuid)
|
67
|
-
vlan_pk = if options[:vlan_id].to_i > 0
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
92
|
+
@vlan_pk = if options[:vlan_id].to_i > 0
|
93
|
+
vlan = M::VlanLease.find(:tag_id=>options[:vlan_id]) || Error.raise("Invalid or Unknown VLAN ID: #{options[:vlan_id]}", 100)
|
94
|
+
vlan.id
|
95
|
+
else
|
96
|
+
0
|
97
|
+
end
|
98
|
+
|
99
|
+
validate_ipv4_range
|
100
|
+
|
101
|
+
fields = map_network_params
|
73
102
|
|
74
|
-
fields = {
|
75
|
-
:ipv4_gw => options[:ipv4_gw],
|
76
|
-
:prefix => options[:prefix],
|
77
|
-
:dns_server => options[:dns],
|
78
|
-
:domain_name => options[:domain],
|
79
|
-
:dhcp_server => options[:dhcp],
|
80
|
-
:metadata_server => options[:metadata],
|
81
|
-
:metadata_server_port => options[:metadata_port],
|
82
|
-
:description => options[:description],
|
83
|
-
:account_id => options[:account_id],
|
84
|
-
:bandwidth => options[:bandwidth],
|
85
|
-
:vlan_lease_id => vlan_pk,
|
86
|
-
}
|
87
103
|
super(M::Network,uuid,fields)
|
88
104
|
end
|
89
105
|
|
90
106
|
desc "nat UUID [options]", "Set or clear nat mapping for a network"
|
91
|
-
method_option :outside_network_id, :type => :string, :
|
92
|
-
method_option :clear, :type => :boolean, :
|
107
|
+
method_option :outside_network_id, :type => :string, :desc => "The network that this network will be natted to"
|
108
|
+
method_option :clear, :type => :boolean, :desc => "Clears a previously natted network"
|
93
109
|
def nat(uuid)
|
94
110
|
in_nw = M::Network[uuid] || Error.raise("Unknown network UUID: #{uuid}", 100)
|
95
111
|
ex_nw = M::Network[options[:outside_network_id]] || Error.raise("Unknown network UUID: #{uuid}", 100) unless options[:outside_network_id].nil?
|
@@ -104,21 +120,21 @@ class Network < Base
|
|
104
120
|
end
|
105
121
|
|
106
122
|
desc "show [UUID] [options]", "Show network(s)"
|
107
|
-
method_option :vlan_id, :type => :numeric, :
|
108
|
-
method_option :account_id, :type => :string, :
|
123
|
+
method_option :vlan_id, :type => :numeric, :desc => "Show networks in the VLAN ID"
|
124
|
+
method_option :account_id, :type => :string, :desc => "Show networks with the account"
|
109
125
|
def show(uuid=nil)
|
110
126
|
if uuid
|
111
|
-
nw = M::Network[uuid] ||
|
127
|
+
nw = M::Network[uuid] || UnknownUUIDError.raise(uuid)
|
112
128
|
puts ERB.new(<<__END, nil, '-').result(binding)
|
113
129
|
Network UUID:
|
114
130
|
<%= nw.canonical_uuid %>
|
115
131
|
Tag VLAN:
|
116
132
|
<%= nw.vlan_lease_id == 0 ? 'none' : nw.vlan_lease.tag_id %>
|
117
133
|
IPv4:
|
118
|
-
Network address: <%= nw.
|
134
|
+
Network address: <%= nw.ipv4_ipaddress %>/<%= nw.prefix %>
|
119
135
|
Gateway address: <%= nw.ipv4_gw %>
|
120
136
|
<%- if nw.nat_network_id -%>
|
121
|
-
Outside NAT network address: <%= nw.nat_network.
|
137
|
+
Outside NAT network address: <%= nw.nat_network.ipv4_ipaddress %>/<%= nw.nat_network.prefix %> (<%= nw.nat_network.canonical_uuid %>)
|
122
138
|
<%- end -%>
|
123
139
|
DHCP Information:
|
124
140
|
DHCP Server: <%= nw.dhcp_server %>
|
@@ -148,7 +164,7 @@ __END
|
|
148
164
|
nw = M::Network.filter(cond).all
|
149
165
|
puts ERB.new(<<__END, nil, '-').result(binding)
|
150
166
|
<%- nw.each { |row| -%>
|
151
|
-
<%= row.canonical_uuid %>\t<%= row.
|
167
|
+
<%= row.canonical_uuid %>\t<%= row.ipv4_ipaddress %>/<%= row.prefix %>\t<%= (row.vlan_lease && row.vlan_lease.tag_id) %>
|
152
168
|
<%- } -%>
|
153
169
|
__END
|
154
170
|
end
|
@@ -166,19 +182,19 @@ __END
|
|
166
182
|
end
|
167
183
|
|
168
184
|
desc "reserve UUID", "Add reserved IP to the network"
|
169
|
-
method_option :ipv4, :type => :string, :
|
185
|
+
method_option :ipv4, :type => :string, :required => true, :desc => "The ip address to reserve"
|
170
186
|
def reserve(uuid)
|
171
187
|
nw = M::Network[uuid] || UnknownUUIDError.raise(uuid)
|
172
|
-
|
173
|
-
if nw.
|
188
|
+
|
189
|
+
if nw.include?(IPAddress(options[:ipv4]))
|
174
190
|
nw.ip_lease_dataset.add_reserved(options[:ipv4])
|
175
191
|
else
|
176
|
-
Error.raise("IP address is out of range: #{options[:ipv4]} => #{nw.
|
192
|
+
Error.raise("IP address is out of range: #{options[:ipv4]} => #{nw.ipv4_ipaddress}/#{nw.prefix}",100)
|
177
193
|
end
|
178
194
|
end
|
179
195
|
|
180
196
|
desc "release UUID", "Release a reserved IP from the network"
|
181
|
-
method_option :ipv4, :type => :string, :
|
197
|
+
method_option :ipv4, :type => :string, :required => true, :desc => "The ip address to release"
|
182
198
|
def release(uuid)
|
183
199
|
nw = M::Network[uuid] || UnknownUUIDError.raise(uuid)
|
184
200
|
|
@@ -187,12 +203,104 @@ __END
|
|
187
203
|
end
|
188
204
|
end
|
189
205
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
206
|
+
desc "forward UUID PHYSICAL", "Set forward interface for network"
|
207
|
+
def forward(uuid, phynet)
|
208
|
+
nw = M::Network[uuid] || UnknownUUIDError.raise(uuid)
|
209
|
+
phy = M::PhysicalNetwork.find(:name=>phynet) || Error.raise("Unknown physical network: #{phynet}")
|
210
|
+
nw.physical_network = phy
|
211
|
+
nw.save
|
212
|
+
end
|
213
|
+
|
214
|
+
class PhyOps < Base
|
215
|
+
namespace :phy
|
216
|
+
M=Dcmgr::Models
|
217
|
+
|
218
|
+
desc "add NAME [options]", "Add new physical network"
|
219
|
+
method_option :null, :type => :boolean, :desc => "Do not attach to any physical interfaces"
|
220
|
+
method_option :interface, :type => :string, :desc => "Physical interface name on host nodes"
|
221
|
+
method_option :description, :type => :string, :desc => "Description for the physical network"
|
222
|
+
def add(name)
|
223
|
+
M::PhysicalNetwork.find(:name=>name) && Error.raise("Duplicate physical network name: #{name}", 100)
|
224
|
+
phy = options[:null] ? nil : (options[:interface] || name)
|
225
|
+
|
226
|
+
fields={
|
227
|
+
:name=>name,
|
228
|
+
:interface=>phy,
|
229
|
+
:description=>options[:description],
|
230
|
+
}
|
231
|
+
M::PhysicalNetwork.create(fields)
|
194
232
|
end
|
195
|
-
}
|
196
233
|
|
234
|
+
desc "modify NAME [options]", "Modify physical network parameters"
|
235
|
+
method_option :null, :type => :boolean, :desc => "Do not attach to any physical interfaces"
|
236
|
+
method_option :interface, :type => :string, :desc => "Physical interface name on host nodes"
|
237
|
+
method_option :description, :type => :string, :desc => "Description for the physical network"
|
238
|
+
def modify(name)
|
239
|
+
phy = M::PhysicalNetwork.find(:name=>name) || Error.raise("Unknown physical network: #{name}", 100)
|
240
|
+
phy = options[:null] ? nil : options[:interface]
|
241
|
+
|
242
|
+
phy.update({
|
243
|
+
:interface=>phy,
|
244
|
+
:description=>options[:description],
|
245
|
+
})
|
246
|
+
end
|
247
|
+
|
248
|
+
desc "del NAME [options]", "Delete physical network"
|
249
|
+
def del(name)
|
250
|
+
phy = M::PhysicalNetwork.find(:name=>name) || Error.raise("Unknown physical network: #{name}", 100)
|
251
|
+
phy.destroy
|
252
|
+
end
|
253
|
+
|
254
|
+
desc "show [NAME]", "Show/List physical network"
|
255
|
+
def show(name=nil)
|
256
|
+
if name
|
257
|
+
phy = M::PhysicalNetwork.find(:name=>name) || Error.raise("Unknown physical network: #{name}", 100)
|
258
|
+
print ERB.new(<<__END, nil, '-').result(binding)
|
259
|
+
Physical Network: <%= phy.name %>
|
260
|
+
Forwarding Interface: <%= phy.interface.nil? ? 'none': phy.interface %>
|
261
|
+
<%- if phy.description -%>
|
262
|
+
Description:
|
263
|
+
<%= phy.description %>
|
264
|
+
<%- end -%>
|
265
|
+
__END
|
266
|
+
else
|
267
|
+
print ERB.new(<<__END, nil, '-').result(binding)
|
268
|
+
<%- M::PhysicalNetwork.order(:id).all.each { |l| -%>
|
269
|
+
<%= "%-20s %-15s" % [l.name, l.interface] %>
|
270
|
+
<%- } -%>
|
271
|
+
__END
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
protected
|
276
|
+
def self.basename
|
277
|
+
"vdc-manage #{Network.namespace} #{self.namespace}"
|
278
|
+
end
|
279
|
+
end
|
280
|
+
register PhyOps, 'phy', "phy [options]", "Maintain physical network"
|
281
|
+
|
282
|
+
class DhcpOps < Base
|
283
|
+
namespace :dhcp
|
284
|
+
M=Dcmgr::Models
|
285
|
+
|
286
|
+
desc "addrange UUID ADDRESS_BEGIN ADDRESS_END", "Add dynamic IP address range to the network"
|
287
|
+
def addrange(uuid, range_begin, range_end)
|
288
|
+
nw = M::Network[uuid] || UnknownUUIDEntry.raise
|
289
|
+
nw.add_ipv4_dynamic_range(range_begin, range_end)
|
290
|
+
end
|
291
|
+
|
292
|
+
desc "delrange UUID ADDRESS_BEGIN ADDRESS_END", "Delete dynamic IP address range from the network"
|
293
|
+
def delrange(uuid, range_begin, range_end)
|
294
|
+
nw = M::Network[uuid] || UnknownUUIDEntry.raise
|
295
|
+
nw.del_ipv4_dynamic_range(range_begin, range_end)
|
296
|
+
end
|
297
|
+
|
298
|
+
protected
|
299
|
+
def self.basename
|
300
|
+
"vdc-manage #{Network.namespace} #{self.namespace}"
|
301
|
+
end
|
302
|
+
end
|
303
|
+
register DhcpOps, 'dhcp', "dhcp [options]", "Maintain dhcp parameters"
|
304
|
+
|
197
305
|
end
|
198
306
|
end
|
data/lib/dcmgr/cli/quota.rb
CHANGED
@@ -6,8 +6,8 @@ module Dcmgr::Cli
|
|
6
6
|
M = Dcmgr::Models
|
7
7
|
|
8
8
|
desc "modify ACCOUNT_UUID [options]", "Modify the quota settings for an account"
|
9
|
-
method_option :weight, :type => :numeric, :
|
10
|
-
method_option :size, :type => :numeric, :
|
9
|
+
method_option :weight, :type => :numeric, :desc => "The instance total weight for this account's quota"
|
10
|
+
method_option :size, :type => :numeric, :desc => "The volume total size for this account's quota"
|
11
11
|
def modify(account_uuid)
|
12
12
|
acc = M::Account[account_uuid] || UnknownUUIDError.raise(account_uuid)
|
13
13
|
super(M::Quota,acc.quota.canonical_uuid,{:instance_total_weight => options[:weight], :volume_total_size => options[:size]})
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
module Dcmgr::Cli
|
4
|
+
class SecurityGroup < Base
|
5
|
+
namespace :securitygroup
|
6
|
+
M = Dcmgr::Models
|
7
|
+
|
8
|
+
no_tasks {
|
9
|
+
def read_rule_text
|
10
|
+
if options[:rule].nil?
|
11
|
+
# Set blank string as rule.
|
12
|
+
return ''
|
13
|
+
elsif options[:rule] == '-'
|
14
|
+
# Read from STDIN
|
15
|
+
STDIN.read
|
16
|
+
else
|
17
|
+
# Read from file.
|
18
|
+
raise "Unknown rule file: #{options[:rule]}" if !File.exists?(options[:rule])
|
19
|
+
File.read(options[:rule])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
}
|
23
|
+
|
24
|
+
desc "add [options]", "Add a new security group"
|
25
|
+
method_option :uuid, :type => :string, :desc => "The UUID for the new security group."
|
26
|
+
method_option :account_id, :type => :string, :desc => "The UUID of the account this security group belongs to.", :required => true
|
27
|
+
method_option :description, :type => :string, :desc => "The description for this new security group."
|
28
|
+
method_option :rule, :type => :string, :desc => "Path to the rule text file. (\"-\" is from STDIN)"
|
29
|
+
def add
|
30
|
+
UnknownUUIDError.raise(options[:account_id]) if M::Account[options[:account_id]].nil?
|
31
|
+
|
32
|
+
fields = options.dup
|
33
|
+
fields[:rule] = read_rule_text
|
34
|
+
|
35
|
+
puts super(M::SecurityGroup,fields)
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "del UUID", "Delete a security group"
|
39
|
+
def del(uuid)
|
40
|
+
super(M::SecurityGroup,uuid)
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "show [UUID]", "Show security group(s)"
|
44
|
+
def show(uuid=nil)
|
45
|
+
if uuid
|
46
|
+
group = M::SecurityGroup[uuid] || UnknownUUIDError.raise(uuid)
|
47
|
+
puts ERB.new(<<__END, nil, '-').result(binding)
|
48
|
+
Group UUID:
|
49
|
+
<%= group.canonical_uuid %>
|
50
|
+
Account id:
|
51
|
+
<%= group.account_id %>
|
52
|
+
<%- if group.description -%>
|
53
|
+
Description:
|
54
|
+
<%= group.description %>
|
55
|
+
<%- end -%>
|
56
|
+
<%- unless group.security_group_rules.empty? -%>
|
57
|
+
Rules:
|
58
|
+
<%- group.security_group_rules.each { |rule| -%>
|
59
|
+
<%= rule.permission %>
|
60
|
+
<%- } -%>
|
61
|
+
<%- end -%>
|
62
|
+
__END
|
63
|
+
else
|
64
|
+
puts ERB.new(<<__END, nil, '-').result(binding)
|
65
|
+
<%- M::SecurityGroup.all { |row| -%>
|
66
|
+
<%= row.canonical_uuid %>\t<%= row.account_id %>\t<%= row.description %>
|
67
|
+
<%- } -%>
|
68
|
+
__END
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "modify UUID [options]", "Modify an existing security group"
|
73
|
+
method_option :account_id, :type => :string, :desc => "The UUID of the account this security group belongs to."
|
74
|
+
method_option :description, :type => :string, :desc => "The description for this new security group."
|
75
|
+
method_option :rule, :type => :string, :desc => "Path to the rule text file. (\"-\" is from STDIN)"
|
76
|
+
def modify(uuid)
|
77
|
+
UnknownUUIDError.raise(options[:account_id]) if options[:account_id] && M::Account[options[:account_id]].nil?
|
78
|
+
|
79
|
+
fields = options.dup
|
80
|
+
if options[:rule]
|
81
|
+
fields[:rule] = read_rule_text
|
82
|
+
end
|
83
|
+
|
84
|
+
super(M::SecurityGroup,uuid, fields)
|
85
|
+
end
|
86
|
+
|
87
|
+
desc "apply UUID [options]", "Apply a security group to an instance"
|
88
|
+
method_option :instance, :type => :string, :required => :true, :desc => "The instance to apply the group to"
|
89
|
+
def apply(uuid)
|
90
|
+
group = M::SecurityGroup[uuid] || UnknownUUIDError.raise(uuid)
|
91
|
+
instance = M::Instance[options[:instance]] || UnknownUUIDError.raise(options[:instance])
|
92
|
+
Error.raise("Group #{uuid} is already applied to instance #{options[:instance]}.",100) if group.instances.member?(instance)
|
93
|
+
group.add_instance(instance)
|
94
|
+
end
|
95
|
+
|
96
|
+
desc "remove UUID [options]", "Remove a security group from an instance"
|
97
|
+
method_option :instance, :type => :string, :required => :true, :desc => "The instance to remove the group from"
|
98
|
+
def remove(uuid)
|
99
|
+
group = M::SecurityGroup[uuid] || UnknownUUIDError.raise(uuid)
|
100
|
+
instance = M::Instance[options[:instance]] || UnknownUUIDError.raise(options[:instance])
|
101
|
+
Error.raise("Group #{uuid} is not applied to instance #{options[:instance]}.",100) unless group.instances.member?(instance)
|
102
|
+
group.remove_instance(instance)
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|