From 047acde2024f8cc6b6f3c80dc9840ef367421de5 Mon Sep 17 00:00:00 2001 From: Vilobh Meshram Date: Tue, 17 May 2016 11:58:45 -0700 Subject: [PATCH] Add Resource and Usage objects Add Resource and Usage objects to Delimiter. Change-Id: Ia8517fc36954f1bb982d532d98aed41a2b132eae --- delimiter/objects/resource.py | 33 +++++++++++++++++++++++++++++++++ delimiter/objects/usage.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 delimiter/objects/resource.py create mode 100644 delimiter/objects/usage.py diff --git a/delimiter/objects/resource.py b/delimiter/objects/resource.py new file mode 100644 index 0000000..16b7240 --- /dev/null +++ b/delimiter/objects/resource.py @@ -0,0 +1,33 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +class Resource(object): + """Represent a resource. + + """ + + def __init__(self, service, name, params=None): + """Initialize a Resource + + :param service: The Service object the resource is associated + with. + :param name: The name of the resource, as a string; e.g., + "instances", "vcpus", "images", etc. + :param params: The names of the parameters necessary to + identify the resource. + + """ + self.service = service + self.name = name + self.params = set(params) if params else set() diff --git a/delimiter/objects/usage.py b/delimiter/objects/usage.py new file mode 100644 index 0000000..e539967 --- /dev/null +++ b/delimiter/objects/usage.py @@ -0,0 +1,33 @@ +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +class Usage(object): + """Represent a resource usage. + + """ + + def __init__(self, resource, category, usage=0): + """Initialize a Usage. + + :param resource: The Resource the usage is for. + :param category: The category of the Usage. + relevant to service users. + :param usage: The current amount of the resource which is in + use by the user. + + """ + + self.resource = resource + self.category = category + self.usage = usage