add_security_group(server_id, sg_name)
click to toggle source
def add_security_group(server_id, sg_name)
response = Excon::Response.new
if server = self.data[:servers][server_id]
data = {"name" => "#{sg_name}"}
if server['security_groups']
server['security_groups'] << data
else
server['security_groups'] = data
end
response.status = 202
else
raise Fog::Compute::HPV2::NotFound
end
response
end
allocate_address()
click to toggle source
def allocate_address
response = Excon::Response.new
response.status = 200
data = {
'instance_id' => Fog::HP::Mock.uuid.to_s,
'ip' => Fog::HP::Mock.ip_address,
'fixed_ip' => Fog::HP::Mock.ip_address,
'id' => Fog::HP::Mock.uuid.to_s
}
self.data[:last_modified][:addresses][data['id']] = Time.now
self.data[:addresses][data['id']] = data
response.body = { 'floating_ip' => data }
response
end
associate_address(server_id, ip_address)
click to toggle source
def associate_address(server_id, ip_address)
response = Excon::Response.new
if server = self.data[:servers][server_id]
data = {"version"=>4, "addr"=>"#{ip_address}"}
if server['addresses']['custom']
server['addresses']['custom'] << data
else
server['addresses']['custom'] = data
end
response.status = 202
else
response.status = 500
raise(Excon::Errors.status_error({:expects => 202}, response))
end
response
end
create_image(server_id, name, metadata = {})
click to toggle source
def create_image(server_id, name, metadata = {})
response = Excon::Response.new
if list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
response.status = 202
image_id = Fog::HP::Mock.uuid.to_s
data = {
'id' => image_id,
'server' => {"id"=>server_id, "links"=>[{"href"=>"http://nova1:8774/v1.1/servers/#{server_id}", "rel"=>"bookmark"}]},
'links' => [{"href"=>"http://nova1:8774/v1.1/tenantid/images/#{image_id}", "rel"=>"self"}, {"href"=>"http://nova1:8774/tenantid/images/#{image_id}", "rel"=>"bookmark"}],
'metadata' => metadata || {},
'name' => name || "image_#{rand(999)}",
'progress' => 0,
'minDisk' => 0,
'minRam' => 0,
'status' => 'SAVING',
'updated' => "2012-01-01T13:32:20Z",
'created' => "2012-01-01T13:32:20Z"
}
self.data[:last_modified][:images][data['id']] = Time.now
self.data[:images][data['id']] = data
response.headers = {'Content-Length' => '0', 'Content-Type' => 'text/html; charset=UTF-8', 'Date' => Time.now, 'Location' => "http://nova1:8774/v1.1/images/#{image_id}"}
response.body = ''
response
else
raise Fog::Compute::HPV2::NotFound
end
end
create_key_pair(key_name, public_key = nil)
click to toggle source
def create_key_pair(key_name, public_key = nil)
response = Excon::Response.new
response.status = 200
private_key, new_public_key = Fog::HP::Mock.key_material
new_public_key = public_key if public_key
data = {
'public_key' => new_public_key,
'fingerprint' => Fog::HP::Mock.key_fingerprint,
'name' => key_name
}
self.data[:last_modified][:key_pairs][key_name] = Time.now
self.data[:key_pairs][key_name] = { 'keypair' => data }
if public_key
response.body = { 'keypair' => data.merge({'user_id' => Fog::HP::Mock.user_id,}) }
else
response.body = { 'keypair' => data.merge({'private_key' => private_key, 'user_id' => Fog::HP::Mock.user_id}) }
end
response
end
create_persistent_server(name, flavor_id, block_device_mapping, options = {})
click to toggle source
def create_persistent_server(name, flavor_id, block_device_mapping, options = {})
response = Excon::Response.new
if block_device_mapping && !block_device_mapping.empty?
if options['security_groups']
sec_group_name = options['security_groups'][0]
else
sec_group_name = 'default'
end
addresses = {'hpcloud' => [{'version'=>4, 'addr'=>Fog::HP::Mock.ip_address}] }
if networks = options['networks']
networks.each do |_|
addresses["Network #{rand(100)}"] = [{'version'=>4, 'addr'=>Fog::HP::Mock.ip_address}]
end
end
id = Fog::HP::Mock.uuid.to_s
data = {
'addresses' => addresses,
'flavor' => {"id"=>"#{flavor_id}", "links"=>[{"href"=>"http://nova1:8774/admin/flavors/#{flavor_id}", "rel"=>"bookmark"}]},
'id' => id,
'links' => [{"href"=>"http://nova1:8774/v1.1/admin/servers/5", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/servers/5", "rel"=>"bookmark"}],
'hostId' => '123456789ABCDEF01234567890ABCDEF',
'metadata' => options['metadata'] || {},
'name' => name || "server_#{rand(999)}",
'accessIPv4' => options['accessIPv4'] || '',
'accessIPv6' => options['accessIPv6'] || '',
'progress' => 0,
'status' => 'BUILD',
'created' => '2012-01-01T13:32:20Z',
'updated' => '2012-01-01T13:32:20Z',
'user_id' => Fog::HP::Mock.user_id.to_s,
'tenant_id' => Fog::Mock.random_numbers(14).to_s,
'config_drive' => '',
'security_groups' => [{'name'=>"#{sec_group_name}"}],
'key_name' => options['key_name'] || ''
}
self.data[:last_modified][:servers][data['id']] = Time.now
self.data[:servers][data['id']] = data
response.headers = {'Content-Length' => '0', 'Content-Type' => 'text/html; charset=UTF-8', 'Date' => Time.now, 'Location' => "http://nova1:8774/v1.1/servers/#{id}"}
response.body = { 'server' => data.merge({'adminPass' => 'password'}) }
response.status = 202
response
else
response.status = 400
raise(Excon::Errors::BadRequest, 'No boot volume or boot image specified')
end
end
create_server(name, flavor_id, image_id, options = {})
click to toggle source
def create_server(name, flavor_id, image_id, options = {})
response = Excon::Response.new
response.status = 202
if options['security_groups']
sec_group_name = options['security_groups'][0]
else
sec_group_name = 'default'
end
addresses = {'hpcloud' => [{'version'=>4, 'addr'=>Fog::HP::Mock.ip_address}] }
if networks = options['networks']
networks.each do |_|
addresses["Network #{rand(100)}"] = [{'version'=>4, 'addr'=>Fog::HP::Mock.ip_address}]
end
end
id = Fog::HP::Mock.uuid.to_s
data = {
'addresses' => addresses,
'flavor' => {"id"=>"#{flavor_id}", "links"=>[{"href"=>"http://nova1:8774/admin/flavors/#{flavor_id}", "rel"=>"bookmark"}]},
'id' => id,
'image' => {"id"=>"#{image_id}", "links"=>[{"href"=>"http://nova1:8774/admin/images/#{image_id}", "rel"=>"bookmark"}]},
'links' => [{"href"=>"http://nova1:8774/v1.1/admin/servers/#{id}", "rel"=>"self"}, {"href"=>"http://nova1:8774/admin/servers/#{id}", "rel"=>"bookmark"}],
'hostId' => "123456789ABCDEF01234567890ABCDEF",
'metadata' => options['metadata'] || {},
'name' => name || "server_#{rand(999)}",
'accessIPv4' => options['accessIPv4'] || "",
'accessIPv6' => options['accessIPv6'] || "",
'progress' => 0,
'status' => 'ACTIVE',
'created' => "2012-01-01T13:32:20Z",
'updated' => "2012-01-01T13:32:20Z",
'user_id' => Fog::HP::Mock.user_id.to_s,
'tenant_id' => Fog::Mock.random_numbers(14).to_s,
'config_drive' => "",
'security_groups' => [{"name"=>"#{sec_group_name}"}],
'key_name' => options['key_name'] || ""
}
self.data[:last_modified][:servers][data['id']] = Time.now
self.data[:servers][data['id']] = data
response.headers = {'Content-Length' => '0', 'Content-Type' => 'text/html; charset=UTF-8', 'Date' => Time.now, 'Location' => "http://nova1:8774/v1.1/servers/#{id}"}
response.body = { 'server' => data.merge({'adminPass' => 'password'}) }
response
end
data()
click to toggle source
def data
self.class.data[@hp_access_key]
end
delete_image(image_id)
click to toggle source
def delete_image(image_id)
response = Excon::Response.new
if image = list_images_detail.body['images'].find {|_| _['id'] == image_id}
if image['status'] == 'SAVING'
response.status = 409
raise(Excon::Errors.status_error({:expects => 202}, response))
else
self.data[:last_modified][:images].delete(image_id)
self.data[:images].delete(image_id)
response.status = 202
end
response
else
raise Fog::Compute::HPV2::NotFound
end
end
delete_key_pair(key_name)
click to toggle source
def delete_key_pair(key_name)
response = Excon::Response.new
if self.data[:key_pairs][key_name]
self.data[:last_modified][:key_pairs].delete(key_name)
self.data[:key_pairs].delete(key_name)
response.status = 202
response
else
raise Fog::Compute::HPV2::NotFound
end
end
delete_server(server_id)
click to toggle source
def delete_server(server_id)
response = Excon::Response.new
if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
if server['status'] == 'BUILD'
response.status = 409
raise(Excon::Errors.status_error({:expects => 202}, response))
else
self.data[:last_modified][:servers].delete(server_id)
self.data[:servers].delete(server_id)
response.status = 204
end
response
else
raise Fog::Compute::HPV2::NotFound
end
end
disassociate_address(server_id, ip_address)
click to toggle source
def disassociate_address(server_id, ip_address)
response = Excon::Response.new
if server = self.data[:servers][server_id]
data = server['addresses']['custom'].reject {|a| a['addr'] == ip_address}
self.data[:servers][server_id]['addresses']['custom'] = data
response.status = 202
else
response.status = 500
raise(Excon::Errors.status_error({:expects => 202}, response))
end
response
end
get_address(address_id)
click to toggle source
def get_address(address_id)
response = Excon::Response.new
if address = self.data[:addresses][address_id]
response.status = 200
response.body = { 'floating_ip' => address }
response
else
raise Fog::Compute::HPV2::NotFound
end
end
get_console_output(server_id, num_lines)
click to toggle source
def get_console_output(server_id, num_lines)
output = ""
response = Excon::Response.new
if list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
(1..num_lines).each {|i| output += "Console Output Line #{i} \r\n"}
response.body = { 'output' => output }
response.status = 200
else
raise Fog::Compute::HPV2::NotFound
end
response
end
get_flavor_details(flavor_id)
click to toggle source
def get_flavor_details(flavor_id)
response = Excon::Response.new
flavor = {
'1' => { 'name' => 'standard.xsmall', 'ram' => 1024, 'disk' => 30, 'id' => '1', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 1, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/1", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/1", "rel"=>"bookmark"}] },
'2' => { 'name' => 'standard.small', 'ram' => 2048, 'disk' => 60, 'id' => '2', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 2, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/2", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/2", "rel"=>"bookmark"}] },
'3' => { 'name' => 'standard.medium', 'ram' => 4096, 'disk' => 120, 'id' => '3', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 2, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/3", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/3", "rel"=>"bookmark"}] },
'4' => { 'name' => 'standard.large', 'ram' => 8192, 'disk' => 240, 'id' => '4', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 4, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/4", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/4", "rel"=>"bookmark"}] },
'5' => { 'name' => 'standard.xlarge', 'ram' => 16384, 'disk' => 480, 'id' => '5', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 4, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/5", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/5", "rel"=>"bookmark"}] },
'6' => { 'name' => 'standard.2xlarge', 'ram' => 32768, 'disk' => 960, 'id' => '6', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 8, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/6", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/6", "rel"=>"bookmark"}] }
}[flavor_id]
if flavor
response.status = 200
response.body = {
'flavor' => flavor
}
response
else
raise Fog::Compute::HPV2::NotFound
end
end
get_image_details(image_id)
click to toggle source
def get_image_details(image_id)
response = Excon::Response.new
if image = list_images_detail.body['images'].find {|_| _['id'] == image_id}
response.status = [200, 203][rand(1)]
response.body = { 'image' => image }
response
else
raise Fog::Compute::HPV2::NotFound
end
end
get_key_pair(key_name)
click to toggle source
def get_key_pair(key_name)
response = Excon::Response.new
if key_pair = self.data[:key_pairs][key_name]
response.status = 200
response.body = { 'keypair' => key_pair['keypair'] }
response
else
raise Fog::Compute::HPV2::NotFound
end
end
get_server_details(server_id)
click to toggle source
def get_server_details(server_id)
response = Excon::Response.new
if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
response.status = 200
response.body = { 'server' => server }
response
else
raise Fog::Compute::HPV2::NotFound
end
end
get_vnc_console(server_id, type='novnc')
click to toggle source
def get_vnc_console(server_id, type='novnc')
output = {
'type' => type,
'url' => 'https://region.compute.hpcloud.com/vnc_auto.html?token=123ABX234'
}
response = Excon::Response.new
if list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
response.body = { 'console' => output }
response.status = 200
else
raise Fog::Compute::HPV2::NotFound
end
response
end
get_windows_password(server_id)
click to toggle source
def get_windows_password(server_id)
private_key = OpenSSL::PKey::RSA.generate(1024)
public_key = private_key.public_key
encoded_password = encrypt_using_public_key("Passw0rd", public_key)
if list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
log_output = "start junk [cloud-init] Encrypt random password\n-----BEGIN BASE64-ENCODED ENCRYPTED PASSWORD-----\n#{encoded_password}-----END BASE64-ENCODED ENCRYPTED PASSWORD-----\nend junk [cloud-init] Done\n"
encrypted_password = extract_password_from_log(log_output)
else
raise Fog::Compute::HPV2::NotFound
end
end
list_addresses()
click to toggle source
def list_addresses
response = Excon::Response.new
addresses = []
addresses = self.data[:addresses].values unless self.data[:addresses].nil?
response.status = 200
response.body = { 'floating_ips' => addresses }
response
end
list_availability_zones()
click to toggle source
def list_availability_zones
response = Excon::Response.new
response.status = 200
response.body = {
'availabilityZoneInfo' => [
{'zoneState' => {'available' => true},
'hosts' => nil,
'zoneName' => 'az1'},
{'zoneState' => {'available' => true},
'hosts' => nil,
'zoneName' => 'az2'}
]
}
response
end
list_flavors()
click to toggle source
def list_flavors
response = Excon::Response.new
response.status = 200
response.body = {
'flavors' => [
{ 'name' => 'standard.xsmall', 'id' => '1', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/1", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/1", "rel"=>"bookmark"}] },
{ 'name' => 'standard.small', 'id' => '2', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/2", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/2", "rel"=>"bookmark"}] },
{ 'name' => 'standard.medium', 'id' => '3', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/3", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/3", "rel"=>"bookmark"}] },
{ 'name' => 'standard.large', 'id' => '4', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/4", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/4", "rel"=>"bookmark"}] },
{ 'name' => 'standard.xlarge', 'id' => '5', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/5", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/5", "rel"=>"bookmark"}] },
{ 'name' => 'standard.2xlarge', 'id' => '6', 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/6", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/6", "rel"=>"bookmark"}] }
]
}
response
end
list_flavors_detail(options = {})
click to toggle source
def list_flavors_detail(options = {})
response = Excon::Response.new
response.status = 200
response.body = {
'flavors' => [
{ 'name' => 'standard.xsmall', 'ram' => 1024, 'disk' => 30, 'id' => '1', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 1, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/1", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/1", "rel"=>"bookmark"}] },
{ 'name' => 'standard.small', 'ram' => 2048, 'disk' => 60, 'id' => '2', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 2, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/2", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/2", "rel"=>"bookmark"}] },
{ 'name' => 'standard.medium', 'ram' => 4096, 'disk' => 120, 'id' => '3', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 2, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/3", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/3", "rel"=>"bookmark"}] },
{ 'name' => 'standard.large', 'ram' => 8192, 'disk' => 240, 'id' => '4', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 4, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/4", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/4", "rel"=>"bookmark"}] },
{ 'name' => 'standard.xlarge', 'ram' => 16384, 'disk' => 480, 'id' => '5', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 4, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/5", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/5", "rel"=>"bookmark"}] },
{ 'name' => 'standard.2xlarge', 'ram' => 32768, 'disk' => 960, 'id' => '6', 'OS-FLV-EXT-DATA:ephemeral' => 20, 'vcpus' => 8, 'links' => [{"href"=>"http://nova1:8774/v1.1/admin/flavors/6", "rel"=>"self"}, {"href"=>"http://nova1:8774admin/flavors/6", "rel"=>"bookmark"}] }
]
}
response
end
list_images(options = {})
click to toggle source
def list_images(options = {})
response = Excon::Response.new
data = list_images_detail.body['images']
images = []
for image in data
images << image.reject { |key, _| !['id', 'name', 'links'].include?(key) }
end
response.status = [200, 203][rand(1)]
response.body = { 'images' => images }
response
end
list_images_detail(options = {})
click to toggle source
def list_images_detail(options = {})
response = Excon::Response.new
images = self.data[:images].values
for image in images
case image['status']
when 'SAVING'
image['status'] = 'ACTIVE'
end
end
response.status = [200, 203][rand(1)]
response.body = { 'images' => images }
response
end
list_key_pairs()
click to toggle source
def list_key_pairs
response = Excon::Response.new
key_pairs = []
key_pairs = self.data[:key_pairs].values unless self.data[:key_pairs].nil?
response.status = [200, 203][rand(1)]
response.body = { 'keypairs' => key_pairs }
response
end
list_limits()
click to toggle source
def list_limits
response = Excon::Response.new
limits = self.data[:limits].values
response.status = 200
response.body = { 'limits' => limits }
response
end
list_server_addresses(server_id)
click to toggle source
def list_server_addresses(server_id)
response = Excon::Response.new
if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
response.status = 200
response.body = { 'addresses' => server['addresses'] }
response
else
raise Fog::Compute::HPV2::NotFound
end
end
list_server_addresses_by_network(server_id, network_name)
click to toggle source
def list_server_addresses_by_network(server_id, network_name)
response = Excon::Response.new
if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
response.status = 200
address = server['addresses'].select { |key, _| key == network_name}
response.body = address
response
else
raise Fog::Compute::HPV2::NotFound
end
end
list_servers(options = {})
click to toggle source
def list_servers(options = {})
response = Excon::Response.new
data = list_servers_detail.body['servers']
servers = []
for server in data
servers << server.reject { |key, value| !['id', 'name', 'links'].include?(key) }
end
response.status = 200
response.body = { 'servers' => servers }
response
end
list_servers_detail(options = {})
click to toggle source
def list_servers_detail(options = {})
response = Excon::Response.new
servers = self.data[:servers].values
for server in servers
case server['status']
when 'BUILD'
if Time.now - self.data[:last_modified][:servers][server['id']] > Fog::Mock.delay * 2
server['status'] = 'ACTIVE'
end
end
end
response.status = 200
response.body = { 'servers' => servers }
response
end
reboot_server(server_id, type = 'SOFT')
click to toggle source
def reboot_server(server_id, type = 'SOFT')
response = Excon::Response.new
if list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
self.data[:servers][server_id]['status'] = (type == 'SOFT') ? 'REBOOT' : 'HARD_REBOOT'
response.status = 202
response
else
raise Fog::Compute::HPV2::NotFound
end
end
rebuild_server(server_id, image_id, name, options={})
click to toggle source
def rebuild_server(server_id, image_id, name, options={})
if image = list_images_detail.body['images'].find {|_| _['id'] == image_id}
if response = get_server_details(server_id)
response.body['server']['name'] = name
response.body['server']['image']['id'] = image_id
response.body['server']['image']['name'] = image['name']
response.body['server']['image']['links'] = image['links']
response.body['server']['status'] = 'REBUILD'
l_options = ['metadata', 'accessIPv4', 'accessIPv6']
l_options.select{|o| options[o]}.each do |key|
response.body['server'][key] = options[key] || ''
end
response.body['server']['personality'] = []
if options['personality']
for file in options['personality']
response.body['server']['personality'] << {
'contents' => Base64.encode64(file['contents']),
'path' => file['path']
}
end
end
response.status = 202
response
else
raise Fog::Compute::HPV2::NotFound
end
else
raise Fog::Compute::HPV2::NotFound.new("Image with image_id #{image_id} not found.")
end
end
release_address(address_id)
click to toggle source
def release_address(address_id)
response = Excon::Response.new
if self.data[:addresses][address_id]
self.data[:last_modified][:addresses].delete(address_id)
self.data[:addresses].delete(address_id)
response.status = 202
else
raise Fog::Compute::HPV2::NotFound
end
response
end
remove_security_group(server_id, sg_name)
click to toggle source
def remove_security_group(server_id, sg_name)
response = Excon::Response.new
if server = self.data[:servers][server_id]
data = server['security_groups'].reject {|sg| sg['name'] == sg_name}
self.data[:servers][server_id]['security_groups'] = data
response.status = 202
else
raise Fog::Compute::HPV2::NotFound
end
response
end
reset_data()
click to toggle source
def reset_data
self.class.data.delete(@hp_access_key)
end
update_server(server_id, options)
click to toggle source
def update_server(server_id, options)
response = Excon::Response.new
if server = list_servers_detail.body['servers'].find {|_| _['id'] == server_id}
if options['name']
server['name'] = options['name']
end
server = server.reject { |key, value| ['key_name', 'security_groups', 'created', 'config_drive', 'OS-EXT-AZ:availability_zone', 'OS-EXT-STS:power_state', 'OS-EXT-STS:task_state', 'OS-EXT-STS:vm_state'].include?(key) }
response.status = 200
response.body = { 'server' => server }
response
else
raise Fog::Compute::HPV2::NotFound
end
end