Example #1
0
        private string applyVersionOneFiles()
        {
            RelatedTask = Task.create(Session, "importTask", Messages.IMPORTING);

            try
            {
                long totalSize    = getSize(new DirectoryInfo(m_filename), 0);
                long bytesWritten = 0;

                if (totalSize == 0)
                {
                    // We didn't find any .gz files, just bail out here
                    throw new Exception(Messages.IMPORT_INCOMPLETE_FILES);
                }

                CommandLib.Config config = new CommandLib.Config
                {
                    hostname = Connection.Hostname,
                    username = Connection.Username,
                    password = Connection.Password
                };

                CommandLib.thinCLIProtocol tCLIprotocol = null;
                int exitCode = 0;
                tCLIprotocol = new CommandLib.thinCLIProtocol(delegate(string s) { throw new Exception(s); },
                                                              delegate { throw new Exception(Messages.EXPORTVM_NOT_HAPPEN); },
                                                              delegate(string s, CommandLib.thinCLIProtocol t) { log.Debug(s); },
                                                              delegate(string s) { log.Debug(s); },
                                                              delegate(string s) { log.Debug(s); },
                                                              delegate { throw new Exception(Messages.EXPORTVM_NOT_HAPPEN); },
                                                              delegate(int i)
                {
                    exitCode             = i;
                    tCLIprotocol.dropOut = true;
                },
                                                              delegate(int i)
                {
                    bytesWritten   += i;
                    PercentComplete = (int)(100.0 * bytesWritten / totalSize);
                },
                                                              config);

                string body = string.Format("vm-import\nsr-uuid={0}\nfilename={1}\ntask_id={2}\n",
                                            SR.uuid, m_filename, RelatedTask.opaque_ref);
                log.DebugFormat("Importing Geneva-style XVA from {0} to SR {1} using {2}", m_filename, SR.Name(), body);
                CommandLib.Messages.performCommand(body, tCLIprotocol);

                // Check the task status -- Geneva-style XVAs don't raise an error, so we need to check manually.
                List <string> excep = TaskErrorInfo();
                if (excep.Count > 0)
                {
                    throw new Failure(excep);
                }

                // CA-33665: We found a situation before were the task handling had been messed up, we should check the exit code as a failsafe
                if (exitCode != 0)
                {
                    throw new Failure(new[] { Messages.IMPORT_GENERIC_FAIL });
                }

                return(Task.get_result(Session, RelatedTask));
            }
            catch (Exception exn)
            {
                List <string> excep = TaskErrorInfo();
                if (excep.Count > 0)
                {
                    throw new Failure(excep);
                }
                else
                {
                    throw exn;
                }
            }
            finally
            {
                Task.destroy(Session, RelatedTask);
            }
        }
Example #2
0
        private string applyVersionOneFiles()
        {
            RelatedTask = Task.create(Session, "importTask", Messages.IMPORTING);

            try
            {
                long totalSize = getSize(new DirectoryInfo(m_filename), 0);
                long bytesWritten = 0;

                if (totalSize == 0)
                {
                    // We didn't find any .gz files, just bail out here
                    throw new Exception(Messages.IMPORT_INCOMPLETE_FILES);
                }

                CommandLib.Config config = new CommandLib.Config
                                           	{
                                           		hostname = Connection.Hostname,
                                           		username = Connection.Username,
                                           		password = Connection.Password
                                           	};

                CommandLib.thinCLIProtocol tCLIprotocol = null;
                int exitCode = 0;
                tCLIprotocol = new CommandLib.thinCLIProtocol(delegate(string s) { throw new Exception(s); },
                                                              delegate { throw new Exception(Messages.EXPORTVM_NOT_HAPPEN); },
                                                              delegate(string s, CommandLib.thinCLIProtocol t) { log.Debug(s); },
                                                              delegate(string s) { log.Debug(s); },
                                                              delegate(string s) { log.Debug(s); },
                                                              delegate { throw new Exception(Messages.EXPORTVM_NOT_HAPPEN); },
                                                              delegate(int i)
                                                              	{
                                                              		exitCode = i;
                                                              		tCLIprotocol.dropOut = true;
                                                              	},
                                                              delegate(int i)
                                                              	{
                                                              		bytesWritten += i;
                                                              		PercentComplete = (int)(100.0*bytesWritten/totalSize);
                                                              	},
                                                              config);

                string body = string.Format("vm-import\nsr-uuid={0}\nfilename={1}\ntask_id={2}\n",
                                            SR.uuid, m_filename, RelatedTask.opaque_ref);
                log.DebugFormat("Importing Geneva-style XVA from {0} to SR {1} using {2}", m_filename, SR.Name, body);
                CommandLib.Messages.performCommand(body, tCLIprotocol);

                // Check the task status -- Geneva-style XVAs don't raise an error, so we need to check manually.
                List<string> excep = TaskErrorInfo();
                if (excep.Count > 0)
                    throw new Failure(excep);

                // CA-33665: We found a situation before were the task handling had been messed up, we should check the exit code as a failsafe
                if (exitCode != 0)
                    throw new Failure(new[] {Messages.IMPORT_GENERIC_FAIL});

                return Task.get_result(Session, RelatedTask);
            }
            catch (Exception exn)
            {
                List<string> excep = TaskErrorInfo();
                if (excep.Count > 0)
                    throw new Failure(excep);
                else
                    throw exn;
            }
            finally
            {
                Task.destroy(Session, RelatedTask);
            }
        }