File: operation.rb

package info (click to toggle)
ruby-fog-google 1.19.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,568 kB
  • sloc: ruby: 16,775; makefile: 3
file content (73 lines) | stat: -rw-r--r-- 2,063 bytes parent folder | download | duplicates (4)
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
module Fog
  module Compute
    class Google
      class Operation < Fog::Model
        identity :name

        attribute :kind
        attribute :id
        attribute :client_operation_id, :aliases => "clientOperationId"
        attribute :creation_timestamp, :aliases => "creationTimestamp"
        attribute :end_time, :aliases => "endTime"
        attribute :error
        attribute :http_error_message, :aliases => "httpErrorMessage"
        attribute :http_error_status_code, :aliases => "httpErrorStatusCode"
        attribute :insert_time, :aliases => "insertTime"
        attribute :operation_type, :aliases => "operationType"
        attribute :progress
        attribute :region
        attribute :self_link, :aliases => "selfLink"
        attribute :start_time, :aliases => "startTime"
        attribute :status
        attribute :status_message, :aliases => "statusMessage"
        attribute :target_id, :aliases => "targetId"
        attribute :target_link, :aliases => "targetLink"
        attribute :user
        attribute :warnings
        attribute :zone

        def ready?
          status == DONE_STATE
        end

        def pending?
          status == PENDING_STATE
        end

        def region_name
          region.nil? ? nil : region.split("/")[-1]
        end

        def zone_name
          zone.nil? ? nil : zone.split("/")[-1]
        end

        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

        def reload
          requires :identity

          data = collection.get(identity, zone, region)
          new_attributes = data.attributes
          merge_attributes(new_attributes)
          self
        end

        PENDING_STATE = "PENDING".freeze
        RUNNING_STATE = "RUNNING".freeze
        DONE_STATE = "DONE".freeze
      end
    end
  end
end