Class: Knife::Server::Ec2SecurityGroup
- Inherits:
-
Object
- Object
- Knife::Server::Ec2SecurityGroup
- Defined in:
- lib/knife/server/ec2_security_group.rb
Overview
Sets up EC2 security groups for a Chef Server.
Instance Method Summary collapse
- #configure_chef_server_group(group_name, options = {}) ⇒ Object
- #find_or_create(name, options = {}) ⇒ Object
-
#initialize(connection, ui) ⇒ Ec2SecurityGroup
constructor
A new instance of Ec2SecurityGroup.
Constructor Details
#initialize(connection, ui) ⇒ Ec2SecurityGroup
Returns a new instance of Ec2SecurityGroup.
24 25 26 27 |
# File 'lib/knife/server/ec2_security_group.rb', line 24 def initialize(connection, ui) @aws = connection @ui = ui end |
Instance Method Details
#configure_chef_server_group(group_name, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/knife/server/ec2_security_group.rb', line 29 def configure_chef_server_group(group_name, = {}) group = find_or_create(group_name, ) .each do |p| if (group, p) @ui.msg "Inbound security group rule " \ "#{p[:proto]}(#{p[:from]} -> #{p[:to]}) exists" else @ui.msg "Creating inbound security group rule for " \ "#{p[:proto]}(#{p[:from]} -> #{p[:to]})" = (group, p) @aws.(group.name, ) end end end |
#find_or_create(name, options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/knife/server/ec2_security_group.rb', line 45 def find_or_create(name, = {}) group = @aws.security_groups.find { |g| g.name == name } if group.nil? @ui.msg "Creating EC2 security group '#{name}'" @aws.create_security_group(name, [:description]) group = @aws.security_groups.find { |g| g.name == name } else @ui.msg "EC2 security group '#{name}' exists" end group end |