Class: ZAWS::AWSCLI::Data::EC2::VPC
- Inherits:
-
Object
- Object
- ZAWS::AWSCLI::Data::EC2::VPC
- Defined in:
- lib/zaws/external/awscli/data/ec2/vpc.rb
Instance Method Summary collapse
- #available ⇒ Object
- #exists(cidr, externalid) ⇒ Object
- #hash_vpc_name_externalid ⇒ Object
- #id ⇒ Object
-
#initialize(shellout, ec2) ⇒ VPC
constructor
A new instance of VPC.
- #load(command, data, verbose) ⇒ Object
- #validJSON ⇒ Object
- #view ⇒ Object
Constructor Details
#initialize(shellout, ec2) ⇒ VPC
Returns a new instance of VPC.
7 8 9 10 11 |
# File 'lib/zaws/external/awscli/data/ec2/vpc.rb', line 7 def initialize(shellout, ec2) @shellout=shellout @ec2=ec2 @vpc_hash=nil end |
Instance Method Details
#available ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/zaws/external/awscli/data/ec2/vpc.rb', line 64 def available() if @vpc_hash and @vpc_hash["Vpc"] return (@vpc_hash["Vpc"]["State"] == "available") end if @vpc_hash and @vpc_hash["Vpcs"] and @vpc_hash["Vpcs"].count==1 return (@vpc_hash["Vpcs"][0]["State"]=="available") end false end |
#exists(cidr, externalid) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/zaws/external/awscli/data/ec2/vpc.rb', line 47 def exists(cidr,externalid) result = false if validJSON @vpc_hash['Vpcs'].each do |vpc| if result break elsif vpc['Tags'] vpc['Tags'].each do |tag| result = tag['Key']=='externalid' ? (externalid==tag['Value']) : false end result = (result and (vpc['CidrBlock']==cidr)) end end end result end |
#hash_vpc_name_externalid ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/zaws/external/awscli/data/ec2/vpc.rb', line 30 def hash_vpc_name_externalid() vpc_name_externalid={} if validJSON @vpc_hash['Vpcs'].each do |vpc| vals={} vals['externalid']="null" vals['Name']="null" vpc['Tags'].each do |tag| vals['Name']=tag['Value'] if tag['Key']=='Name' vals['externalid']=tag['Value'] if tag['Key']=='externalid' end vpc_name_externalid[vpc['VpcId']]=vals end end return vpc_name_externalid end |
#id ⇒ Object
74 75 76 77 78 79 |
# File 'lib/zaws/external/awscli/data/ec2/vpc.rb', line 74 def id() if @vpc_hash and @vpc_hash["Vpc"] return (@vpc_hash["Vpc"]["VpcId"]) end 0 end |
#load(command, data, verbose) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/zaws/external/awscli/data/ec2/vpc.rb', line 17 def load(command, data, verbose) @vpc_raw_data = data @vpc_hash=nil begin @vpc_hash =JSON.parse(data) rescue JSON::ParserError => e end end |
#validJSON ⇒ Object
13 14 15 |
# File 'lib/zaws/external/awscli/data/ec2/vpc.rb', line 13 def validJSON return (not @vpc_hash.nil?) end |
#view ⇒ Object
26 27 28 |
# File 'lib/zaws/external/awscli/data/ec2/vpc.rb', line 26 def view() return @vpc_raw_data end |