File: cluster_parser.rb

package info (click to toggle)
ruby-fog-aws 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,816 kB
  • sloc: ruby: 68,587; makefile: 6
file content (143 lines) | stat: -rw-r--r-- 5,863 bytes parent folder | download | duplicates (5)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
module Fog
  module Parsers
    module Redshift
      module AWS
        class ClusterParser < Fog::Parsers::Base
          # :cluster_identifier - (String)
          # :node_type - (String)
          # :cluster_status - (String)
          # :modify_status - (String)
          # :master_username - (String)
          # :db_name - (String)
          # :endpoint - (Hash)
          #   :address - (String)
          #   :port - (Integer)
          # :cluster_create_time - (Time)
          # :automated_snapshot_retention_period - (Integer)
          # :cluster_security_groups - (Array)
          #   :cluster_security_group_name - (String)
          #   :status - (String)
          # :vpc_security_groups - (Array)
          #   :vpc_security_group_id - (String)
          #   :status - (String)
          # :cluster_parameter_groups - (Array)
          #   :parameter_group_name - (String)
          #   :parameter_apply_status - (String)
          # :cluster_subnet_group_name - (String)
          # :vpc_id - (String)
          # :availability_zone - (String)
          # :preferred_maintenance_window - (String)
          # :pending_modified_values - (Hash)
          #   :master_user_password - (String)
          #   :node_type - (String)
          #   :number_of_nodes - (Integer)
          #   :cluster_type - (String)
          #   :cluster_version - (String)
          #   :automated_snapshot_retention_period - (Integer)
          # :cluster_version - (String)
          # :allow_version_upgrade - (Boolean)
          # :number_of_nodes - (Integer)
          # :publicly_accessible - (Boolean)
          # :encrypted - (Boolean)
          # :restore_status - (Hash)
          #   :status - (String)
          #   :current_restore_rate_in_mega_bytes_per_second - (Numeric)
          #   :snapshot_size_in_mega_bytes - (Integer)
          #   :progress_in_mega_bytes - (Integer)
          #   :elapsed_time_in_seconds - (Integer)
          #   :estimated_time_to_completion_in_seconds - (Integer)

          def reset
            @cluster = fresh_cluster
          end

          def fresh_cluster
            { 'ClusterParameterGroups' => [], 'ClusterSecurityGroups' => [], 'VpcSecurityGroups' => [],
              'EndPoint' => {}, 'PendingModifiedValues'=> {}, 'RestoreStatus' => {}}
          end

          def start_element(name, attrs = [])
            super
            case name
            when 'ClusterSecurityGroups'
              @in_cluster_security_groups = true
              @cluster_security_group = {}
            when 'ClusterParameterGroups'
              @cluster_parameter_group = {}
            when 'VpcSecurityGroups'
              @in_vpc_security_groups = true
              @vpc_security_group = {}
            when 'PendingModifiedValues'
              @in_pending_modified_values = true
            end
          end

          def end_element(name)
            case name
            when 'AvailabilityZone', 'ClusterIdentifier', 'ClusterStatus', 'ClusterSubnetGroupName', 'DBName',
              'MasterUsername', 'ModifyStatus', 'PreferredMaintenanceWindow', 'VpcId'
              @cluster[name] = value
            when 'ClusterCreateTime'
              @cluster[name] = Time.parse(value)
            when 'AllowVersionUpgrade', 'Encrypted', 'PubliclyAccessible'
              @cluster[name] = (value == "true")
            when 'Address'
              @cluster['EndPoint'][name] = value
            when 'Port'
              @cluster['EndPoint'][name] = value.to_i
            when 'NodeType', 'ClusterVersion'
              if @in_pending_modified_values
                @cluster['PendingModifiedValues'][name] = value
              else
                @cluster[name] = value
              end
            when 'NumberOfNodes', 'AutomatedSnapshotRetentionPeriod'
              if @in_pending_modified_values
                @cluster['PendingModifiedValues'][name] = value.to_i
              else
                @cluster[name] = value.to_i
              end
            when 'MasterUserPassword', 'ClusterType'
              @cluster['PendingModifiedValues'][name] = value
            when 'Status'
              if @in_vpc_security_groups
                @vpc_security_group[name] = value
              elsif @in_cluster_security_groups
                @cluster_security_group[name] = value
              else
                @cluster['RestoreStatus'][name] = value
              end
            when 'ParameterGroupName', 'ParameterApplyStatus'
              @cluster_parameter_group[name] = value
            when 'ClusterSecurityGroupName'
              @cluster_security_group[name] = value
            when 'VpcSecurityGroupId'
              @vpc_security_group[name] = value
            when 'SnapshotSizeInMegaBytes', 'ProgressInMegaBytes', 'ElapsedTimeInSeconds', 'EstimatedTimeToCompletionInSeconds'
              @cluster['RestoreStatus'][name] = value.to_i
            when 'CurrentRestoreRateInMegaBytesPerSecond'
              @cluster['RestoreStatus'][name] = value.to_f

            when 'ClusterSecurityGroups'
              @in_cluster_security_groups = false
            when 'VpcSecurityGroups'
              @in_vpc_security_groups = false
            when 'PendingModifiedValues'
              @in_pending_modified_values = false

            when 'ClusterParameterGroup'
              @cluster['ClusterParameterGroups'] << {name => @cluster_parameter_group}
              @cluster_parameter_group = {}
            when 'ClusterSecurityGroup'
              @cluster['ClusterSecurityGroups'] << {name => @cluster_security_group}
              @cluster_security_group = {}
            when 'VpcSecurityGroup'
              @cluster['VpcSecurityGroups'] << {name => @vpc_security_group}
              @vpc_security_group = {}
            end
          end
        end
      end
    end
  end
end