Class: Staypuft::NetworkQuery

Inherits:
Object
  • Object
show all
Defined in:
app/lib/staypuft/network_query.rb

Defined Under Namespace

Classes: Jail

Constant Summary collapse

VIP_NAMES =
{
  :ceilometer_admin_vip   => Staypuft::SubnetType::ADMIN_API,
  :ceilometer_private_vip => Staypuft::SubnetType::MANAGEMENT,
  :ceilometer_public_vip  => Staypuft::SubnetType::PUBLIC_API,
  :cinder_admin_vip       => Staypuft::SubnetType::ADMIN_API,
  :cinder_private_vip     => Staypuft::SubnetType::MANAGEMENT,
  :cinder_public_vip      => Staypuft::SubnetType::PUBLIC_API,
  :db_vip                 => Staypuft::SubnetType::MANAGEMENT,
  :glance_admin_vip       => Staypuft::SubnetType::ADMIN_API,
  :glance_private_vip     => Staypuft::SubnetType::MANAGEMENT,
  :glance_public_vip      => Staypuft::SubnetType::PUBLIC_API,
  :heat_admin_vip         => Staypuft::SubnetType::ADMIN_API,
  :heat_private_vip       => Staypuft::SubnetType::MANAGEMENT,
  :heat_public_vip        => Staypuft::SubnetType::PUBLIC_API,
  :heat_cfn_admin_vip     => Staypuft::SubnetType::ADMIN_API,
  :heat_cfn_private_vip   => Staypuft::SubnetType::MANAGEMENT,
  :heat_cfn_public_vip    => Staypuft::SubnetType::PUBLIC_API,
  :horizon_admin_vip      => Staypuft::SubnetType::ADMIN_API,
  :horizon_private_vip    => Staypuft::SubnetType::MANAGEMENT,
  :horizon_public_vip     => Staypuft::SubnetType::PUBLIC_API,
  :keystone_admin_vip     => Staypuft::SubnetType::ADMIN_API,
  :keystone_private_vip   => Staypuft::SubnetType::MANAGEMENT,
  :keystone_public_vip    => Staypuft::SubnetType::PUBLIC_API,
  :loadbalancer_vip       => Staypuft::SubnetType::PUBLIC_API,
  :neutron_admin_vip      => Staypuft::SubnetType::ADMIN_API,
  :neutron_private_vip    => Staypuft::SubnetType::MANAGEMENT,
  :neutron_public_vip     => Staypuft::SubnetType::PUBLIC_API,
  :nova_admin_vip         => Staypuft::SubnetType::ADMIN_API,
  :nova_private_vip       => Staypuft::SubnetType::MANAGEMENT,
  :nova_public_vip        => Staypuft::SubnetType::PUBLIC_API,
  :amqp_vip               => Staypuft::SubnetType::MANAGEMENT,
  :swift_public_vip       => Staypuft::SubnetType::PUBLIC_API,
  :keystone_private_vip   => Staypuft::SubnetType::MANAGEMENT
}
COUNT =
VIP_NAMES.size

Instance Method Summary collapse

Constructor Details

#initialize(deployment, host = nil) ⇒ NetworkQuery

Returns a new instance of NetworkQuery.



40
41
42
43
# File 'app/lib/staypuft/network_query.rb', line 40

def initialize(deployment, host=nil)
  @deployment = deployment
  @host       = host
end

Instance Method Details

#controller_fqdnsObject



86
87
88
# File 'app/lib/staypuft/network_query.rb', line 86

def controller_fqdns
  controllers.map &:fqdn
end

#controller_ip(subnet_type_name) ⇒ Object



82
83
84
# File 'app/lib/staypuft/network_query.rb', line 82

def controller_ip(subnet_type_name)
  ip_for_host(subnet_type_name, controllers.tap { |v| v.size == 1 or raise('only one controller is allowed') }.first)
end

#controller_ips(subnet_type_name) ⇒ Object



78
79
80
# File 'app/lib/staypuft/network_query.rb', line 78

def controller_ips(subnet_type_name)
  controllers.map { |controller| ip_for_host(subnet_type_name, controller) }
end

#controllersObject



74
75
76
# File 'app/lib/staypuft/network_query.rb', line 74

def controllers
  @controllers ||= @deployment.controller_hostgroup.hosts.order(:id)
end

#gateway_interface(host = @host) ⇒ Object



66
67
68
# File 'app/lib/staypuft/network_query.rb', line 66

def gateway_interface(host=@host)
  gateway_hash_for_host(host)[:interface]
end

#gateway_interface_mac(host = @host) ⇒ Object



70
71
72
# File 'app/lib/staypuft/network_query.rb', line 70

def gateway_interface_mac(host=@host)
  gateway_hash_for_host(host)[:mac]
end

#gateway_subnet(host = @host) ⇒ Object



62
63
64
# File 'app/lib/staypuft/network_query.rb', line 62

def gateway_subnet(host=@host)
  gateway_hash_for_host(host)[:subnet]
end

#get_vip(vip_name) ⇒ Object



97
98
99
100
101
102
103
# File 'app/lib/staypuft/network_query.rb', line 97

def get_vip(vip_name)
  if VIP_NAMES[vip_name]
    controller = vip_controller
    interface = controller.interfaces.vip.where(:tag => vip_name).first if controller
    interface.ip if interface
  end
end

#interface_for_host(subnet_type_name, host = @host) ⇒ Object



49
50
51
# File 'app/lib/staypuft/network_query.rb', line 49

def interface_for_host(subnet_type_name, host=@host)
  interface_hash_for_host(subnet_type_name, host)[:interface]
end

#ip_for_host(subnet_type_name, host = @host) ⇒ Object



45
46
47
# File 'app/lib/staypuft/network_query.rb', line 45

def ip_for_host(subnet_type_name, host=@host)
  interface_hash_for_host(subnet_type_name, host)[:ip]
end

#network_address_for_host(subnet_type_name, host = @host) ⇒ Object



53
54
55
56
# File 'app/lib/staypuft/network_query.rb', line 53

def network_address_for_host(subnet_type_name, host=@host)
  subnet = subnet_for_host(subnet_type_name, host)
  subnet.network_address if subnet
end

#subnet_for_host(subnet_type_name, host = @host) ⇒ Object



58
59
60
# File 'app/lib/staypuft/network_query.rb', line 58

def subnet_for_host(subnet_type_name, host=@host)
  interface_hash_for_host(subnet_type_name, host)[:subnet]
end

#vip_controllerObject



90
91
92
93
94
95
# File 'app/lib/staypuft/network_query.rb', line 90

def vip_controller
  controllers.each do |controller|
    return controller unless controller.interfaces.vip.empty?
  end
  return nil
end