Class: Fog::Compute::Google::UrlMap

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/compute/google/models/url_map.rb

Constant Summary collapse

RUNNING_STATE =
"READY".freeze

Instance Method Summary collapse

Instance Method Details

#add_host_rules(rules_to_add, async = true) ⇒ Object


58
59
60
61
62
63
64
65
66
67
68
# File 'lib/fog/compute/google/models/url_map.rb', line 58

def add_host_rules(rules_to_add, async = true)
  requires :identity

  rules = (host_rules || []).concat rules_to_add
  data = service.patch_url_map(identity, :host_rules => rules)

  operation = Fog::Compute::Google::Operations.new(:service => service)
                                              .get(data.name)
  operation.wait_for { ready? } unless async
  reload
end

#add_path_matchers(matchers_to_add, rules_to_add, async = true) ⇒ Object


70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/fog/compute/google/models/url_map.rb', line 70

def add_path_matchers(matchers_to_add, rules_to_add, async = true)
  requires :identity

  matchers = (path_matchers || []) + matchers_to_add
  rules = (host_rules || []) + rules_to_add
  data = service.patch_url_map(identity,
                               :host_rules => rules,
                               :path_matchers => matchers)

  operation = Fog::Compute::Google::Operations.new(:service => service)
                                              .get(data.name)
  operation.wait_for { ready? } unless async
  reload
end

#destroy(async = true) ⇒ Object


43
44
45
46
47
48
49
50
51
# File 'lib/fog/compute/google/models/url_map.rb', line 43

def destroy(async = true)
  requires :identity

  data = service.delete_url_map(identity)
  operation = Fog::Compute::Google::Operations.new(:service => service)
                                              .get(data.name)
  operation.wait_for { ready? } unless async
  operation
end

#invalidate_cache(path, host = nil, async = true) ⇒ Object


85
86
87
88
89
90
91
92
93
# File 'lib/fog/compute/google/models/url_map.rb', line 85

def invalidate_cache(path, host = nil, async = true)
  requires :identity

  data = service.invalidate_url_map_cache(identity, path, host)
  operation = Fog::Compute::Google::Operations.new(:service => service)
                                              .get(data.name)
  operation.wait_for { ready? } unless async
  operation
end

#ready?Boolean

Returns:

  • (Boolean)

95
96
97
98
99
100
101
# File 'lib/fog/compute/google/models/url_map.rb', line 95

def ready?
  service.get_url_map(name)
  true
rescue ::Google::Apis::ClientError => e
  raise e unless e.status_code == 404
  false
end

#reloadObject


103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/fog/compute/google/models/url_map.rb', line 103

def reload
  requires :name

  return unless data = begin
    collection.get(name)
  rescue Excon::Errors::SocketError
    nil
  end

  new_attributes = data.attributes
  merge_attributes(new_attributes)
  self
end

#saveObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/compute/google/models/url_map.rb', line 18

def save
  requires :identity, :default_service

  options = {
    :default_service => default_service,
    :description => description,
    :fingerprint => fingerprint,
    :host_rules => host_rules,
    :path_matchers => path_matchers,
    :tests => tests
  }

  # Update if creation_timestamp is set, create url map otherwise.
  data = nil
  if creation_timestamp
    data = service.update_url_map(identity, options)
  else
    data = service.insert_url_map(identity, options)
  end
  operation = Fog::Compute::Google::Operations.new(:service => service)
                                              .get(data.name)
  operation.wait_for { !pending? }
  reload
end

#validateObject


53
54
55
56
# File 'lib/fog/compute/google/models/url_map.rb', line 53

def validate
  requires :identity
  service.validate_url_map(identity, attributes)
end