Module: Fog::Rackspace::MockData

Constant Summary collapse

NOT_FOUND_ID =
"NOT-FOUND"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ipv4_addressObject


210
211
212
# File 'lib/fog/rackspace/mock_data.rb', line 210

def self.ipv4_address
  4.times.map { Fog::Mock.random_numbers(3) }.join(".")
end

.ipv6_addressObject


214
215
216
# File 'lib/fog/rackspace/mock_data.rb', line 214

def self.ipv6_address
  8.times.map { Fog::Mock.random_hex(4) }.join(":")
end

.keep(hash, *keys) ⇒ Object


218
219
220
221
222
# File 'lib/fog/rackspace/mock_data.rb', line 218

def self.keep(hash, *keys)
  {}.tap do |kept|
    keys.each { |k| kept[k] = hash[k] if hash.key?(k) }
  end
end

.slice(hash, *keys) ⇒ Object


224
225
226
227
228
# File 'lib/fog/rackspace/mock_data.rb', line 224

def self.slice(hash, *keys)
  hash.dup.tap do |sliced|
    keys.each { |k| sliced.delete(k) }
  end
end

.stringify(message) ⇒ Object


234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/fog/rackspace/mock_data.rb', line 234

def self.stringify(message)
  case message
  when Symbol
    message.to_s
  when Hash
    result = Hash.new
    message.each do |key, value|
      nk = stringify(key)
      nv = stringify(value)
      result[nk] = nv
    end
    result
  else
    message
  end
end

.uuidObject


206
207
208
# File 'lib/fog/rackspace/mock_data.rb', line 206

def self.uuid
  [8,4,4,4,12].map { |i| Fog::Mock.random_hex(i) }.join("-")
end

.zulu_timeObject


230
231
232
# File 'lib/fog/rackspace/mock_data.rb', line 230

def self.zulu_time
  Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
end

Instance Method Details

#dataObject


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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/fog/rackspace/mock_data.rb', line 6

def data
  @@data ||= Hash.new do |hash, key|
    hash[key] = begin

      #Compute V2
      flavor_id  = Fog.credentials[:rackspace_flavor_id] ||= '3'
      image_id   = Fog.credentials[:rackspace_image_id] ||= Fog::Rackspace::MockData.uuid
      image_name = Fog::Mock.random_letters(6)
      network_id = Fog::Rackspace::MockData.uuid
      user_id    = Fog::Mock.random_numbers(6).to_s

      flavor = {
        "OS-FLV-EXT-DATA:ephemeral" => 4,
        "disk"  => 20,
        "id"    => flavor_id,
        "links" => [
          {
            "href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/flavors/#{flavor_id}",
            "rel"  => "self"
          },
          {
            "href" => "https://dfw.servers.api.rackspacecloud.com/010101/flavors/#{flavor_id}",
            "rel"  => "bookmark"
          }
        ],
        "name"        => "512MB Standard Instance",
        "ram"         => 512,
        "rxtx_factor" => 2.0,
        "swap"        => 512,
        "vcpus"       => 1
      }

      image = {
        "OS-DCF:diskConfig" => "AUTO",
        "created" => "2012-02-28T19:38:57Z",
        "id" => image_id,
        "name" => image_name,
        "links" => [
          {
            "href" => "https://dfw.servers.api.rackspacecloud.com/v2/010101/images/#{image_id}",
            "rel"  => "self"
          },
          {
            "href" => "https://dfw.servers.api.rackspacecloud.com/010101/images/#{image_id}",
            "rel"  => "bookmark"
          },
          {
            "href" => "https://dfw.servers.api.rackspacecloud.com/010101/images/#{image_id}",
            "rel"  => "alternate",
            "type" => "application/vnd.openstack.image"
          }
        ],
        "metadata" => {
          "arch" => "x86-64",
          "auto_disk_config" => "True",
          "com.rackspace__1__build_core" => "1",
          "com.rackspace__1__build_managed" => "0",
          "com.rackspace__1__build_rackconnect" => "0",
          "com.rackspace__1__options" => "0",
          "com.rackspace__1__visible_core" => "1",
          "com.rackspace__1__visible_managed" => "0",
          "com.rackspace__1__visible_rackconnect" => "0",
          "image_type" => "base",
          "org.openstack__1__architecture" => "x64",
          "org.openstack__1__os_distro" => "org.ubuntu",
          "org.openstack__1__os_version" => "11.10",
          "os_distro" => "ubuntu",
          "os_type" => "linux",
          "os_version" => "11.10",
          "rax_managed" => "false",
          "rax_options" => "0"
        },
        "minDisk"  => 10,
        "minRam"   => 256,
        "progress" => 100,
        "status"   => "ACTIVE",
        "updated"  => "2012-02-28T19:39:05Z"
      }

      network = {
        'id' => network_id,
        'label' => 'network label',
        'cidr' => '192.168.0.0/24'
      }

      key_pair = {
        'public_key'  => "ssh-rsa ".concat(Fog::Mock.random_letters(372)).concat(" Generated by Nova\n"),
        'private_key' => "-----BEGIN RSA PRIVATE KEY-----\n".concat(Fog::Mock.random_letters(1635)).concat("\n-----END RSA PRIVATE KEY-----\n"),
        'user_id'     => user_id,
        'name'        => Fog::Mock.random_letters(32),
        'fingerprint' => "00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"
      }

      #Block Storage
      volume_type1_id = Fog::Mock.random_numbers(3).to_s
      volume_type2_id = Fog::Mock.random_numbers(3).to_s

      volume_type1 = {
        "id" => volume_type1_id,
        "name" => "SATA",
        "extra_specs" => {}
      }

      volume_type2 = {
        "id" => volume_type2_id,
        "name" => "SSD",
        "extra_specs" => {}
      }

      #AutoScale
      launch_config = {
        "args" => {
          "loadBalancers" => [
            {
              "port" => 8080,
              "loadBalancerId" => 9099
            }
          ],
          "server" => {
            "name" => "autoscale_server",
            "imageRef" => "0d589460-f177-4b0f-81c1-8ab8903ac7d8",
            "flavorRef" => "2",
            "OS-DCF =>diskConfig" => "AUTO",
            "metadata" => {
              "build_config" => "core",
              "meta_key_1" => "meta_value_1",
              "meta_key_2" => "meta_value_2"
            },
            "networks" => [
              {
                "uuid" => "11111111-1111-1111-1111-111111111111"
              },
              {
                "uuid" => "00000000-0000-0000-0000-000000000000"
              }
            ],
            "personality" => [
              {
                "path" => "/root/.csivh",
                "contents" => "VGhpcyBpcyBhIHRlc3QgZmlsZS4="
              }
            ]
          }
        },
        "type" => "launch_server"
      }

      group_config = {
        "max_entities" => 10,
        "cooldown" => 360,
        "name" => "testscalinggroup198547",
        "min_entities" => 0,
        "metadata" => {
          "gc_meta_key_2" => "gc_meta_value_2",
          "gc_meta_key_1" => "gc_meta_value_1"
        }
      }

      policy = {
        "cooldown" => 0,
        "type" => "webhook",
        "name" => "scale up by 1",
        "change" => 1
      }

      webhook = {
        "name" => "webhook name",
        "metadata" => {'foo' => 'bar'}
      }

      mock_data = {
        #Compute V2
        :flavors  => Hash.new { |h,k| h[k] = flavor  unless [NOT_FOUND_ID, '0'].include?(k) },
        :images   => Hash.new { |h,k| h[k] = image   unless [NOT_FOUND_ID, '0'].include?(k) },
        :networks => Hash.new { |h,k| h[k] = network unless [NOT_FOUND_ID, '0'].include?(k) },
        :keys     => [],
        :keypair  => key_pair,
        :keypairs => [],
        :servers  => {},

        #Block Storage
        :volumes            => {},
        :snapshots          => {},
        :volume_attachments => [],
        :volume_types       => {volume_type1_id => volume_type1, volume_type2_id => volume_type2},

        #Autoscale
        :autoscale_groups => {}
      }

      # seed with initial data
      mock_data[:flavors][flavor_id] = flavor
      mock_data[:images][image_id] = image
      mock_data[:networks][network_id] = network

      mock_data
    end
  end[@rackspace_api_key]
end