class ZAWS::Services::EC2::VPC

Public Class Methods

new(shellout, aws,undofile) click to toggle source
# File lib/zaws/services/ec2/vpc.rb, line 10
def initialize(shellout, aws,undofile)
  @shellout=shellout
  @aws=aws
  @undofile=undofile
  @undofile ||= ZAWS::Helper::ZFile.new
end

Public Instance Methods

check_management_data(region, textout,verbose=nil,profile=nil) click to toggle source
# File lib/zaws/services/ec2/vpc.rb, line 27
def check_management_data(region, textout,verbose=nil,profile=nil)
  @aws.awscli.command_ec2.describeVPCs.execute(region, 'json',{}, verbose,profile)
  hash_vpc_name_externalid_data = @aws.awscli.data_ec2.vpc.hash_vpc_name_externalid
  hash_vpc_name_externalid_data.each do |id,vpc|
    if vpc['externalid']=='null'
      textout.puts("FAIL: VPC '#{id}' does not have the tag 'externalid' required to manage vpc with ZAWS.")
    end
    if vpc['Name']=='null'
      textout.puts("WARNING: VPC '#{id}' does not have the tag 'Name' which usually assists humans.")
    end
  end
end
declare(region,cidr,externalid,availabilitytimeout,textout,verbose=nil,profile=nil) click to toggle source
# File lib/zaws/services/ec2/vpc.rb, line 40
def declare(region,cidr,externalid,availabilitytimeout,textout,verbose=nil,profile=nil)
  @aws.awscli.command_ec2.describeVPCs.execute(region, 'json',{}, verbose,profile)
  vpc_exists = @aws.awscli.data_ec2.vpc.exists(cidr,externalid)
  if vpc_exists
    ZAWS::Helper::Output.out_no_op(textout, "No action needed. VPC exists already.")
    return 0
  end
  @aws.awscli.command_ec2.createVPC.execute(region,'json',cidr,textout,verbose,profile)
  vpc_id = @aws.awscli.data_ec2.vpc.id
  @aws.awscli.command_ec2.createTags.execute(vpc_id, region, 'externalid', externalid, textout, verbose)
  @aws.awscli.command_ec2.createTags.execute(vpc_id, region, 'Name', externalid, textout, verbose)
  begin
    filters={ "tag:externalid" => "#{externalid}","vpc-id"=>"#{vpc_id}","cidr"=>"#{cidr}" }
    Timeout.timeout(availabilitytimeout) do
      until @aws.awscli.data_ec2.vpc.available
        sleep(1)
        @aws.awscli.command_ec2.describeVPCs.execute(region, 'json',filters , verbose, profile)
      end
    end
    ZAWS::Helper::Output.out_change(textout, "VPC created.")
  rescue Timeout::Error
    throw 'Timeout before Subnet made available.'
  end
  return 0
end
view(region, view, textout=nil, verbose=nil) click to toggle source
# File lib/zaws/services/ec2/vpc.rb, line 17
def view(region, view, textout=nil, verbose=nil)
  @aws.awscli.command_ec2.describeVPCs.execute(region, view, {},verbose)
  textout.puts @aws.awscli.data_ec2.vpc.view
end
view_peering(region, view, textout=nil, verbose=nil) click to toggle source
# File lib/zaws/services/ec2/vpc.rb, line 22
def view_peering(region, view, textout=nil, verbose=nil)
  @aws.awscli.command_ec2.describeVpcPeeringConnections.execute(region, view, {},verbose)
  textout.puts @aws.awscli.data_ec2.vpc.view
end