Class: AWS::Vpccreate

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-vpccreate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ec2) ⇒ Vpccreate

Returns a new instance of Vpccreate.



31
32
33
34
35
# File 'lib/aws-vpccreate.rb', line 31

def initialize ec2
  @logger = Logger.new
  @ec2 = ec2
  @vpc = nil
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



29
30
31
# File 'lib/aws-vpccreate.rb', line 29

def logger
  @logger
end

#vpcObject (readonly)

Returns the value of attribute vpc.



29
30
31
# File 'lib/aws-vpccreate.rb', line 29

def vpc
  @vpc
end

Instance Method Details

#create_igObject



57
58
59
60
61
62
63
# File 'lib/aws-vpccreate.rb', line 57

def create_ig
  raise "no vpc instance" if @vpc == nil

  ig = @ec2.internet_gateways.create
  ig.attach @vpc
  ig
end

#create_rt(options = {}) ⇒ Object



76
77
78
79
80
81
# File 'lib/aws-vpccreate.rb', line 76

def create_rt options = {}
  raise "no vpc instance" if @vpc == nil

  options[:vpc] = @vpc
  @ec2.route_tables.create(options)
end

#create_sg(name, options = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/aws-vpccreate.rb', line 65

def create_sg name, options = {}
  raise "no vpc instance" if @vpc == nil

  @logger.put({ :key => :security_group,
                :value => { :name => name, 
                  :description => options[:description]}})

  options[:vpc] = @vpc
  @ec2.security_groups.create(name, options)
end

#create_subnet(cidr_block, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/aws-vpccreate.rb', line 46

def create_subnet cidr_block, options = {}
  raise "no vpc instance" if @vpc == nil

  @logger.put({:key => :subnets, 
                :value => {:subnet_addr => cidr_block,
                  :availability_zone => options[:availability_zone]}})

  options[:vpc] = @vpc
  @ec2.subnets.create(cidr_block, options)
end

#create_vpc(cidr_block, options = {}) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/aws-vpccreate.rb', line 37

def create_vpc cidr_block, options = {}
  @vpc = @ec2.vpcs.create(cidr_block, options)

  @logger.put({:key => :vpc_subnet, :value => cidr_block})
  @logger.put({:key => :vpc_id, :value => @vpc.id})

  @vpc
end