forked from fog/fog-google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl_map.rb
95 lines (80 loc) · 2.66 KB
/
url_map.rb
1
2
3
4
5
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
require 'fog/core/model'
module Fog
module Compute
class Google
class UrlMap < Fog::Model
identity :name
attribute :kind, :aliases => 'kind'
attribute :creationTimestamp, :aliases => 'creation_timestamp'
attribute :defaultService, :aliases => ['default_service', :default_service]
attribute :description, :aliases => 'description'
attribute :fingerprint, :aliases => 'fingerprint'
attribute :hostRules, :aliases => 'host_rules'
attribute :id, :aliases => 'id'
attribute :pathMatchers, :aliases => 'path_matchers'
attribute :self_link, :aliases => 'selfLink'
attribute :tests, :aliases => 'tests'
def save
requires :name, :defaultService
options = {
'defaultService' => defaultService,
'description' => description,
'fingerprint' => fingerprint,
'hostRules' => hostRules,
'pathMatchers' => pathMatchers,
'tests' => tests
}
data = service.insert_url_map(name, options).body
operation = Fog::Compute::Google::Operations.new(:service => service).get(data['name'])
operation.wait_for { !pending? }
reload
end
def destroy(async=true)
requires :name
operation = service.delete_url_map(name)
if not async
Fog.wait_for do
operation = service.get_global_operation(operation.body["name"])
operation.body["status"] == "DONE"
end
end
operation
end
def validate
service.validate_url_map self
end
def add_host_rules hostRules
hostRules= [hostRules] unless hostRules.class == Array
service.update_url_map(self, hostRules)
reload
end
def add_path_matchers(pathMatchers, hostRules)
pathMatchers = [pathMatchers] unless pathMatchers.class == Array
hostRules=[hostRules] unless hostRules.class == Array
service.update_url_map(self, hostRules, pathMatchers)
reload
end
def ready?
begin
service.get_url_map(self.name)
true
rescue Fog::Errors::NotFound
false
end
end
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
RUNNING_STATE ="READY"
end
end
end
end