Sha256: dbf778c4f8c43843cc7589efb3e931230faaf7da3ed4eb03785a9f21455672f2

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module Kakine
  class Operation
    class << self
      def adapter
        @@adapter ||= Kakine::Adapter.get_instance
      end

      def create_security_group(sg)
        attributes = {name: sg.name, description: sg.description, tenant_id: sg.tenant_id}
        security_group_id = adapter.create_security_group(attributes)

        #delete default rule
        sg.get_default_rule_instance.rules.each { |rule| rule.unregister! } unless adapter.instance_of?(Kakine::Adapter::Mock)
        security_group_id
      end

      def delete_security_group(sg)
        security_group = Kakine::Resource.security_group(sg.tenant_name, sg.name)
        adapter.delete_security_group(security_group.id)
      end

      def create_security_rule(tenant_name, sg_name, rule)
        security_group_id = if adapter.instance_of?(Kakine::Adapter::Mock)
          "[Mock] #{sg_name} ID"
        else
          Kakine::Resource.security_group(tenant_name, sg_name).id
        end
        adapter.create_rule(security_group_id, rule.direction, rule)
      end

      def delete_security_rule(tenant_name, sg_name, rule)
        security_group = Kakine::Resource.security_group(tenant_name, sg_name)
        security_group_rule = Kakine::Resource.security_group_rule(security_group, rule)
        adapter.delete_rule(security_group_rule.id)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kakine-0.3.0 lib/kakine/operation.rb