This implements the basic capabilities we need from the metadata server. Each API call returns proper HTTP responses (404, 409, etc.). The server is currently not connected to a real database. Rather, it uses a simple mock. This allows for quick initial API changes before things stabilize. The immediate next steps are to integrate the server with the cfn tools (cfn-metadata being the prime candidate) to see what may be wrong/missing. And then to connect the server to a real database. Signed-off-by: Tomas Sedovic <tomas@sedovic.cz>changes/40/40/1
parent
c061dc0029
commit
9843bc8baa
@ -0,0 +1,64 @@
|
||||
DB = {}
|
||||
|
||||
|
||||
class ConflictError(Exception):
|
||||
pass
|
||||
|
||||
class StackNotFoundError(Exception):
|
||||
pass
|
||||
|
||||
class ResourceNotFoundError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def list_stacks():
|
||||
return DB.keys()
|
||||
|
||||
def create_stack(name, stack):
|
||||
global DB
|
||||
if name in DB:
|
||||
raise ConflictError(name)
|
||||
data = {}
|
||||
# TODO(shadower): validate the stack input format
|
||||
data['name'] = name
|
||||
data['heat_id'] = stack['id']
|
||||
data['resources'] = {}
|
||||
DB[name] = data
|
||||
return data
|
||||
|
||||
def list_resources(stack_name):
|
||||
if not stack_name in DB:
|
||||
raise StackNotFoundError(stack_name)
|
||||
stack = DB[stack_name]
|
||||
try:
|
||||
resources = stack['resources'].keys()
|
||||
except:
|
||||
resources = []
|
||||
return resources
|
||||
|
||||
def get_resource(stack_name, resource_id):
|
||||
if not stack_name in DB:
|
||||
raise StackNotFoundError(stack_name)
|
||||
stack = DB[stack_name]
|
||||
|
||||
if not resource_id in stack['resources']:
|
||||
raise ResourceNotFoundError(resource_id)
|
||||
return stack['resources'][resource_id]
|
||||
|
||||
def create_resource_metadata(stack_name, resource_id, metadata):
|
||||
if not stack_name in DB:
|
||||
raise StackNotFoundError(stack_name)
|
||||
stack = DB[stack_name]
|
||||
|
||||
if resource_id in stack['resources']:
|
||||
raise ConflictError(resource_id)
|
||||
stack['resources'][resource_id] = metadata
|
||||
|
||||
def update_resource_metadata(stack_name, resource_id, metadata):
|
||||
if not stack_name in DB:
|
||||
raise StackNotFoundError(stack_name)
|
||||
stack = DB[stack_name]
|
||||
|
||||
if not resource_id in stack['resources']:
|
||||
raise ResourceNotFoundError(resource_id)
|
||||
stack['resources'][resource_id] = metadata
|
Loading…
Reference in new issue