Class: Kanmon::SecurityGroup

Inherits:
Object
  • Object
show all
Defined in:
lib/kanmon/securitygroup.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, port, ip = nil) ⇒ SecurityGroup

Returns a new instance of SecurityGroup.



9
10
11
12
13
14
# File 'lib/kanmon/securitygroup.rb', line 9

def initialize(id, port, ip = nil)
  @id = id
  @port = port || 22
  @ip = ip || Kanmon::MyIP.get
  @tenant_id = Yao.current_tenant_id
end

Instance Attribute Details

#ipObject (readonly)

Returns the value of attribute ip.



7
8
9
# File 'lib/kanmon/securitygroup.rb', line 7

def ip
  @ip
end

Instance Method Details

#closeObject



29
30
31
32
33
34
35
36
37
# File 'lib/kanmon/securitygroup.rb', line 29

def close
  result = Yao::SecurityGroupRule.list(rule)

  if result.empty?
    puts "Rule not found"
  else
    delete_rules(result)
  end
end

#openObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/kanmon/securitygroup.rb', line 16

def open
  result = Yao::SecurityGroupRule.create(rule)
  puts "Added Rule: #{result.id}"

  if block_given?
    begin
      yield
    ensure
      delete_rules([result])
    end
  end
end