Class: Fog::IBM::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/rackspace-fog/ibm.rb

Class Method Summary collapse

Class Method Details

.create_address(location_id, offering_id, vlan_id) ⇒ Object



161
162
163
164
165
166
167
168
169
170
# File 'lib/rackspace-fog/ibm.rb', line 161

def create_address(location_id, offering_id, vlan_id)
  # TODO: Figure out vlan handling
  {
    "id"        => Fog::IBM::Mock.id,
    "location"  => location_id,
    "offeringId"=> offering_id,
    "ip"        => "",
    "state"     => 0
  }
end

.create_instance(name, image_id, instance_type, location, options) ⇒ Object



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
# File 'lib/rackspace-fog/ibm.rb', line 109

def create_instance(name, image_id, instance_type, location, options)
  {
    "name"          => name,
    "location"      => location,
    "keyName"       => options[:key_name],
    "primaryIP"     => Fog::IBM::Mock.primary_ip,
    "productCodes"  => [],
    "requestId"     => Fog::IBM::Mock.request_id,
    "imageId"       => image_id,
    "launchTime"    => Fog::IBM::Mock.launch_time,
    "id"            => Fog::IBM::Mock.instance_id,
    "volumes"       => [],
    "isMiniEphemeral" => "false",
    "instanceType"  => instance_type,
    "diskSize"      => "60",
    "requestName"   => "",
    "secondaryIP"   => [],
    "status"        => 1,
    "software"      => [
      { "name"=>"SUSE Linux Enterprise Server",
        "type"=>"OS",
        "version"=>"11 SP1" }
    ],
    "expirationTime"=> Fog::IBM::Mock.expiry_time,
    "owner"         => Fog::IBM::Mock.owner
  }
end

.create_volume(name, format, location_id, size, offering_id) ⇒ Object



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/rackspace-fog/ibm.rb', line 137

def create_volume(name, format, location_id, size, offering_id)
  {
    "instanceId"  => "0",
    "state"       => 1,
    "size"        => size,
    "offeringId"  => offering_id,
    "ioPrice" => {
      "rate"  => 0.11,
      "unitOfMeasure" => "CNT",
      "countryCode"   => "897",
      "effectiveDate" => Fog::IBM::Mock.launch_time,
      "currencyCode"  => "USD",
      "pricePerQuantity"  => 1
    },
    "owner"       => Fog::IBM::Mock.owner,
    "createdTime" => Fog::IBM::Mock.launch_time,
    "location"    => location_id,
    "productCodes"=> [],
    "format"      => format,
    "name"        => name,
    "id"          => Fog::IBM::Mock.id,
  }
end

.expiry_timeObject

1 year from now, in miliseconds since epoch



85
86
87
# File 'lib/rackspace-fog/ibm.rb', line 85

def expiry_time
  ((Time.now.tv_sec + 31556926) * 1000).to_i
end

.hostnameObject



75
76
77
# File 'lib/rackspace-fog/ibm.rb', line 75

def hostname
  "vhost" + Fog::Mock.random_numbers(3).to_i.to_s + ".fake.compute.ihost.com"
end

.idObject Also known as: instance_id, request_id



57
58
59
# File 'lib/rackspace-fog/ibm.rb', line 57

def id
  Fog::Mock.random_numbers(7).to_i.to_s
end

.ip_addressObject



67
68
69
70
71
72
73
# File 'lib/rackspace-fog/ibm.rb', line 67

def ip_address
  ip = []
  4.times do
    ip << Fog::Mock.random_numbers(rand(3) + 1).to_i.to_s # remove leading 0
  end
  ip.join('.')
end

.key_materialObject



93
94
95
# File 'lib/rackspace-fog/ibm.rb', line 93

def key_material
  OpenSSL::PKey::RSA.generate(1024)
end

.launch_timeObject

Miliseconds since epoch



80
81
82
# File 'lib/rackspace-fog/ibm.rb', line 80

def launch_time
  (Time.now.tv_sec * 1000).to_i
end

.ownerObject



89
90
91
# File 'lib/rackspace-fog/ibm.rb', line 89

def owner
  "user" + Fog::Mock.random_numbers(3).to_i.to_s + "@company.com"
end

.primary_ipObject



63
64
65
# File 'lib/rackspace-fog/ibm.rb', line 63

def primary_ip
  { "type" => 0, "ip" => Fog::IBM::Mock.ip_address, "hostname" => Fog::IBM::Mock.hostname }
end

.private_image(name, description) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/rackspace-fog/ibm.rb', line 97

def private_image(name, description)
  {
    "name"        => name,
    "createdTime" => Fog::IBM::Mock.launch_time,
    "productCodes"=> [],
    "id"          => Fog::IBM::Mock.instance_id,
    "description" => description,
    "visibility"  => "PRIVATE",
    "state"       => 0
  }
end