Skip to content

Commit

Permalink
Merge pull request #242 from mpeuster/master
Browse files Browse the repository at this point in the history
OpenStack-fake API improvements for OSM DevOps integration and containerized deployment
  • Loading branch information
mpeuster authored Aug 30, 2017
2 parents 6fabcc5 + c0e0cc0 commit 7b6e0f9
Show file tree
Hide file tree
Showing 11 changed files with 90 additions and 97 deletions.
3 changes: 3 additions & 0 deletions ansible/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,8 @@
- name: install ipaddress
pip: name=ipaddress state=latest

- name: install urllib
pip: name=urllib state=latest



11 changes: 11 additions & 0 deletions src/emuvim/api/openstack/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from urlparse import urlparse
import logging

LOG = logging.getLogger("api.openstack.helper")

def get_host(r):
try:
return urlparse(r.base_url).hostname
except:
LOG.error("Could not get host part of request URL.")
return "0.0.0.0"
1 change: 0 additions & 1 deletion src/emuvim/api/openstack/openstack_dummies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
from keystone_dummy_api import KeystoneDummyApi
from neutron_dummy_api import NeutronDummyApi
from nova_dummy_api import NovaDummyApi

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask_restful import Resource
from flask import Response, request
from emuvim.api.openstack.openstack_dummies.base_openstack_dummy import BaseOpenstackDummy
from emuvim.api.openstack.helper import get_host
import logging
import json

Expand Down Expand Up @@ -182,7 +183,7 @@ def post(self):
resp['image'] = f
# build actual response with headers and everything
r = Response(json.dumps(resp), status=201, mimetype="application/json")
r.headers.add("Location", "http://%s:%d/v1/images/%s" % (self.api.ip,
r.headers.add("Location", "http://%s:%d/v1/images/%s" % (get_host(request),
self.api.port,
img_id))
return r
Expand Down
7 changes: 4 additions & 3 deletions src/emuvim/api/openstack/openstack_dummies/heat_dummy_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask_restful import Resource
from emuvim.api.openstack.resources import Stack
from emuvim.api.openstack.openstack_dummies.base_openstack_dummy import BaseOpenstackDummy
from emuvim.api.openstack.helper import get_host
from datetime import datetime
from emuvim.api.openstack.heat_parser import HeatParser
import logging
Expand Down Expand Up @@ -75,7 +76,7 @@ def get(self):
"id": "v1.0",
"links": [
{
"href": "http://%s:%d/v2.0" % (self.api.ip, self.api.port),
"href": "http://%s:%d/v2.0" % (get_host(request), self.api.port),
"rel": "self"
}
]
Expand Down Expand Up @@ -123,7 +124,7 @@ def post(self, tenant_id):
"links": [
{
"href": "http://%s:%s/v1/%s/stacks/%s"
% (self.api.ip, self.api.port, tenant_id, stack.id),
% (get_host(request), self.api.port, tenant_id, stack.id),
"rel": "self"
}]}}

Expand Down Expand Up @@ -204,7 +205,7 @@ def get(self, tenant_id, stack_name_or_id, stack_id=None):
"links": [
{
"href": "http://%s:%s/v1/%s/stacks/%s"
% (self.api.ip, self.api.port, tenant_id, stack.id),
% (get_host(request), self.api.port, tenant_id, stack.id),
"rel": "self"
}
],
Expand Down
98 changes: 29 additions & 69 deletions src/emuvim/api/openstack/openstack_dummies/keystone_dummy_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask_restful import Resource
from flask import request, Response
from emuvim.api.openstack.openstack_dummies.base_openstack_dummy import BaseOpenstackDummy
from emuvim.api.openstack.helper import get_host
import logging
import json

Expand All @@ -15,8 +16,8 @@ def __init__(self, in_ip, in_port):
self.api.add_resource(Shutdown, "/shutdown")
self.api.add_resource(KeystoneShowAPIv2, "/v2.0", resource_class_kwargs={'api': self})
self.api.add_resource(KeystoneGetToken, "/v2.0/tokens", resource_class_kwargs={'api': self})
self.api.add_resource(KeystoneShowAPIv3, "/v3", resource_class_kwargs={'api': self})
self.api.add_resource(KeystoneGetTokenv3, "/v3/auth/tokens", resource_class_kwargs={'api': self})
self.api.add_resource(KeystoneShowAPIv3, "/v3.0", resource_class_kwargs={'api': self})
self.api.add_resource(KeystoneGetTokenv3, "/v3.0/auth/tokens", resource_class_kwargs={'api': self})

def _start_flask(self):
LOG.info("Starting %s endpoint @ http://%s:%d" % (__name__, self.ip, self.port))
Expand Down Expand Up @@ -62,7 +63,7 @@ def get(self):
"id": "v2.0",
"links": [
{
"href": "http://%s:%d/v2.0" % (self.api.ip, self.api.port),
"href": "http://%s:%d/v2.0" % (get_host(request), self.api.port),
"rel": "self"
}
],
Expand Down Expand Up @@ -113,32 +114,12 @@ def get(self):
"id": "v2.0",
"links": [
{
"href": "http://%s:%d/v2.0" % (self.api.ip, self.api.port),
"rel": "self"
},
{
"href": "http://%s:%d/v2.0/tokens" % (self.api.ip, self.api.port),
"rel": "self"
},
{
"href": "http://%s:%d/v2.0/networks" % (self.api.ip, neutron_port),
"rel": "self"
},
{
"href": "http://%s:%d/v2.0/subnets" % (self.api.ip, neutron_port),
"rel": "self"
},
{
"href": "http://%s:%d/v2.0/ports" % (self.api.ip, neutron_port),
"rel": "self"
},
{
"href": "http://%s:%d/v1/<tenant_id>/stacks" % (self.api.ip, heat_port),
"href": "http://%s:%d/v2.0" % (get_host(request), self.api.port),
"rel": "self"
}
]
}

LOG.debug(json.dumps(resp))
return Response(json.dumps(resp), status=200, mimetype='application/json')


Expand Down Expand Up @@ -169,33 +150,13 @@ def get(self):
"media-types": [
{
"base": "application/json",
"type": "application/vnd.openstack.identity-v2.0+json"
"type": "application/vnd.openstack.identity-v3.0+json"
}
],
"id": "v2.0",
"id": "v3.0",
"links": [
{
"href": "http://%s:%d/v2.0" % (self.api.ip, self.api.port),
"rel": "self"
},
{
"href": "http://%s:%d/v2.0/tokens" % (self.api.ip, self.api.port),
"rel": "self"
},
{
"href": "http://%s:%d/v2.0/networks" % (self.api.ip, neutron_port),
"rel": "self"
},
{
"href": "http://%s:%d/v2.0/subnets" % (self.api.ip, neutron_port),
"rel": "self"
},
{
"href": "http://%s:%d/v2.0/ports" % (self.api.ip, neutron_port),
"rel": "self"
},
{
"href": "http://%s:%d/v1/<tenant_id>/stacks" % (self.api.ip, heat_port),
"href": "http://%s:%d/v3.0" % (get_host(request), self.api.port),
"rel": "self"
}
]
Expand Down Expand Up @@ -260,11 +221,11 @@ def post(self):
ret['access']['serviceCatalog'] = [{
"endpoints": [
{
"adminURL": "http://%s:%s/v2.1/%s" % (self.api.ip, self.api.port + 3774, user['id']),
"adminURL": "http://%s:%s/v2.1/%s" % (get_host(request), self.api.port + 3774, user['id']),
"region": "RegionOne",
"internalURL": "http://%s:%s/v2.1/%s" % (self.api.ip, self.api.port + 3774, user['id']),
"internalURL": "http://%s:%s/v2.1/%s" % (get_host(request), self.api.port + 3774, user['id']),
"id": "2dad48f09e2a447a9bf852bcd93548ef",
"publicURL": "http://%s:%s/v2.1/%s" % (self.api.ip, self.api.port + 3774, user['id'])
"publicURL": "http://%s:%s/v2.1/%s" % (get_host(request), self.api.port + 3774, user['id'])
}
],
"endpoints_links": [],
Expand All @@ -274,11 +235,11 @@ def post(self):
{
"endpoints": [
{
"adminURL": "http://%s:%s/v2.0" % (self.api.ip, self.api.port),
"adminURL": "http://%s:%s/v2.0" % (get_host(request), self.api.port),
"region": "RegionOne",
"internalURL": "http://%s:%s/v2.0" % (self.api.ip, self.api.port),
"internalURL": "http://%s:%s/v2.0" % (get_host(request), self.api.port),
"id": "2dad48f09e2a447a9bf852bcd93543fc",
"publicURL": "http://%s:%s/v2" % (self.api.ip, self.api.port)
"publicURL": "http://%s:%s/v2" % (get_host(request), self.api.port)
}
],
"endpoints_links": [],
Expand All @@ -288,11 +249,11 @@ def post(self):
{
"endpoints": [
{
"adminURL": "http://%s:%s" % (self.api.ip, self.api.port + 4696),
"adminURL": "http://%s:%s" % (get_host(request), self.api.port + 4696),
"region": "RegionOne",
"internalURL": "http://%s:%s" % (self.api.ip, self.api.port + 4696),
"internalURL": "http://%s:%s" % (get_host(request), self.api.port + 4696),
"id": "2dad48f09e2a447a9bf852bcd93548cf",
"publicURL": "http://%s:%s" % (self.api.ip, self.api.port + 4696)
"publicURL": "http://%s:%s" % (get_host(request), self.api.port + 4696)
}
],
"endpoints_links": [],
Expand All @@ -302,11 +263,11 @@ def post(self):
{
"endpoints": [
{
"adminURL": "http://%s:%s" % (self.api.ip, self.api.port + 4242),
"adminURL": "http://%s:%s" % (get_host(request), self.api.port + 4242),
"region": "RegionOne",
"internalURL": "http://%s:%s" % (self.api.ip, self.api.port + 4242),
"internalURL": "http://%s:%s" % (get_host(request), self.api.port + 4242),
"id": "2dad48f09e2a447a9bf852bcd93548cf",
"publicURL": "http://%s:%s" % (self.api.ip, self.api.port + 4242)
"publicURL": "http://%s:%s" % (get_host(request), self.api.port + 4242)
}
],
"endpoints_links": [],
Expand All @@ -316,11 +277,11 @@ def post(self):
{
"endpoints": [
{
"adminURL": "http://%s:%s/v1/%s" % (self.api.ip, self.api.port + 3004, user['id']),
"adminURL": "http://%s:%s/v1/%s" % (get_host(request), self.api.port + 3004, user['id']),
"region": "RegionOne",
"internalURL": "http://%s:%s/v1/%s" % (self.api.ip, self.api.port + 3004, user['id']),
"internalURL": "http://%s:%s/v1/%s" % (get_host(request), self.api.port + 3004, user['id']),
"id": "2dad48f09e2a447a9bf852bcd93548bf",
"publicURL": "http://%s:%s/v1/%s" % (self.api.ip, self.api.port + 3004, user['id'])
"publicURL": "http://%s:%s/v1/%s" % (get_host(request), self.api.port + 3004, user['id'])
}
],
"endpoints_links": [],
Expand Down Expand Up @@ -406,7 +367,7 @@ def post(self):
token['catalog'] = [{
"endpoints": [
{
"url": "http://%s:%s/v2.1/%s" % (self.api.ip, self.api.port + 3774, user['id']),
"url": "http://%s:%s/v2.1/%s" % (get_host(request), self.api.port + 3774, user['id']),
"region": "RegionOne",
"interface": "public",
"id": "2dad48f09e2a447a9bf852bcd93548ef"
Expand All @@ -419,7 +380,7 @@ def post(self):
{
"endpoints": [
{
"url": "http://%s:%s/v2.0" % (self.api.ip, self.api.port),
"url": "http://%s:%s/v2.0" % (get_host(request), self.api.port),
"region": "RegionOne",
"interface": "public",
"id": "2dad48f09e2a447a9bf852bcd93543fc"
Expand All @@ -432,7 +393,7 @@ def post(self):
{
"endpoints": [
{
"url": "http://%s:%s" % (self.api.ip, self.api.port + 4696),
"url": "http://%s:%s" % (get_host(request), self.api.port + 4696),
"region": "RegionOne",
"interface": "public",
"id": "2dad48f09e2a447a9bf852bcd93548cf"
Expand All @@ -445,7 +406,7 @@ def post(self):
{
"endpoints": [
{
"url": "http://%s:%s" % (self.api.ip, self.api.port + 4242),
"url": "http://%s:%s" % (get_host(request), self.api.port + 4242),
"region": "RegionOne",
"interface": "public",
"id": "2dad48f09e2a447a9bf852bcd93548cf"
Expand All @@ -458,7 +419,7 @@ def post(self):
{
"endpoints": [
{
"url": "http://%s:%s/v1/%s" % (self.api.ip, self.api.port + 3004, user['id']),
"url": "http://%s:%s/v1/%s" % (get_host(request), self.api.port + 3004, user['id']),
"region": "RegionOne",
"interface": "public",
"id": "2dad48f09e2a447a9bf852bcd93548bf"
Expand All @@ -469,7 +430,6 @@ def post(self):
"name": "heat"
}
]

return Response(json.dumps(ret), status=201, mimetype='application/json')

except Exception as ex:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask_restful import Resource
from flask import request, Response
from emuvim.api.openstack.openstack_dummies.base_openstack_dummy import BaseOpenstackDummy
from emuvim.api.openstack.helper import get_host
from datetime import datetime
import neutron_sfc_dummy_api as SFC
import logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import uuid

from emuvim.api.openstack.resources.port_chain import PortChain
from emuvim.api.openstack.helper import get_host


class SFC(Resource):
Expand Down
Loading

0 comments on commit 7b6e0f9

Please sign in to comment.