예제 #1
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
예제 #2
0
파일: vm.py 프로젝트: stamhe/apc
 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
예제 #3
0
파일: vm.py 프로젝트: stamhe/apc
 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
예제 #4
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
예제 #5
0
파일: vm.py 프로젝트: stamhe/apc
 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
예제 #6
0
파일: vm.py 프로젝트: stamhe/apc
 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
예제 #7
0
파일: vm.py 프로젝트: stamhe/apc
 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
예제 #8
0
파일: vm.py 프로젝트: stamhe/apc
 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
예제 #9
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
예제 #10
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
예제 #11
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
예제 #12
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