Class: Fog::IBM::Mock

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

Class Method Summary collapse

Class Method Details

.create_address(location_id, offering_id, vlan_id) ⇒ Object



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

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



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

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



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

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



86
87
88
# File 'lib/fog/ibm.rb', line 86

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

.hostnameObject



76
77
78
# File 'lib/fog/ibm.rb', line 76

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



58
59
60
# File 'lib/fog/ibm.rb', line 58

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

.ip_addressObject



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

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



94
95
96
# File 'lib/fog/ibm.rb', line 94

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

.launch_timeObject

Miliseconds since epoch



81
82
83
# File 'lib/fog/ibm.rb', line 81

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

.ownerObject



90
91
92
# File 'lib/fog/ibm.rb', line 90

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

.primary_ipObject



64
65
66
# File 'lib/fog/ibm.rb', line 64

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

.private_image(name, description) ⇒ Object



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

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