Commit bef8ad13 authored by Stavros Sachtouris's avatar Stavros Sachtouris

Implement server/image/flavor info

"image info" and "flavor info" implementations are trivial and are
implemented by these methods:
* snf_get_flavor
* snf_get_info

"server info" is implemented by this method:
* snf_get_server
but also requires the following side implementations:
* snf_get_server_volume_links (volume attachments)
* snf_get_server_net_attachments (server nics)

Modifications in the json response template had to be applied in
in snf_get_server and snf_get_server_net_attachments to achieve
OpenStack compatibility
parent e43253b9
...@@ -42,9 +42,88 @@ def snf_get_images(cls, req): ...@@ -42,9 +42,88 @@ def snf_get_images(cls, req):
return cls.get_from_response(response, 'images', []) return cls.get_from_response(response, 'images', [])
def _openstackify_addresses(addresses, attachments):
"""Adjust server-nics to os-interface format
This will affect addresses, not attachments, but attachments are used as
input information
"""
for att in attachments:
net_id, mac_addr = att['network_id'], att['mac_address']
for addr in addresses[net_id]:
addr.setdefault('net_id', net_id)
addr.setdefault('OS-EXT-IPS-MAC:mac_addr', mac_addr)
def snf_get_server(cls, req, server_id):
"""Synnefo: server info <server_id>"""
req.environ['service_type'] = 'compute'
req.environ['method_name'] = 'servers_get'
req.environ['kwargs'] = {'server_id': server_id}
response = req.get_response(cls.app)
r = cls.get_from_response(response, "server", {})
_openstackify_addresses(r['addresses'], r['attachments'])
return r
def snf_get_flavor(cls, req, flavor_id):
"""Synnefo: flavor info <flavor_id>"""
req.environ['service_type'] = 'compute'
req.environ['method_name'] = 'flavors_get'
req.environ['kwargs'] = {'flavor_id': flavor_id}
response = req.get_response(cls.app)
return cls.get_from_response(response, "flavor", {})
def snf_get_image(cls, req, image_id):
"""Synnefo: flavor info <image_id>"""
req.environ['service_type'] = 'compute'
req.environ['method_name'] = 'images_get'
req.environ['kwargs'] = {'image_id': image_id}
response = req.get_response(cls.app)
return cls.get_from_response(response, "image", {})
def snf_get_server_volumes_link(cls, req, server_id):
"""Synnefo: server attachments <server_id>"""
req.environ['service_type'] = 'compute'
req.environ['method_name'] = 'volume_attachment_get'
req.environ['kwargs'] = {'server_id': server_id}
response = req.get_response(cls.app)
return cls.get_from_response(response, "volumeAttachments", [])
def _openstackify_net_attachments(attachments):
"""OpenStack uses different keys for the same fields"""
for a in attachments:
a['net_id'] = a['network_id']
a['mac_addr'] = a['mac_address']
a['port_id'] = a['id']
if a.get('OS-EXT-IPS:type', '') in ('fixed', ):
fixed_ips, ipv4, ipv6 = {}, a.get('ipv4'), a.get('ipv6')
if ipv4 or ipv6:
fixed_ips['ip_address'] = ipv6 or ipv4
a['fixed_ips'] = fixed_ips
def snf_get_server_net_attachments(cls, req, compute_id):
"""Adjust server-nics to os-interface format"""
req.environ['service_type'] = 'compute'
req.environ['method_name'] = 'servers_ips_get'
req.environ['kwargs'] = {'server_id': compute_id}
response = req.get_response(cls.app)
r = cls.get_from_response(response, 'attachments', [])
_openstackify_net_attachments(r)
return r
function_map = { function_map = {
'index': snf_index, 'index': snf_index,
'get_server': snf_get_server,
'get_flavors': snf_get_flavors, 'get_flavors': snf_get_flavors,
'get_flavor': snf_get_flavor,
'get_images': snf_get_images, 'get_images': snf_get_images,
'get_image': snf_get_image,
'get_floating_ip_pools': empty_list_200, 'get_floating_ip_pools': empty_list_200,
'get_server_volumes_link': snf_get_server_volumes_link,
'_get_ports': snf_get_server_net_attachments,
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment