Class: Fog::Google::Compute::Operation
- Inherits:
-
Model
- Object
- Model
- Fog::Google::Compute::Operation
show all
- Defined in:
- lib/fog/google/compute/models/operation.rb
Defined Under Namespace
Classes: ErrorInfo, QuotaInfo
Constant Summary
collapse
- PENDING_STATE =
"PENDING".freeze
- RUNNING_STATE =
"RUNNING".freeze
- DONE_STATE =
"DONE".freeze
Instance Method Summary
collapse
Instance Method Details
#destroy ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
|
# File 'lib/fog/google/compute/models/operation.rb', line 150
def destroy
requires :identity
if zone
service.delete_zone_operation(zone, identity)
elsif region
service.delete_region_operation(region, identity)
else
service.delete_global_operation(identity)
end
true
end
|
#error? ⇒ Boolean
97
98
99
|
# File 'lib/fog/google/compute/models/operation.rb', line 97
def error?
! error.nil?
end
|
#error_info_class(code) ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/fog/google/compute/models/operation.rb', line 121
def error_info_class(code)
case code
when "QUOTA_EXCEEDED" then QuotaInfo
else
ErrorInfo
end
end
|
#error_infos ⇒ Object
Returns an array of ErrorInfo objects derived from the raw error hash.
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/fog/google/compute/models/operation.rb', line 130
def error_infos
return [] unless error.is_a?(Hash)
return [] unless errors.is_a?(Array)
errors.map do |err|
klass = error_info_class(err[:code])
klass.new(
code: err[:code],
message: err[:message],
location: err[:location],
error_details: err[:error_details]
)
end
end
|
#errors ⇒ Object
101
102
103
|
# File 'lib/fog/google/compute/models/operation.rb', line 101
def errors
error? ? error[:errors] : nil
end
|
#pending? ⇒ Boolean
109
110
111
|
# File 'lib/fog/google/compute/models/operation.rb', line 109
def pending?
status == PENDING_STATE
end
|
#primary_error ⇒ Object
Convenience helper: return the first error (most Google APIs provide only one).
146
147
148
|
# File 'lib/fog/google/compute/models/operation.rb', line 146
def primary_error
error_infos.first
end
|
#ready? ⇒ Boolean
105
106
107
|
# File 'lib/fog/google/compute/models/operation.rb', line 105
def ready?
status == DONE_STATE
end
|
#region_name ⇒ Object
113
114
115
|
# File 'lib/fog/google/compute/models/operation.rb', line 113
def region_name
region.nil? ? nil : region.split("/")[-1]
end
|
#reload ⇒ Object
163
164
165
166
167
168
169
170
|
# File 'lib/fog/google/compute/models/operation.rb', line 163
def reload
requires :identity
data = collection.get(identity, zone, region)
new_attributes = data.attributes
merge_attributes(new_attributes)
self
end
|
#zone_name ⇒ Object
117
118
119
|
# File 'lib/fog/google/compute/models/operation.rb', line 117
def zone_name
zone.nil? ? nil : zone.split("/")[-1]
end
|