Skip to content

Commit

Permalink
Merge pull request #961 from rsalevsky/rename_node
Browse files Browse the repository at this point in the history
Rename NodeObject to Node
  • Loading branch information
Rick Salevsky authored Jan 9, 2017
2 parents bce2be3 + 0e26d50 commit cdd9474
Show file tree
Hide file tree
Showing 49 changed files with 1,938 additions and 1,919 deletions.
2 changes: 1 addition & 1 deletion bin/crowbar_machines
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def aliases
names = body.nodes.map(&:name)
aliases = body.nodes.map { |node|
# FIXME: This code is a duplicate of the fallback value in
# NodeObject#alias.
# Node#alias.
hostname = node.name.split(".")[0]
node.alias == hostname ? "-" : node.alias
}
Expand Down
2 changes: 1 addition & 1 deletion chef/cookbooks/barclamp/libraries/barclamp_library.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def unique_name
# just rely on by-path. This means you can't go reordering disks
# in VirtualBox, but we can probably live with that.
#
# Keep these paths in sync with NodeObject#unique_device_for
# Keep these paths in sync with Node#unique_device_for
# within the crowbar barclamp to return always similar values.
disk_lookups = ["by-path"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def upgrade ta, td, a, d

# Make sure that all nodes have the proper run list order for the dns-client
# role
nodes = NodeObject.find("roles:dns-client")
nodes = Node.find("roles:dns-client")
nodes.each do |node|
node.delete_from_run_list("dns-client")
node.add_to_run_list("dns-client",
Expand Down
4 changes: 2 additions & 2 deletions chef/data_bags/crowbar/migrate/ipmi/100_merge_roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def upgrade(ta, td, a, d)
d["elements"].delete("ipmi-discover")

# ipmi roles are on all nodes
NodeObject.all.each do |node|
Node.all.each do |node|
node.add_to_run_list("ipmi",
td["element_run_list_order"]["ipmi"],
td["element_states"]["ipmi"])
Expand All @@ -29,7 +29,7 @@ def downgrade(ta, td, a, d)
d["elements"].delete("ipmi")

# ipmi roles are on all nodes
NodeObject.all.each do |node|
Node.all.each do |node|
node.add_to_run_list("ipmi-configure",
td["element_run_list_order"]["ipmi-configure"],
td["element_states"]["ipmi-configure"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def upgrade(ta, td, a, d)
d["elements"].delete("provisioner-bootdisk-finder")

# provisioner-bootdisk-finder was on all nodes
NodeObject.all.each do |node|
Node.all.each do |node|
node.delete_from_run_list("provisioner-bootdisk-finder")
node.save
end
Expand All @@ -18,7 +18,7 @@ def downgrade(ta, td, a, d)
d["elements"]["provisioner-bootdisk-finder"] = d["elements"]["provisioner-base"]

# provisioner-bootdisk-finder should be on all nodes
NodeObject.all.each do |node|
Node.all.each do |node|
node.add_to_run_list("provisioner-bootdisk-finder",
td["element_run_list_order"]["provisioner-bootdisk-finder"],
td["element_states"]["provisioner-bootdisk-finder"])
Expand Down
4 changes: 2 additions & 2 deletions crowbar_framework/app/controllers/barclamp_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def transition
# Be backward compatible with barclamps returning a node hash, passing
# them intact.
if response[:name]
render json: NodeObject.find_node_by_name(response[:name]).to_hash
render json: Node.find_node_by_name(response[:name]).to_hash
else
render json: response
end
Expand Down Expand Up @@ -928,7 +928,7 @@ def proposal_update
flash[:notice] = answer[1] if answer[0] >= 300 and answer[0] < 400
flash[:notice] = t("barclamp.proposal_show.commit_proposal_success") if answer[0] == 200
if answer[0] == 202
missing_nodes = answer[1].map { |node_dns| NodeObject.find_node_by_name(node_dns) }
missing_nodes = answer[1].map { |node_dns| Node.find_node_by_name(node_dns) }

unready_nodes = missing_nodes.select { |n| n.state != "ready" }.map(&:alias)
unallocated_nodes = missing_nodes.reject(&:allocated?).map(&:alias)
Expand Down
2 changes: 1 addition & 1 deletion crowbar_framework/app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def active_roles
private

def load_records
@nodes = NodeObject.all
@nodes = Node.all
@roles = RoleObject.all
@proposals = Proposal.all
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index

def node_name_map
nodes = {}
NodeObject.all.each { |node| nodes[node.name] = node }
Node.all.each { |node| nodes[node.name] = node }
nodes
end

Expand Down
4 changes: 2 additions & 2 deletions crowbar_framework/app/controllers/machines_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def index
raise "Could not find chef key at #{ENV["CHEF_CLIENT_KEY"]}"
end

@nodes = NodeObject.find_all_nodes.map do |node|
@nodes = Node.find_all_nodes.map do |node|
{
name: node.name,
alias: node.alias,
Expand Down Expand Up @@ -180,7 +180,7 @@ def load_machine_or_render_not_found
end

def load_machine
@machine = NodeObject.find_node_by_name_or_alias(
@machine = Node.find_node_by_name_or_alias(
params[:name] || params[:id]
)
end
Expand Down
8 changes: 4 additions & 4 deletions crowbar_framework/app/controllers/network_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ def switch
@nodes = {}

nodes = if params[:node]
NodeObject.find_nodes_by_name params[:node]
Node.find_nodes_by_name params[:node]
else
NodeObject.all
Node.all
end

nodes.each do |node|
Expand Down Expand Up @@ -232,7 +232,7 @@ def vlan
@vlans = net_bc.default_attributes["network"]["networks"]
end
@nodes = {}
NodeObject.all.each do |node|
Node.all.each do |node|
@nodes[node.handle] = { alias: node.alias, description: node.description(false, true), vlans: {} }
@nodes[node.handle][:vlans] = node_vlans(node)
end
Expand All @@ -258,7 +258,7 @@ def nodes
end

@nodes = {}
NodeObject.all.each do |node|
Node.all.each do |node|
@nodes[node.handle] = {
alias: node.alias,
description: node.description,
Expand Down
60 changes: 30 additions & 30 deletions crowbar_framework/app/controllers/nodes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def index
@groups = {}
session[:node] = params[:name]
if params.key?(:role)
result = NodeObject.all #this is not efficient, please update w/ a search!
result = Node.all # this is not efficient, please update w/ a search!
@nodes = result.find_all { |node| node.role? params[:role] }
if params.key?(:names_only)
names = @nodes.map { |node| node.handle }
Expand All @@ -71,7 +71,7 @@ def list
@allocated = true

@nodes = {}.tap do |nodes|
NodeObject.all.each do |node|
Node.all.each do |node|
nodes[node.handle] = node
end
end
Expand All @@ -85,7 +85,7 @@ def unallocated
@allocated = false

@nodes = {}.tap do |nodes|
NodeObject.all.each do |node|
Node.all.each do |node|
unless node.allocated?
nodes[node.handle] = node
end
Expand Down Expand Up @@ -131,7 +131,7 @@ def bulk
node_values.each do |node_name, node_attributes|
begin
dirty = false
node = NodeObject.find_node_by_name node_name
node = Node.find_node_by_name node_name
is_allocated = node.allocated?

if node_attributes["allocate"] and not is_allocated
Expand Down Expand Up @@ -210,7 +210,7 @@ def bulk

def families
@families = {}.tap do |families|
NodeObject.all.each do |node|
Node.all.each do |node|
family = node.family.to_s

unless families.key? family
Expand Down Expand Up @@ -240,7 +240,7 @@ def families
param :group, String, desc: "Group name", required: true
error 404, "Node not found"
def group_change
NodeObject.find_node_by_name(params[:id]).tap do |node|
Node.find_node_by_name(params[:id]).tap do |node|
raise ActionController::RoutingError.new("Not Found") if node.nil?

if params[:group].downcase.eql? "automatic"
Expand Down Expand Up @@ -310,7 +310,7 @@ def status
groups: {}
}.tap do |result|
begin
NodeObject.all.each do |node|
Node.all.each do |node|
group_name = node.group || I18n.t("unknown")

result[:groups][group_name] ||= begin
Expand Down Expand Up @@ -368,7 +368,7 @@ def status
], desc: "Action that needs to be performed on the node", required: true
def hit
name = params[:name] || params[:id]
machine = NodeObject.find_node_by_name name
machine = Node.find_node_by_name name

respond_to do |format|
format.json do
Expand Down Expand Up @@ -494,7 +494,7 @@ def update

#this code allow us to get values of attributes by path of node
def attribute
@node = NodeObject.find_node_by_name(params[:name])
@node = Node.find_node_by_name(params[:name])
raise ActionController::RoutingError.new("Node #{params[:name]} not found.") if @node.nil?
@attribute = @node.to_hash
params[:path].to_a.each do |element|
Expand Down Expand Up @@ -559,7 +559,7 @@ def save_node
def get_node_and_network(node_name)
network = {}
@network = []
@node = NodeObject.find_node_by_name(node_name) if @node.nil?
@node = Node.find_node_by_name(node_name) if @node.nil?
if @node
# If we're in discovery mode, then we have a temporary DHCP IP address.
if !["discovering", "discovered"].include?(@node.state)
Expand Down Expand Up @@ -598,27 +598,27 @@ def get_nodes_and_groups(node_name, draggable = true)
@sum = 0
@groups = {}
@nodes = {}
raw_nodes = NodeObject.all
raw_nodes.each do |node|
@sum = @sum + node.name.hash
@nodes[node.handle] = { alias: node.alias, description: node.description, status: node.status, state: node.state }
group = node.group
@groups[group] = { automatic: !node.display_set?("group"),
status: { "ready" => 0,
"failed" => 0,
"unknown" => 0,
"unready" => 0,
"pending" => 0,
"crowbar_upgrade" => 0 },
nodes: {}
} unless @groups.key? group
@groups[group][:nodes][node.group_order] = node.handle
@groups[group][:status][node.status] = (@groups[group][:status][node.status] || 0).to_i + 1
if node.handle === node_name
@node = node
get_node_and_network(node.handle)
end
raw_nodes = Node.all
raw_nodes.each do |node|
@sum = @sum + node.name.hash
@nodes[node.handle] = { alias: node.alias, description: node.description, status: node.status, state: node.state }
group = node.group
@groups[group] = { automatic: !node.display_set?("group"),
status: { "ready" => 0,
"failed" => 0,
"unknown" => 0,
"unready" => 0,
"pending" => 0,
"crowbar_upgrade" => 0 },
nodes: {}
} unless @groups.key? group
@groups[group][:nodes][node.group_order] = node.handle
@groups[group][:status][node.status] = (@groups[group][:status][node.status] || 0).to_i + 1
if node.handle === node_name
@node = node
get_node_and_network(node.handle)
end
end
@draggable = draggable
end
end
2 changes: 1 addition & 1 deletion crowbar_framework/app/controllers/support_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def export_chef
file.unlink if file.extname == ".json"
end

NodeObject.all.each { |n| n.export }
Node.all.each { |n| n.export }
RoleObject.all.each { |r| r.export }
Proposal.all.each { |p| p.export }

Expand Down
6 changes: 3 additions & 3 deletions crowbar_framework/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,14 @@ def value_for(value, fallback, condition = nil)
end

def default_platform
NodeObject.default_platform
Node.default_platform
end

def available_platforms(architecture)
NodeObject.available_platforms(architecture)
Node.available_platforms(architecture)
end

def disabled_platforms(architecture)
(NodeObject.disabled_platforms(architecture) + Crowbar::Repository.disabled_platforms(architecture)).uniq
(Node.disabled_platforms(architecture) + Crowbar::Repository.disabled_platforms(architecture)).uniq
end
end
10 changes: 5 additions & 5 deletions crowbar_framework/app/helpers/nodes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@

module NodesHelper
def all_non_admin_nodes
NodeObject.find("NOT admin_node:true")
Node.find("NOT admin_node:true")
end

def upgrading_nodes_count
NodeObject.find("state:crowbar_upgrade OR state:os-upgrading OR state:os-upgraded").count
Node.find("state:crowbar_upgrade OR state:os-upgrading OR state:os-upgraded").count
end

def failed_nodes_count
NodeObject.find("state:problem").count
Node.find("state:problem").count
end

def nodes_ready?
all_non_admin_nodes.select { |n| n.status != "ready" }.empty?
end

def nodes_by_role(role)
NodeObject.find("roles:#{role}").sort_by(&:alias)
Node.find("roles:#{role}").sort_by(&:alias)
end

def piechart_for(group)
Expand Down Expand Up @@ -107,7 +107,7 @@ def nodes_hash(group = nil)

@nodes_hash[group] ||= begin
{}.tap do |nodes|
NodeObject.all.each do |node|
Node.all.each do |node|
nodes[node.name] = {
handle: node.handle,
alias: node.alias,
Expand Down
4 changes: 2 additions & 2 deletions crowbar_framework/app/models/api/crowbar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def addons

def ceph_status
{}.tap do |ret|
ceph_node = NodeObject.find("roles:ceph-mon AND ceph_config_environment:*").first
ceph_node = ::Node.find("roles:ceph-mon AND ceph_config_environment:*").first
return ret if ceph_node.nil?
ssh_retval = ceph_node.run_ssh_cmd("LANG=C ceph health 2>&1")
unless ssh_retval[:stdout].include? "HEALTH_OK"
Expand All @@ -94,7 +94,7 @@ def ceph_status
def compute_resources_status
{}.tap do |ret|
["kvm", "xen"].each do |virt|
compute_nodes = NodeObject.find("roles:nova-compute-#{virt}")
compute_nodes = ::Node.find("roles:nova-compute-#{virt}")
next unless compute_nodes.size == 1
ret["errors"] ||= []
ret["errors"].push(
Expand Down
4 changes: 2 additions & 2 deletions crowbar_framework/app/models/api/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
module Api
class Node < Tableless
def initialize(name = nil)
@node = NodeObject.find_node_by_name name
@node = ::Node.find_node_by_name name
end

# execute script in background and wait for it to finish
Expand Down Expand Up @@ -202,7 +202,7 @@ def repocheck(options = {})

def node_architectures
{}.tap do |ret|
NodeObject.all.each do |node|
::Node.all.each do |node|
arch = node.architecture
ret["os"] ||= []
ret["os"].push(arch) unless ret["os"].include?(arch)
Expand Down
Loading

0 comments on commit cdd9474

Please sign in to comment.