Class: Fog::IBM::Mock

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

Class Method Summary collapse

Class Method Details

.create_address(location_id, offering_id, vlan_id) ⇒ Object



159
160
161
162
163
164
165
166
167
168
# File 'lib/fog/ibm/core.rb', line 159

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



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

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



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

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 milliseconds since epoch



83
84
85
# File 'lib/fog/ibm/core.rb', line 83

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

.hostnameObject



73
74
75
# File 'lib/fog/ibm/core.rb', line 73

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



55
56
57
# File 'lib/fog/ibm/core.rb', line 55

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

.ip_addressObject



65
66
67
68
69
70
71
# File 'lib/fog/ibm/core.rb', line 65

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



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

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

.launch_timeObject

Milliseconds since epoch



78
79
80
# File 'lib/fog/ibm/core.rb', line 78

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

.ownerObject



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

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

.primary_ipObject



61
62
63
# File 'lib/fog/ibm/core.rb', line 61

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

.private_image(name, description) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/fog/ibm/core.rb', line 95

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