'Creates a new image.
:param      node: Node
:type       node: :class:`Node`
:param      name: The name for the new image.
:type       name: ``str``
:param      metadata: Key and value pairs for metadata.
:type       metadata: ``dict``
:rtype: :class:`NodeImage`'

def create_image(self, node, name, metadata=None):

    optional_params = {}
    if metadata:
        optional_params['metadata'] = metadata
    resp = self._node_action(node, 'createImage', name=name, **optional_params)
    image_id = self._extract_image_id_from_url(resp.headers['location'])
    return self.get_image(image_id=image_id)
