예제 #1
0
 def resize(self, vm_id, flavor_id, username):
     '''
     更改虚拟机flavor类型
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id, vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {
         "resize": {
             "flavorRef": flavor_id,
             "OS-DCF:diskConfig": "AUTO"
         }
     }
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     t1 = run_in_thread(self.wait_complete,
                        vm_id, ["VERIFY_RESIZE"],
                        username,
                        timeout=TIMEOUT)
     assert t1 == 0
     params = {"confirmResize": ""}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     t2 = run_in_thread(self.wait_complete,
                        vm_id, ["ACTIVE", "SHUTOFF"],
                        username,
                        timeout=TIMEOUT)
     assert t2 == 0
     return ret
예제 #2
0
 def rebuild(self,
             vm_id,
             image_id,
             name,
             adminPass="",
             metadata="",
             personality="",
             preserve_ephemeral=False,
             username=""):
     '''
     主机从镜像(快照)还原
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id, vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"rebuild": {"imageRef": image_id, "name": name}}
     if adminPass:
         params["rebuild"].update({"adminPass": adminPass})
     if metadata:
         params["rebuild"].update({"metadata": metadata})
     if personality:
         params["rebuild"].update({"personality": personality})
     if preserve_ephemeral:
         params["rebuild"].update({"preserve_ephemeral": True})
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #3
0
파일: vm.py 프로젝트: baifendian/Sirius
 def get_console(self, vm_id,username):
     '''
     主机备份
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id,vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"os-getVNCConsole": {"type": "novnc"}}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #4
0
파일: vm.py 프로젝트: baifendian/Sirius
 def create_backup(self, vm_id, name, rotation, type="daily",username=""):
     '''
     主机备份
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id,vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-uth-Token": token}
     params = {"createBackup": {"name": name, "backup_type": type, "rotation": rotation}}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #5
0
 def get_console(self, vm_id, username):
     '''
     主机备份
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id, vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"os-getVNCConsole": {"type": "novnc"}}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #6
0
 def reboot(self, vm_id, type="HARD", username=""):
     '''
     重启虚拟机
     :param vm_id:
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id, vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"reboot": {"type": type}}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #7
0
파일: vm.py 프로젝트: baifendian/Sirius
 def reboot(self, vm_id, type="HARD",username=""):
     '''
     重启虚拟机
     :param vm_id:
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id,vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"reboot": {"type": type}}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #8
0
파일: vm.py 프로젝트: baifendian/Sirius
 def create_image(self, vm_id, image_name,username):
     '''
     创建镜像
     只有在ACTIVE, SHUTOFF, PAUSED, 或 SUSPENDED的状态下才能制作镜像
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id,vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"createImage": {"name": image_name, "metadata": {"meta_var": "meta_val"}}}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #9
0
파일: vm.py 프로젝트: baifendian/Sirius
 def live_migrate(self, vm_id, host, block_migration, disk_over_commit,username):
     '''
     虚拟机热迁移
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id,vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {
         "os-migrateLive": {"host": host, "block_migration": block_migration, "disk_over_commit": disk_over_commit}}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #10
0
파일: vm.py 프로젝트: baifendian/Sirius
 def get_console_log(self, vm_id, length=0,username=""):
     '''
     获取虚拟机日志
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id,vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"os-getConsoleOutput": {}}
     if length:
         params["os-getConsoleOutput"].update({"length":length})
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #11
0
 def get_console_log(self, vm_id, length=0, username=""):
     '''
     获取虚拟机日志
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id, vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"os-getConsoleOutput": {}}
     if length:
         params["os-getConsoleOutput"].update({"length": length})
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #12
0
파일: vm.py 프로젝트: baifendian/Sirius
 def stop(self, vm_id,username):
     '''
     停止虚拟机
     :param vm_id:
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id,vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"os-stop": ""}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     t1 = run_in_thread(self.wait_complete, vm_id, ["SHUTOFF"],username,timeout=TIMEOUT)
     assert t1 == 0
     return ret
예제 #13
0
 def stop(self, vm_id, username):
     '''
     停止虚拟机
     :param vm_id:
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id, vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"os-stop": ""}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     t1 = run_in_thread(self.wait_complete,
                        vm_id, ["SHUTOFF"],
                        username,
                        timeout=TIMEOUT)
     assert t1 == 0
     return ret
예제 #14
0
 def create_backup(self, vm_id, name, rotation, type="daily", username=""):
     '''
     主机备份
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id, vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-uth-Token": token}
     params = {
         "createBackup": {
             "name": name,
             "backup_type": type,
             "rotation": rotation
         }
     }
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #15
0
파일: vm.py 프로젝트: baifendian/Sirius
 def resize(self, vm_id, flavor_id,username):
     '''
     更改虚拟机flavor类型
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id,vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"resize": {"flavorRef": flavor_id, "OS-DCF:diskConfig": "AUTO"}}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     t1 = run_in_thread(self.wait_complete, vm_id, ["VERIFY_RESIZE"],username,timeout=TIMEOUT)
     assert t1 == 0
     params = {"confirmResize": ""}
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     t2 = run_in_thread(self.wait_complete, vm_id, ["ACTIVE", "SHUTOFF"],username,timeout=TIMEOUT)
     assert t2 == 0
     return ret
예제 #16
0
 def live_migrate(self, vm_id, host, block_migration, disk_over_commit,
                  username):
     '''
     虚拟机热迁移
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id, vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {
         "os-migrateLive": {
             "host": host,
             "block_migration": block_migration,
             "disk_over_commit": disk_over_commit
         }
     }
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #17
0
파일: vm.py 프로젝트: baifendian/Sirius
 def rebuild(self, vm_id, image_id, name, adminPass="", metadata="", personality="", preserve_ephemeral=False,username=""):
     '''
     主机从镜像(快照)还原
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id,vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {"rebuild": {"imageRef": image_id, "name": name}}
     if adminPass:
         params["rebuild"].update({"adminPass": adminPass})
     if metadata:
         params["rebuild"].update({"metadata": metadata})
     if personality:
         params["rebuild"].update({"personality": personality})
     if preserve_ephemeral:
         params["rebuild"].update({"preserve_ephemeral": True})
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret
예제 #18
0
 def create_image(self, vm_id, image_name, username):
     '''
     创建镜像
     只有在ACTIVE, SHUTOFF, PAUSED, 或 SUSPENDED的状态下才能制作镜像
     :return:
     '''
     ret = 0
     token = self.token_dict[username]
     project_id = self.project_id_dict[username]
     assert token != "", "not login"
     path = url_vm_control_action.format(project_id=project_id, vm_id=vm_id)
     method = "POST"
     head = {"Content-Type": "application/json", "X-Auth-Token": token}
     params = {
         "createImage": {
             "name": image_name,
             "metadata": {
                 "meta_var": "meta_val"
             }
         }
     }
     ret = send_request(method, IP_nova, PORT_nova, path, params, head)
     assert ret != 1, "send_request error"
     return ret