Sha256: 11521d53ae013c6bf872ac9190bc9933010d22cb437ed396c10b5d76f2fe7e5e

Contents?: true

Size: 1.98 KB

Versions: 20

Compression:

Stored size: 1.98 KB

Contents

module Fog
  module OpenStack
    class Compute
      class Real
        def list_security_groups(options = {})
          path = "os-security-groups"

          if options.kind_of?(Hash)
            server_id = options.delete(:server_id)
            query = options
          else
            # Backwards compatibility layer, only server_id was passed as first parameter previously
            Fog::Logger.deprecation('Calling OpenStack[:compute].list_security_groups(server_id) is deprecated, use .list_security_groups(:server_id => value) instead')
            server_id = options
            query = {}
          end

          if server_id
            path = "servers/#{server_id}/#{path}"
          end

          request(
            :expects => [200],
            :method  => 'GET',
            :path    => path,
            :query   => query
          )
        end
      end

      class Mock
        def list_security_groups(options = {})
          server_id = if options.kind_of?(Hash)
                        options.delete(:server_id)
                      else
                        options
                      end

          security_groups = data[:security_groups].values

          groups = if server_id
                     server_group_names =
                       Array(data[:server_security_group_map][server_id])

                     server_group_names.map do |name|
                       security_groups.find do |sg|
                         sg['name'] == name
                       end
                     end.compact
                   else
                     security_groups
                   end

          Excon::Response.new(
            :body    => {'security_groups' => groups},
            :headers => {
              "X-Compute-Request-Id" => "req-#{Fog::Mock.random_base64(36)}",
              "Content-Type"         => "application/json",
              "Date"                 => Date.new
            },
            :status  => 200
          )
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
fog-openstack-1.1.3 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.1.2 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-fork-99 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.1.0 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.1.0.pre lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-apibank-1.0.102 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.11 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-apibank-1.0.101 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.10 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.9 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.8 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.7 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.6 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.5 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.4 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.3 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.2 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.1 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-1.0.0 lib/fog/openstack/compute/requests/list_security_groups.rb
fog-openstack-0.3.1 lib/fog/openstack/compute/requests/list_security_groups.rb