#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os, uuid
from standalone_cloud_api.util.keys import find_public_keys
from standalone_cloud_api.util.network import create_api_routes, MetaDataAPIHandler
from StringIO import StringIO
from standalone_cloud_api.util.userdata import create_user_data

EC2_API_ID="EC2"

Route = create_api_routes("Route", EC2_API_ID)

class EC2MetaDataAPI(MetaDataAPIHandler):
    def __init__(self, config):
        MetaDataAPIHandler.__init__(self, config, EC2_API_ID)

    def encode_results(self, request, results):
        return results


class metadata:
    metadata_funcs = []

    def __init__(self, name=None):
        self.name = name
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

import uuid, json
from standalone_cloud_api.util.keys import find_public_keys
from standalone_cloud_api.util.metadata import get_machine_meta_data
from standalone_cloud_api.util.network import create_api_routes, MetaDataAPIHandler

OPENSTACK_API_ID="Openstack"

Route = create_api_routes("Route", OPENSTACK_API_ID)

class OpenstackMetaDataAPI(MetaDataAPIHandler):
    def __init__(self, config):
        MetaDataAPIHandler.__init__(self, config, OPENSTACK_API_ID)

    def encode_results(self, request, results):
        if request.request_url.endswith(".json"):
            self.set_header("Content-Type","application/json")
            return json.dumps(results)
        return results

@Route("/openstack/2012-08-10/uuid(.json)*")
def instance_id(request):
    return uuid.uuid5(uuid.NAMESPACE_DNS, hostname(request)).__str__()