Sha256: ce892e7a487aed91462562f6805b72e34461d7c24300806c92f5337d12e5dbb9

Contents?: true

Size: 1.67 KB

Versions: 26

Compression:

Stored size: 1.67 KB

Contents

require 'capistrano'

module AlphaOmega

  def self.what_branch (allowed = %w(production master develop))
    if ENV["BRANCH"]
      ENV["BRANCH"]
    elsif ENV["TAG"]
      ENV["TAG"]
    else
      current = `git branch`.split("\n").find {|b| b.split(" ")[0] == '*' } # use Grit
      if current
        star, branch_name = current.split(" ")
        branch_type, branch_feature = branch_name.split("/")
        if %w(feature hotfix).member?(branch_type)
          branch_name
        elsif !branch_feature && allowed.member?(branch_type)
          branch_type
        else
          puts "current branch must be #{allowed.join(', ')}, feature/xyz, or hotfix/xyz"
          abort
        end
      else
        puts "could not find a suitable branch"
        abort
      end
    end
  end

  def self.what_hosts (nodes_spec)
    # load all the nodes and define cap tasks
    nodes = {}

    Dir[nodes_spec].each do |fname|
      nm_node = File.basename(fname, ".json")

      node = JSON.parse(IO.read(fname))
      node[:node_name] = nm_node

      nodes[nm_node] = node

      yield node if node[:node_name] && node["public_ip"] # TODO is the :node_name test necessary?
    end

    nodes

  end

  def self.what_groups (nodes)
    # generalize groups
    cap_groups = {}

    nodes.each do |nm_node, node|
      %w(chef_group cap_group).each do |nm_group| # TODO get rid of chef_group
        if node.member?(nm_group) && !node["ignore"]
          node[nm_group].each do |g|
            cap_groups[g] ||= {}
            cap_groups[g][nm_node] = node
          end
        end
      end
    end

    cap_groups.each do |nm_group, group|
      yield nm_group, group
    end

    cap_groups
  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
alpha_omega-0.0.51 lib/alpha_omega/utils.rb
alpha_omega-0.0.49 lib/alpha_omega/utils.rb
alpha_omega-0.0.48 recipes/alpha_omega/utils.rb
alpha_omega-0.0.47 recipes/alpha_omega/utils.rb
alpha_omega-0.0.46 recipes/alpha_omega/utils.rb
alpha_omega-0.0.45 recipes/alpha_omega/utils.rb
alpha_omega-0.0.43 recipes/alpha_omega/utils.rb
alpha_omega-0.0.42 recipes/alpha_omega/utils.rb
alpha_omega-0.0.41 recipes/alpha_omega/utils.rb
alpha_omega-0.0.39 recipes/alpha_omega/utils.rb
alpha_omega-0.0.38 recipes/alpha_omega/utils.rb
alpha_omega-0.0.37 recipes/alpha_omega/utils.rb
alpha_omega-0.0.36 recipes/alpha_omega/utils.rb
alpha_omega-0.0.35 recipes/alpha_omega/utils.rb
alpha_omega-0.0.34 recipes/alpha_omega/utils.rb
alpha_omega-0.0.33 recipes/alpha_omega/utils.rb
alpha_omega-0.0.32 recipes/alpha_omega/utils.rb
alpha_omega-0.0.31 recipes/alpha_omega/utils.rb
alpha_omega-0.0.30 recipes/alpha_omega/utils.rb
alpha_omega-0.0.29 recipes/alpha_omega/utils.rb