[英]Command not fully executing under ssh.net in c#
我正在使用由constructVirtBuilderCommand生成的字符串,並將其用作服務器在xen中生成圖像所需的命令。 但是,該命令返回了多個信息,因為它告知您libvirt在下載映像的過程中執行了多個步驟,返回的第一(也是唯一)信息是“ [2.5]下載: http : //libguestfs.org/ download / builder / ubuntu-18.04.xz “,但這只是以下內容的全部輸出中的一行:
[3.2]下載: http : //libguestfs.org/download/builder/ubuntu-18.04.xz
[4.7]計划如何構建此圖像
[4.7]解壓縮
[14.7]調整大小(使用virt-resize)以將磁盤擴展到15.0G
[497.3]安裝firstboot命令:重新啟動
[497.7]設置密碼
[510.8]完成
Output file: test.img
Output size: 15.0G
Output format: raw
Total usable space: 14.7G
Free space: 13.2G (99%)
這似乎對我造成了問題。 因為命令在返回之前沒有完全執行。 有沒有人有這個問題的經驗? 沒有為我下載任何圖像-如果只有該圖像僅存在片刻,並且在開始下載另一張圖像后文件突然消失。 我已經嘗試了一些方法來強制客戶端等待其完成下載圖像。 第一個是在命令末尾附加“ | grep Finishing”。 我嘗試的第二件事是在命令已完全執行后,使用“> file.txt”生成此文件,但效果不佳。
誰能幫助我弄清楚如何使libvirt完全執行此命令? 如果我在服務器上通過ssh手動將其輸入,則它可以正常工作。 謝謝!
private String constructVirtBuilderCommand()
{
String virt_builder_command = "sudo virt-builder ";
virt_builder_command += operating_system_comboBox.SelectedItem.ToString();
virt_builder_command += "-";
virt_builder_command += operating_system_version_comboBox.SelectedItem.ToString();
virt_builder_command += " --arch ";
virt_builder_command += operating_system_architecture_comboBox.SelectedItem.ToString();
virt_builder_command += " -o nodeand#.img --size ";
virt_builder_command += storage_textBox.Text;
virt_builder_command += "G --root-password password:toor --firstboot-command 'reboot'";
return virt_builder_command;
}
private void add_new_cluster_button_Click(object sender, EventArgs e)
{
if (new_cluster_name_textBox.Text != "")
{
String virtbuilder = constructVirtBuilderCommand();
String virtinstaller = constructVirtInstallCommand();
for (int i=0;i<Int32.Parse(number_of_vms_textBox.Text);i++)
{
String tmp_virtbuilder_command = virtbuilder.Replace("nodeand#", new_cluster_name_textBox.Text + i.ToString());
String tmp_virtbuilder_result = sshclient.CreateCommand(tmp_virtbuilder_command).Execute();
Console.WriteLine(tmp_virtbuilder_result);
}
label19.Text = "completed";
}
else
{
// some error message popup
}
}
編輯:
1)延長超時時間似乎有助於使其進一步融入命令中。 但是由於某種原因,下載的文件會在下一次圖像下載迭代時刪除。 如果超時通過以下方式延長:sshclient.ConnectionInfo.Timeout = TimeSpan.FromSeconds(1000); 然后,我可以在輸出中達到這一點:
[3.2]下載: http : //libguestfs.org/download/builder/ubuntu-18.04.xz
[4.7]計划如何構建此圖像
[4.7]解壓縮
[14.7]調整大小(使用virt-resize)以將磁盤擴展到15.0G
不需要將超時延長到更長的時間,因為這一切都應該很快執行。 我只是將其設置為1000秒,以確保這不是主要問題。
2)如果要重新創建預期的輸出,請輸入:sudo virt-builder centos-7.1 --arch x86_64 -o testc0.img --size 15G --root-password password:toor --firstboot-command'reboot'
進入終端
解決方案是使用sshclient.CreateShellStream(),以使ssh api不會僅僅因為在shell中執行未返回任何內容而返回。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.