Skip to content

Instantly share code, notes, and snippets.

@dav3860
Created August 19, 2014 12:58
Show Gist options
  • Save dav3860/7ba5eb7add3862df790f to your computer and use it in GitHub Desktop.
Save dav3860/7ba5eb7add3862df790f to your computer and use it in GitHub Desktop.
--- vmbix-discovery.py.orig 2014-08-19 14:53:19.768779919 +0200
+++ vmbix-discovery.py 2014-07-25 15:28:12.808115479 +0200
@@ -51,31 +53,45 @@
exit(1)
hosts = zapi.host.get({"output": "extend", "selectGroups": ["name"], "selectParentTemplates": ["name"]})
-try:
- get = zapi.hostgroup.get({
+if VMPROXY:
+ try:
+ get = zapi.proxy.get({
"output": "extend",
"filter": {
- "name": VMGROUP
- }
- })
- groupids = [{"groupid": x['groupid']} for x in get]
- logging.info("Groups : %s" %(groupids))
- #groupid = get[0]['groupid']
-except:
- logging.error("Cannot resolve VM group")
+ "host": [VMPROXY]
+ }
+ })
+ proxy_hostid = get[0]['proxyid']
+ except:
+ logging.error("Cannot resolve VM proxy")
+
+if VMGROUP:
+ try:
+ get = zapi.hostgroup.get({
+ "output": "extend",
+ "filter": {
+ "name": VMGROUP
+ }
+ })
+ groupids = [{"groupid": x['groupid']} for x in get]
+ logging.info("Groups : %s" %(groupids))
+ #groupid = get[0]['groupid']
+ except:
+ logging.error("Cannot resolve VM group")
-try:
- get = zapi.template.get({
- "output": "extend",
- "filter": {
- "host": VMTEMPLATE
- }
- })
- templateids = [{"templateid": x['templateid']} for x in get]
- logging.info("Templates : %s" % (templateids))
- #templateid = get[0]['templateid']
-except:
- logging.error("Cannot resolve Template name")
+if VMTEMPLATE:
+ try:
+ get = zapi.template.get({
+ "output": "extend",
+ "filter": {
+ "host": VMTEMPLATE
+ }
+ })
+ templateids = [{"templateid": x['templateid']} for x in get]
+ logging.info("Templates : %s" % (templateids))
+ #templateid = get[0]['templateid']
+ except:
+ logging.error("Cannot resolve Template name")
# Loop through discovered VMs
created = 0
@@ -115,6 +131,7 @@
"port": 10050
}],
"groups": groupids,
+ "proxy_hostid": (proxy_hostid),
"templates": templateids
})
created = created + 1
@@ -132,6 +149,7 @@
"port": 10050
}],
"groups": groupids,
+ "proxy_hostid": (proxy_hostid),
"templates": templateids
})
created = created + 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment