Class: Mccloud::Provider::Core::Provider

Inherits:
Object
  • Object
show all
Defined in:
lib/mccloud/provider/core/provider.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, env) ⇒ Provider

Returns a new instance of Provider.



10
11
12
# File 'lib/mccloud/provider/core/provider.rb', line 10

def initialize(name,options,env)
  @env=env
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



101
102
103
# File 'lib/mccloud/provider/core/provider.rb', line 101

def method_missing(m, *args, &block)
 env.logger.info "There's no method #{m} defined for provider #{@name}-- ignoring it"
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



6
7
8
# File 'lib/mccloud/provider/core/provider.rb', line 6

def env
  @env
end

#namespaceObject

Returns the value of attribute namespace.



8
9
10
# File 'lib/mccloud/provider/core/provider.rb', line 8

def namespace
  @namespace
end

Instance Method Details

#check_gem_availability(gems) ⇒ Object

TODO this loading of gem , needs to be moved else where This provider should only check what it needs



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/mccloud/provider/core/provider.rb', line 83

def check_gem_availability(gems)

  gems.each do |gemname|
    availability_gem=false
    begin
      availability_gem=true unless Gem::Specification::find_by_name("#{gemname}").nil?
    rescue Gem::LoadError
      availability_gem=false
    rescue
      availability_gem=Gem.available?("#{gemname}")
    end
    unless availability_gem
      abort "The #{gemname} gem is not installed and is required by the #{@name.to_sym} provider"
      exit
    end
  end
end

#filterObject



62
63
64
65
66
67
68
# File 'lib/mccloud/provider/core/provider.rb', line 62

def filter
  if @namespace.nil? || @namespace==""
    return ""
  else
    return "#{@namespace}-"
  end
end

#get_component(type, env) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/mccloud/provider/core/provider.rb', line 14

def get_component(type,env)
  real_component=nil
  begin
    # Now that we know the actual provider, we can check if the provider has this type of component
    require_path='mccloud/provider/'+@flavor.to_s.downcase+"/"+type.to_s.downcase
    require require_path
    # Now we can create the real component

    env.logger.debug("provider #{@flavor} about to create component of type #{type}")

    real_component=Object.const_get("Mccloud").const_get("Provider").const_get(@flavor.to_s.capitalize).const_get(type.to_s.capitalize).new(env)

  rescue Error => e
    env.ui.error "Error getting component - #{e}"
  end
  return real_component
end

#hostsObject



70
71
72
73
74
75
76
77
78
# File 'lib/mccloud/provider/core/provider.rb', line 70

def hosts
  hostentries = Hash.new
  self.vms.each do |name,vm|
   hostentries[name] = Hash.new
   hostentries[name]['public_ip_address'] = vm.public_ip_address
   hostentries[name]['private_ip_address'] = vm.private_ip_address
  end
  return hostentries
end

#on_selected_components(type, selection = nil) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/mccloud/provider/core/provider.rb', line 32

def on_selected_components(type,selection=nil)
  unless self.instance_variables.collect{|v| v.to_s}.include?("@vms")
    env.ui.info "There are no #{type}s defined for provider #{@name}"
    # Nothing to do here
    return
  end

  components=self.instance_variable_get("@#{type}s")

  unless components.nil?

  if selection.nil? || selection == "all"
    components.each do |name,component|
      if component.auto_selected?
        yield name,component
      else
        env.ui.info "[#{name}] Skipping because it has autoselection off"
      end
    end
  else # a specific component
    if components.has_key?(selection)
      yield name,components[selection]
    end
  end

  else
        env.ui.info "[#{name}] Has no components of type #{type}"
  end
end