Class: Fog::DNS::OpenStack::V2::Real

Inherits:
Object
  • Object
show all
Includes:
OpenStack::Core
Defined in:
lib/fog/dns/openstack/v2.rb,
lib/fog/dns/openstack/v2/requests/get_zone.rb,
lib/fog/dns/openstack/v2/requests/get_quota.rb,
lib/fog/dns/openstack/v2/requests/list_zones.rb,
lib/fog/dns/openstack/v2/requests/create_zone.rb,
lib/fog/dns/openstack/v2/requests/delete_zone.rb,
lib/fog/dns/openstack/v2/requests/update_zone.rb,
lib/fog/dns/openstack/v2/requests/update_quota.rb,
lib/fog/dns/openstack/v2/requests/get_recordset.rb,
lib/fog/dns/openstack/v2/requests/list_recordsets.rb,
lib/fog/dns/openstack/v2/requests/create_recordset.rb,
lib/fog/dns/openstack/v2/requests/delete_recordset.rb,
lib/fog/dns/openstack/v2/requests/update_recordset.rb

Instance Attribute Summary

Attributes included from OpenStack::Core

#auth_token, #auth_token_expiration, #current_tenant, #current_user, #current_user_id, #openstack_cache_ttl, #openstack_domain_id, #openstack_domain_name, #openstack_identity_prefix, #openstack_project_domain, #openstack_project_domain_id, #openstack_project_id, #openstack_user_domain, #openstack_user_domain_id, #unscoped_token

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OpenStack::Core

#credentials, #initialize_identity, #reload

Constructor Details

#initialize(options = {}) ⇒ Real


178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/fog/dns/openstack/v2.rb', line 178

def initialize(options = {})
  initialize_identity options

  @openstack_service_type           = options[:openstack_service_type] || ['dns']
  @openstack_service_name           = options[:openstack_service_name]

  @connection_options               = options[:connection_options] || {}

  authenticate
  set_api_path
  @persistent = options[:persistent] || false
  @connection = Fog::Core::Connection.new("#{@scheme}://#{@host}:#{@port}/", @persistent, @connection_options)
end

Class Method Details

.not_found_classObject


174
175
176
# File 'lib/fog/dns/openstack/v2.rb', line 174

def self.not_found_class
  Fog::DNS::OpenStack::NotFound
end

Instance Method Details

#create_recordset(zone_id, name, type, records, options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fog/dns/openstack/v2/requests/create_recordset.rb', line 6

def create_recordset(zone_id, name, type, records, options = {})
  data = {
    'name'    => name,
    'type'    => type,
    'records' => records
  }

  vanilla_options = [:ttl, :description]

  vanilla_options.select { |o| options[o] }.each do |key|
    data[key] = options[key]
  end

  request(
    :body    => Fog::JSON.encode(data),
    :expects => 202,
    :method  => 'POST',
    :path    => "zones/#{zone_id}/recordsets"
  )
end

#create_zone(name, email, options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/dns/openstack/v2/requests/create_zone.rb', line 6

def create_zone(name, email, options = {})
  data = {
    'name'  => name,
    'email' => email
  }

  vanilla_options = [:ttl, :description, :type, :masters]

  vanilla_options.select { |o| options[o] }.each do |key|
    data[key] = options[key]
  end

  request(
    :body    => Fog::JSON.encode(data),
    :expects => 202,
    :method  => 'POST',
    :path    => "zones"
  )
end

#delete_recordset(zone_id, id, options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'lib/fog/dns/openstack/v2/requests/delete_recordset.rb', line 6

def delete_recordset(zone_id, id, options = {})
  headers, _options = Fog::DNS::OpenStack::V2.setup_headers(options)
  request(
    :expects => 202,
    :method  => 'DELETE',
    :path    => "zones/#{zone_id}/recordsets/#{id}",
    :headers => headers
  )
end

#delete_zone(id, options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'lib/fog/dns/openstack/v2/requests/delete_zone.rb', line 6

def delete_zone(id, options = {})
  headers, _options = Fog::DNS::OpenStack::V2.setup_headers(options)
  request(
    :expects => 202,
    :method  => 'DELETE',
    :path    => "zones/#{id}",
    :headers => headers
  )
end

#get_quota(project_id = nil) ⇒ Object


6
7
8
9
10
11
12
13
14
15
# File 'lib/fog/dns/openstack/v2/requests/get_quota.rb', line 6

def get_quota(project_id = nil)
  headers, _options = Fog::DNS::OpenStack::V2.setup_headers(:all_projects => !project_id.nil?)

  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "quotas/#{project_id}",
    :headers => headers
  )
end

#get_recordset(zone_id, id, options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'lib/fog/dns/openstack/v2/requests/get_recordset.rb', line 6

def get_recordset(zone_id, id, options = {})
  headers, _options = Fog::DNS::OpenStack::V2.setup_headers(options)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "zones/#{zone_id}/recordsets/#{id}",
    :headers => headers
  )
end

#get_zone(id, options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
# File 'lib/fog/dns/openstack/v2/requests/get_zone.rb', line 6

def get_zone(id, options = {})
  headers, _options = Fog::DNS::OpenStack::V2.setup_headers(options)
  request(
    :expects => 200,
    :method  => 'GET',
    :path    => "zones/#{id}",
    :headers => headers
  )
end

#list_recordsets(zone_id = nil, options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/fog/dns/openstack/v2/requests/list_recordsets.rb', line 6

def list_recordsets(zone_id = nil, options = {})
  # for backward compatability: consider removing the zone_id param (breaking change)
  unless zone_id.nil?
    if zone_id.kind_of?(Hash)
      options = zone_id
      zone_id = nil
    else
      Fog::Logger.deprecation(
        'Calling list_recordsets(zone_id) is deprecated, use .list_recordsets(zone_id: value) instead'
      )
    end
  end

  zone_id = options.delete(:zone_id) if zone_id.nil?
  path = zone_id.nil? ? 'recordsets' : "zones/#{zone_id}/recordsets"

  headers, options = Fog::DNS::OpenStack::V2.setup_headers(options)

  request(
    :expects => 200,
    :method  => 'GET',
    :path    => path,
    :query   => options,
    :headers => headers
  )
end

#list_zones(options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/dns/openstack/v2/requests/list_zones.rb', line 6

def list_zones(options = {})
  headers, options = Fog::DNS::OpenStack::V2.setup_headers(options)

  request(
    :expects => 200,
    :method  => 'GET',
    :path    => 'zones',
    :query   => options,
    :headers => headers
  )
end

#set_api_pathObject


192
193
194
195
196
197
198
199
200
201
# File 'lib/fog/dns/openstack/v2.rb', line 192

def set_api_path
  unless @path.match(SUPPORTED_VERSIONS)
    @path = Fog::OpenStack.get_supported_version_path(
      SUPPORTED_VERSIONS,
      @openstack_management_uri,
      @auth_token,
      @connection_options
    )
  end
end

#update_quota(project_id, options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/dns/openstack/v2/requests/update_quota.rb', line 6

def update_quota(project_id, options = {})
  headers, options = Fog::DNS::OpenStack::V2.setup_headers(options)

  request(
    :body    => Fog::JSON.encode(options),
    :expects => 200,
    :method  => 'PATCH',
    :path    => "quotas/#{project_id}",
    :headers => headers
  )
end

#update_recordset(zone_id, id, options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/dns/openstack/v2/requests/update_recordset.rb', line 6

def update_recordset(zone_id, id, options = {})
  headers, options = Fog::DNS::OpenStack::V2.setup_headers(options)

  request(
    :body    => Fog::JSON.encode(options),
    :expects => 202,
    :method  => 'PUT',
    :path    => "zones/#{zone_id}/recordsets/#{id}",
    :headers => headers
  )
end

#update_zone(id, options = {}) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/dns/openstack/v2/requests/update_zone.rb', line 6

def update_zone(id, options = {})
  headers, options = Fog::DNS::OpenStack::V2.setup_headers(options)

  request(
    :body    => Fog::JSON.encode(options),
    :expects => 202,
    :method  => 'PATCH',
    :path    => "zones/#{id}",
    :headers => headers
  )
end