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

Added method to get vm by mac

parent fbc9b557
......@@ -97,7 +97,7 @@ class Client(object):
self.principal = principal
def _format_url(self, resource, query=None, args=None, subresource=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()
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