def snapshot_info(self, guest_id, snapshot_id): vm = self._vm_ref(guest_id) snap = vmware.get_snapshot(vm, snapshot_id) if snap: return self._snapshot_info(snap) else: raise EntityNotFound("Snapshot", snapshot_id)
def guest_update(self, guest_id, guestdata): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) self.guests[guest_id].update(guestdata) return self.guests[guest_id]
def snapshot_info(self, guestname, snapshot_name): dom = self.libvirt_connection.lookupByUUIDString(guest_id) snap = self.libvirt_get_snapshot(dom, snapshot_id) if snap: return self.libvirt_snapshot_info(snap) else: raise EntityNotFound("Snapshot", snapshot_id)
def network_interface_update(self, guest_id, interface_id, data): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) nw_int = self.guests[guest_id]['network_interfaces'][interface_id] if data.get("network"): nw_int["network"] = data["network"] return nw_int
def _disk_rec(self, vm_ref, disk_id): disk_id = str(disk_id) for disk in self.get_disks(vm_ref): if disk["userdevice"] == disk_id: return disk entity_info = "%s - on Guest" % (disk_id) raise EntityNotFound("Disk", entity_info)
def network_interface_info(self, guest_id, network_interface_id): vm = self._vm_ref(guest_id) vifs = vmware.get_network_interfaces(vm) for vif in vifs: if vif.macAddress == network_interface_id: return self._network_interface_info(vif) entity_info = "%s - on Guest %s" % (network_interface_id, guest_id) raise EntityNotFound("NetworkInterface", entity_info)
def _network_interface_ref(self, vm_ref, network_interface_id): vif_refs = self.connection.xenapi.VM.get_VIFs(vm_ref) for vif_ref in vif_refs: vif_rec = self.connection.xenapi.VIF.get_record(vif_ref) if vif_rec["MAC"] == network_interface_id: return vif_ref entity_info = "%s - on Guest" % (network_interface_id) raise EntityNotFound("NetworkInterface", entity_info)
def network_interface_info(self, guest_id, network_interface_id): dom = self.libvirt_connection.lookupByUUIDString(guest_id) root = et.fromstring(dom.XMLDesc(0)) nw_interfaces = self.network_interface_list(guest_id) for iface in nw_interfaces: if iface["id"] == network_interface_id: return iface raise EntityNotFound("Network interface", network_interface_id)
def network_interface_delete(self, guest_id, network_interface_id): dom = self.libvirt_connection.lookupByUUIDString(guest_id) root = et.fromstring(dom.XMLDesc(0)) iface_id = "address" # defining the simplestack's libvirt id for iface in root.iter("interface"): for i in iface.getchildren(): if i.attrib.get(iface_id) == network_interface_id: dom.detachDeviceFlags(et.tostring(iface), 2) return {"id": network_interface_id} raise EntityNotFound("Network interface", network_interface_id)
def network_interface_create(self, guest_id, data): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) mac = "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" % (random.randint( 0, 255), random.randint(0, 255), random.randint( 0, 255), random.randint(0, 255), random.randint( 0, 255), random.randint(0, 255), random.randint( 0, 255), random.randint(0, 255)) self.guests[guest_id]['network_interfaces'][mac] = { "id": mac, "number": "0", "mac": mac, "network": "network1" } return self.guests[guest_id]['network_interfaces'][mac]
def guest_start(self, guest_id): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) self.guests[guest_id]['state'] = "STARTED"
def guest_reboot(self, guest_id, force=False): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) self.guests[guest_id]['state'] = "STARTED"
def guest_suspend(self, guest_id): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) self.guests[guest_id]['state'] = "PAUSED"
def guest_shutdown(self, guest_id, force=False): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) self.guests[guest_id]['state'] = "STOPPED"
def network_interface_info(self, guest_id, interface_id): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) return self.guests[guest_id]['network_interfaces'][interface_id]
def guest_delete(self, guest_id): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) del self.guests[guest_id]
def network_interface_list(self, guest_id): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) return self.guests[guest_id]['network_interfaces'].values()
def media_info(self, guest_id): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) return {"name": self.guests[guest_id]["cd"]}
def media_mount(self, guest_id, media_data): if not self.guests.get(guest_id): raise EntityNotFound("Guest", guest_id) self.guests[guest_id]["cd"] = media_data.get("name")