Class: Awful::Subnet
  
  
  
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  Methods inherited from Cli
  #initialize, #ll, #version
  
  Constructor Details
  
    This class inherits a constructor from Awful::Cli
  
 
  
    Instance Method Details
    
      
  
  
    #create(name)  ⇒ Object 
  
  
  
  
    
      
30
31
32
33
34
35
36
37
38
39 
     | 
    
      # File 'lib/awful/subnet.rb', line 30
def create(name)
  opt = load_cfg
  whitelist = %i[vpc_id cidr_block availability_zone]
  opt = remove_empty_strings(opt)
  ec2.create_subnet(only_keys_matching(opt, whitelist)).tap do |response|
    id = response.map(&:subnet).map(&:subnet_id)
    ec2.create_tags(resources: Array(id), tags: opt[:tags]) if opt[:tags]
    puts id
  end
end
     | 
  
 
    
      
  
  
    #delete(name)  ⇒ Object 
  
  
  
  
    
      
42
43
44
45
46
47 
     | 
    
      # File 'lib/awful/subnet.rb', line 42
def delete(name)
  id = find_subnet(name)
  if id and yes?("really delete subnet #{name} (#{id})?")
    ec2.delete_subnet(subnet_id: id)
  end
end
     | 
  
 
    
      
  
  
    #dump(name)  ⇒ Object 
  
  
  
  
    
      
21
22
23
24
25
26
27 
     | 
    
      # File 'lib/awful/subnet.rb', line 21
def dump(name)
  ec2.describe_subnets.map(&:subnets).flatten.find do |subnet|
    subnet.subnet_id == name or subnet.tags.any? { |tag| tag.value == name }
  end.tap do |subnet|
    puts YAML.dump(stringify_keys(subnet.to_hash))
  end
end
     | 
  
 
    
      
  
  
    #ls(name = /./)  ⇒ Object 
  
  
  
  
    
      
7
8
9
10
11
12
13
14
15
16
17
18 
     | 
    
      # File 'lib/awful/subnet.rb', line 7
def ls(name = /./)
  fields = options[:long] ?
    ->(s) { [(tag_name(s) || '-'), s.subnet_id, s.state, s.cidr_block, s.available_ip_address_count, s.availability_zone] } :
    ->(s) { [s.subnet_id] }
  ec2.describe_subnets.map(&:subnets).flatten.select do |subnet|
    subnet.tags.any? { |tag| tag.value.match(name) }
  end.map do |subnet|
    fields.call(subnet)
  end.tap do |list|
    print_table list.sort
  end
end
     |