Module: Befog::Commands::Mixins::Scope

Included in:
Add, Configure, List, Remove, Run, Start, Stop
Defined in:
lib/befog/commands/mixins/scope.rb

Instance Method Summary collapse

Instance Method Details

#_bankObject



105
106
107
# File 'lib/befog/commands/mixins/scope.rb', line 105

def _bank
  banks[bank_name] ||= {}
end

#account_keyObject



25
26
27
# File 'lib/befog/commands/mixins/scope.rb', line 25

def 
  provider["key"]
end

#account_secretObject



29
30
31
# File 'lib/befog/commands/mixins/scope.rb', line 29

def 
  provider["secret"]
end

#bankObject



109
110
111
# File 'lib/befog/commands/mixins/scope.rb', line 109

def bank
  _bank["configuration"] ||= {}
end

#bank?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/befog/commands/mixins/scope.rb', line 113

def bank?
  !!options[:bank]
end

#bank_nameObject



117
118
119
# File 'lib/befog/commands/mixins/scope.rb', line 117

def bank_name
  options[:bank] or error("Did you mean to include a bank name?")
end

#banksObject



101
102
103
# File 'lib/befog/commands/mixins/scope.rb', line 101

def banks
  configuration["banks"] ||= {}
end

#computeObject

TODO: do something clever once we have more than 2-3 providers



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/befog/commands/mixins/scope.rb', line 34

def compute
  case provider_name
  when "aws"
    @compute ||= Fog::Compute.new(:provider => "AWS", 
      :aws_access_key_id => , 
      :aws_secret_access_key => ,
      :region => region)
  else
    error("Provider '#{provider_name}' is currently unsupported.")
  end
end

#flavorObject



60
61
62
63
# File 'lib/befog/commands/mixins/scope.rb', line 60

def flavor
  options[:type] or bank["type"] or 
    error("Specify an instance type (flavor) with --type or by adding one to the '#{bank_name}' bank.")
end

#flavor?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/befog/commands/mixins/scope.rb', line 65

def flavor?
  !!options[:type] or bank["type"]
end

#get_server(id) ⇒ Object



46
47
48
# File 'lib/befog/commands/mixins/scope.rb', line 46

def get_server(id)
  compute.servers.get(id)
end

#imageObject



69
70
71
72
# File 'lib/befog/commands/mixins/scope.rb', line 69

def image
  options[:image] or bank["image"] or 
    error("Specify an image with --image or by adding one to the '#{bank_name}' bank.")
end

#image?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/befog/commands/mixins/scope.rb', line 74

def image?
  !!options[:image] or bank["image"]
end

#keypairObject



87
88
89
90
# File 'lib/befog/commands/mixins/scope.rb', line 87

def keypair
  options[:keypair] or bank["keypair"] or 
    error("Specify a keypair with --keypair or by adding one to the '#{bank_name}' bank.")
end

#keypair?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/befog/commands/mixins/scope.rb', line 97

def keypair?
  !!options[:keypair] or bank["keypair"]
end

#priceObject



92
93
94
95
# File 'lib/befog/commands/mixins/scope.rb', line 92

def price
  options[:price] or bank["price"] or
    error("Specify a spot instance price with --price or by adding one to the '#{bank_name}' bank.")
end

#providerObject



21
22
23
# File 'lib/befog/commands/mixins/scope.rb', line 21

def provider
  @provider ||= (providers[provider_name] ||= {})
end

#provider?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/befog/commands/mixins/scope.rb', line 13

def provider?
  !!options[:provider] or bank["provider"]
end

#provider_nameObject



8
9
10
11
# File 'lib/befog/commands/mixins/scope.rb', line 8

def provider_name
  options[:provider] or bank["provider"] or 
    error("Specify a provider with --provider or by adding one to the '#{bank_name}' bank.")
end

#providersObject



17
18
19
# File 'lib/befog/commands/mixins/scope.rb', line 17

def providers
  @providers ||= (configuration["providers"] ||= {})
end

#regionObject



51
52
53
54
# File 'lib/befog/commands/mixins/scope.rb', line 51

def region
  options[:region] or bank["region"] or 
    error("Specify a region with --region or by adding one to the '#{bank_name}' bank.")
end

#region?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/befog/commands/mixins/scope.rb', line 56

def region?
  !!options[:region] or bank["region"]
end

#security_groupObject



78
79
80
81
# File 'lib/befog/commands/mixins/scope.rb', line 78

def security_group
  options[:group] or bank["group"] or 
    error("Specify a security group with --group or by adding one to the '#{bank_name}' bank.")
end

#security_group?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/befog/commands/mixins/scope.rb', line 83

def security_group?
  options[:group] or bank["group"]
end

#serversObject



121
122
123
# File 'lib/befog/commands/mixins/scope.rb', line 121

def servers
  _bank["servers"] ||= []
end

#servers=(array) ⇒ Object



125
126
127
# File 'lib/befog/commands/mixins/scope.rb', line 125

def servers=(array)
  _bank["servers"] = array
end