def attach_nic(self, vm, network_id): sunstone = Sunstone(vm.cluster) network = Network.query.get(network_id) params = '{"action":{"perform":"attachnic","params":{"nic_template":{"NIC":{"NETWORK":"%s","NETWORK_UNAME":"oneadmin","MODEL":"virtio"}}}}}' % \ network.sunstone_name resp = sunstone.vm_action(vm.vm_id, params) return resp.status == 204 and 1 or 0
def attach_nic(self, vm, network_id): sunstone = Sunstone(vm.cluster) network = Network.query.get(network_id) params = '{"action":{"perform":"attachnic","params":{"nic_template":{"NIC":{"NETWORK":"%s","NETWORK_UNAME":"oneadmin","MODEL":"virtio"}}}}}' % \ network.sunstone_name resp = sunstone.vm_action(vm.vm_id, params) return resp.status==204 and 1 or 0
def resize(self, vm, cpu, mem): (cpu, mem) = (int(cpu), int(mem)) sunstone = Sunstone(vm.cluster) params = '{"action":{"perform":"resize","params":{"vm_template":{"CPU":"%s","MEMORY":"%s"},"enforce":false}}}' % (cpu, mem*1024) resp = sunstone.vm_action(vm.vm_id, params) if resp.status == 204: vm.cpu = cpu vm.mem = mem db.session.add(vm) db.session.commit() vminst = VMC() vminst.gen_price(vm) return 1 else: return 0
def resize(self, vm, cpu, mem): (cpu, mem) = (int(cpu), int(mem)) sunstone = Sunstone(vm.cluster) params = '{"action":{"perform":"resize","params":{"vm_template":{"CPU":"%s","MEMORY":"%s"},"enforce":false}}}' % ( cpu, mem * 1024) resp = sunstone.vm_action(vm.vm_id, params) if resp.status == 204: vm.cpu = cpu vm.mem = mem db.session.add(vm) db.session.commit() vminst = VMC() vminst.gen_price(vm) return 1 else: return 0
def recreate(self, vm): sunstone = Sunstone(vm.cluster) post = '{"action":{"perform":"resubmit"}}' resp = sunstone.vm_action(vm.vm_id, post) return resp.status==204 and 1 or 0
def poweroff_hard(self, vm): sunstone = Sunstone(vm.cluster) post = '{"action":{"perform":"poweroff","params":{"hard":true}}}' resp = sunstone.vm_action(vm.vm_id, post) return resp.status==204 and 1 or 0
def detach_nic(self, vm, nic_id): sunstone = Sunstone(vm.cluster) params = '{"action":{"perform":"detachnic","params":{"nic_id":"%s"}}}' % nic_id resp = sunstone.vm_action(vm.vm_id, params) return resp.status==204 and 1 or 0
def rename(self, vm, newname): sunstone = Sunstone(vm.cluster) params = '{"action":{"perform":"rename","params":{"name":"%s"}}}' % newname resp = sunstone.vm_action(vm.vm_id, params) return resp.status==204 and 1 or 0
def recreate(self, vm): sunstone = Sunstone(vm.cluster) post = '{"action":{"perform":"resubmit"}}' resp = sunstone.vm_action(vm.vm_id, post) return resp.status == 204 and 1 or 0
def poweroff_hard(self, vm): sunstone = Sunstone(vm.cluster) post = '{"action":{"perform":"poweroff","params":{"hard":true}}}' resp = sunstone.vm_action(vm.vm_id, post) return resp.status == 204 and 1 or 0
def detach_nic(self, vm, nic_id): sunstone = Sunstone(vm.cluster) params = '{"action":{"perform":"detachnic","params":{"nic_id":"%s"}}}' % nic_id resp = sunstone.vm_action(vm.vm_id, params) return resp.status == 204 and 1 or 0
def rename(self, vm, newname): sunstone = Sunstone(vm.cluster) params = '{"action":{"perform":"rename","params":{"name":"%s"}}}' % newname resp = sunstone.vm_action(vm.vm_id, params) return resp.status == 204 and 1 or 0