Commit 9f7c0df3 authored by Sigmund Augdal's avatar Sigmund Augdal

Added method to get vm by mac

parent fbc9b557
...@@ -97,7 +97,7 @@ class Client(object): ...@@ -97,7 +97,7 @@ class Client(object):
self.principal = principal self.principal = principal
def _format_url(self, resource, query=None, args=None, subresource=None, def _format_url(self, resource, query=None, args=None, subresource=None,
expand=None): expand=None, raw_filter=None):
url = self.baseurl url = self.baseurl
if self.subscription: if self.subscription:
url += "/" + self.subscription url += "/" + self.subscription
...@@ -113,6 +113,8 @@ class Client(object): ...@@ -113,6 +113,8 @@ class Client(object):
if query: if query:
argstr = " and ".join(("{key} eq {value}".format(key=key, value=type_encode_argvalue(query[key])) for key in query)) argstr = " and ".join(("{key} eq {value}".format(key=key, value=type_encode_argvalue(query[key])) for key in query))
fragments["$filter"] = argstr fragments["$filter"] = argstr
elif raw_filter:
fragments['$filter'] = raw_filter
if expand: if expand:
fragments["$expand"] = expand fragments["$expand"] = expand
if fragments: if fragments:
...@@ -158,8 +160,8 @@ class Client(object): ...@@ -158,8 +160,8 @@ class Client(object):
collections = self._do_request(url) collections = self._do_request(url)
return (collection for collection in collections.xpath('/b:service/b:workspace/b:collection/atom:title/text()', namespaces=namespaces)) return (collection for collection in collections.xpath('/b:service/b:workspace/b:collection/atom:title/text()', namespaces=namespaces))
def query_collection(self, collection, query=None, expand=None, **kw_args): def query_collection(self, collection, query=None, expand=None, raw_filter=None, **kw_args):
url = self._format_url(collection, query, kw_args, expand=expand) url = self._format_url(collection, query, kw_args, expand=expand, raw_filter=raw_filter)
result = [] result = []
while url: while url:
collection = self._do_request(url) collection = self._do_request(url)
...@@ -386,6 +388,9 @@ class VMMClient(Client): ...@@ -386,6 +388,9 @@ class VMMClient(Client):
def restore_checkpoint(self, stampid, _id): def restore_checkpoint(self, stampid, _id):
self.update_entry("VMCheckPoints", stampid, _id, VMCheckPointAction="Restore") self.update_entry("VMCheckPoints", stampid, _id, VMCheckPointAction="Restore")
def get_vm_by_mac(self, stampid, mac):
return self.query_collection("VirtualMachines", raw_filter="VirtualNetworkAdapters/any(nic: nic/MACAddress eq '{}')")
def get_config(): def get_config():
cfg = SafeConfigParser() cfg = SafeConfigParser()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment