From 9f7c0df3b51b36561101e83afb5a51781cd5b945 Mon Sep 17 00:00:00 2001 From: Sigmund Augdal Date: Fri, 27 Sep 2019 15:20:13 +0200 Subject: [PATCH] Added method to get vm by mac --- scvmm_client/odata.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scvmm_client/odata.py b/scvmm_client/odata.py index 78ae974..799c6f3 100644 --- a/scvmm_client/odata.py +++ b/scvmm_client/odata.py @@ -97,7 +97,7 @@ class Client(object): self.principal = principal def _format_url(self, resource, query=None, args=None, subresource=None, - expand=None): + expand=None, raw_filter=None): url = self.baseurl if self.subscription: url += "/" + self.subscription @@ -113,6 +113,8 @@ class Client(object): if query: argstr = " and ".join(("{key} eq {value}".format(key=key, value=type_encode_argvalue(query[key])) for key in query)) fragments["$filter"] = argstr + elif raw_filter: + fragments['$filter'] = raw_filter if expand: fragments["$expand"] = expand if fragments: @@ -158,8 +160,8 @@ class Client(object): collections = self._do_request(url) 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): - url = self._format_url(collection, query, kw_args, expand=expand) + def query_collection(self, collection, query=None, expand=None, raw_filter=None, **kw_args): + url = self._format_url(collection, query, kw_args, expand=expand, raw_filter=raw_filter) result = [] while url: collection = self._do_request(url) @@ -386,6 +388,9 @@ class VMMClient(Client): def restore_checkpoint(self, stampid, _id): 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(): cfg = SafeConfigParser() -- GitLab