CORD-880 add accessor for core api
Change-Id: Idd83ac235504b7266a6a72f9a50831f00f5ad22b
diff --git a/xos/xos_client/xosapi/convenience/__init__.py b/xos/xos_client/xosapi/convenience/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/xos/xos_client/xosapi/convenience/__init__.py
diff --git a/xos/xos_client/xosapi/convenience/instance.py b/xos/xos_client/xosapi/convenience/instance.py
new file mode 100644
index 0000000..10da548
--- /dev/null
+++ b/xos/xos_client/xosapi/convenience/instance.py
@@ -0,0 +1,55 @@
+from xosapi.orm import ORMWrapper, register_convenience_wrapper
+
+class ORMWrapperInstance(ORMWrapper):
+
+ def all_ips(self):
+ ips={}
+ for ns in self.ports.all():
+ if ns.ip:
+ ips[ns.network.name] = ns.ip
+ return ips
+
+ def all_ips_string(self):
+ result = []
+ ips = self.all_ips()
+ for key in sorted(ips.keys()):
+ #result.append("%s = %s" % (key, ips[key]))
+ result.append(ips[key])
+ return ", ".join(result)
+
+ def get_public_ip(self):
+ for ns in self.ports.all():
+ if (ns.ip) and (ns.network.template.visibility=="public") and (ns.network.template.translation=="none"):
+ return ns.ip
+ return None
+
+ # return an address on nat-net
+ def get_network_ip(self, pattern):
+ for ns in self.ports.all():
+ if pattern in ns.network.name.lower():
+ return ns.ip
+ return None
+
+ # return an address that the synchronizer can use to SSH to the instance
+ def get_ssh_ip(self):
+ # first look specifically for a management_local network
+ for ns in self.ports.all():
+ if ns.network.template and ns.network.template.vtn_kind=="MANAGEMENT_LOCAL":
+ return ns.ip
+
+ # for compatibility, now look for any management network
+ management=self.get_network_ip("management")
+ if management:
+ return management
+
+ # if all else fails, look for nat-net (for OpenCloud?)
+ return self.get_network_ip("nat")
+
+ @property
+ def controller(self):
+ if self.node and self.node.site_deployment:
+ return self.node.site_deployment.controller
+ else:
+ return None
+
+register_convenience_wrapper("Instance", ORMWrapperInstance)