Class: Dcmgr::NodeModules::HvaCollector
- Inherits:
-
Isono::NodeModules::Base
- Object
- Isono::NodeModules::Base
- Dcmgr::NodeModules::HvaCollector
- Includes:
- Isono::NodeModules
- Defined in:
- lib/dcmgr/node_modules/hva_collector.rb
Instance Method Summary collapse
- #get_alive_instances(node_id) ⇒ Object
- #get_dhcp_conf(network_name) ⇒ Object
- #get_group_instance_ipv4s(instance_id) ⇒ Object
- #get_instance(instance_id) ⇒ Object
- #get_instances_of_netfilter_group(netfilter_group_id) ⇒ Object
- #get_netfilter_groups_of_instance(instance_id) ⇒ Object
- #get_network(network_id) ⇒ Object
- #get_networks ⇒ Object
- #update_instance(instance_id, data) ⇒ Object
Instance Method Details
#get_alive_instances(node_id) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/dcmgr/node_modules/hva_collector.rb', line 120 def get_alive_instances(node_id) Models::HostPool.lock! hp = Models::HostPool.find(:node_id => node_id) raise "UnknownNodeID", node_id if hp.nil? inst_on_hp = hp.instances_dataset.lives.all.map { |inst| inst.to_hash } inst_on_hp.uniq! if inst_on_hp.size > 0 inst_on_hp end |
#get_dhcp_conf(network_name) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/dcmgr/node_modules/hva_collector.rb', line 80 def get_dhcp_conf(network_name) Models::Network.lock! network = Models::Network.find(:name=>network_name) raise "Unknown network name: #{network_name}" if network.nil? prefix = IPAddress::Prefix32.new(network.prefix) h = { :ipv4_gw=>network.ipv4_gw, :netmask => prefix.to_ip, :prefix => network.prefix, :dns_server=> network.dns_server, :domain_name => network.domain_name, :mac2addr => [], :addr2host=> [], } network.ip_lease.each { |ip| # ignore IPs unbound to vnic. next if ip.instance_nic.nil? || ip.instance_nic.instance.nil? h[:mac2addr] << { :mac_addr => ip.instance_nic.pretty_mac_addr, :ipaddr => ip.ipv4 } h[:addr2host] << { :hostname => ip.instance_nic.instance.fqdn_hostname, :ipaddr => ip.ipv4 } } h end |
#get_group_instance_ipv4s(instance_id) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/dcmgr/node_modules/hva_collector.rb', line 50 def get_group_instance_ipv4s(instance_id) Models::Instance.lock! inst = Models::Instance[instance_id] raise "UnknownInstanceID" if inst.nil? insts = inst.netfilter_group_instances ips = insts.map { |instance| next if instance.nil? instance.ips.map { |ip| ip.ipv4 unless ip.nil? } } ips.flatten! if ips.size > 0 ips.compact end |
#get_instance(instance_id) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/dcmgr/node_modules/hva_collector.rb', line 25 def get_instance(instance_id) Models::Instance.lock! inst = Models::Instance[instance_id] raise "UnknownInstanceID" if inst.nil? ret = inst.to_hash ret end |
#get_instances_of_netfilter_group(netfilter_group_id) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/dcmgr/node_modules/hva_collector.rb', line 112 def get_instances_of_netfilter_group(netfilter_group_id) Models::NetfilterGroup.lock! g = Models::NetfilterGroup[netfilter_group_id] raise "UnknownNetfilterGroupID" if g.nil? inst_maps = g.instances.map { |instance| instance.to_hash unless instance.nil? } inst_maps.compact end |
#get_netfilter_groups_of_instance(instance_id) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/dcmgr/node_modules/hva_collector.rb', line 42 def get_netfilter_groups_of_instance(instance_id) Models::Instance.lock! inst = Models::Instance[instance_id] raise "UnknownInstanceID" if inst.nil? inst.netfilter_groups.map { |g| g.to_hash } end |
#get_network(network_id) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/dcmgr/node_modules/hva_collector.rb', line 65 def get_network(network_id) Models::Network.lock! network = Models::Network[network_id] raise "UnknownNetworkID" if network.nil? network.to_hash end |