Sha256: 3c269f8aac43498c6eb3740ac7c27c874e8400ab686cec7a9f8b8882a77a8d8b

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

#!/usr/bin/env ruby
# encoding: UTF-8

# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
#
#    Licensed under the Apache License, Version 2.0 (the "License");
#    you may not use this file except in compliance with the License.
#    You may obtain a copy of the License at
#
#        http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.

require 'require_relative'

require_relative 'connection.rb'
include Connection

#
# SecurityGroup module
#
module SecurityGroup

  def create_security_group(name)
    description = format('Security group for blueprint %{name}', name: name)
    Connection.network.security_groups.create(
        :name => name,
        :description => description
    )
  end

  def delete_security_group(security_group_id)
    Connection.network.security_groups.get(security_group_id).destroy
  end

  def create_security_group_rule(security_group_id, protocol, port_min, port_max)
    begin
      Connection.network.security_group_rules.create(
          :security_group_id => security_group_id,
          :direction => 'ingress',
          :protocol => protocol,
          :port_range_min => port_min,
          :port_range_max => port_max,
          :remote_ip_prefix => '0.0.0.0/0'
      )
    rescue StandardError
      puts format('error creating the rule for port %{port_min}', port_min: port_min)
    end
  end

  def delete_security_group_rule(rule_id)
    Connection.network.security_group_rules.get(rule_id).destroy
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
forj-0.0.21 lib/security.rb
forj-0.0.20 lib/security.rb