vSphere ESXi shell clone vm instance without vCenter

由於使用的是免費版的 ESXi 在測試,所以沒有 VCenter 的簡便功能可以作很多事,所以要做一些比較複雜的操作就要靠自己了…

我灌的情況比較特別,其實是安裝 ESX  然後輸入 ESXi 的免費序號,不曉得到底是算啥…混合板…= =

有幾種方法可以擴充一些免費版無法做的操作

SDK

SDK 我自己也有抓下來在 windows 的環境跑,要把伺服器上的某個 crt 抓下來設定比較麻煩之外,用起來是蠻容易的,如果要自己整合一些簡單的介面就推薦這種方式囉。他裡面幾乎每個 api 好像都有些 sample 可以直接用。

Vsphere Shell

另外一種是如果 api 不支援,就要登進去灌 vsphere 的主機上,直接用命令對他做操作,大多都是 vm* 開頭的指令,如果是複製 vm 的話可以參考這個網站[1],教你用 Shell vmkfstools 指令去複製 VM,還說明了許多 vm 存放資料概念,

重要的概念是 vmdk 那個檔是存放很多參數,所以複製的時後記得透過 vmkfstools 才不會把內容的名字留下來。

只是複製完了呢?要如何讓 vm client 登入的時候看得到呢?

因為 vsphere 似乎沒辦法直接掃瞄硬碟就察覺有新的 vm 進入,我猜測是是透過內建的資料庫去存放這些資訊,所以除了單純複製資料夾外,就是要對 vsphere 資料庫進行註冊,這就要參考這篇[2]文章了~!,他其實是Scripting-VMware-Power-Tools-Infrastructure 這本書節錄下來的章節,他描述了整個流程,並且寫了幾個不同語言的 script 來做這些事。

  • 新增新的 vm 要存放的資料夾
  • 產生 *.vmx 內容
  • 用 vmkfstools 去複製 *.vmdk , *-flat.vmdk ; vmkfstools -i /vmfs/volumes/Storage1/2003/2003.vmdk -d thin /vmfs/volumes/Storage1/2003c/2003c.vmdk
  • 使用 vmware-cmd -s register *.vmx 去向 vsphere 註冊

而我在作到最後一步的時候發生了 fault.RestrictedVersion.summary 的錯誤,根據[3] 的內容大概推斷是新版本的 ESXi 免費版開始不支援你透過指令去寫 config。

但是由於 vsphere shell 內有很多指令可以用,就另外找到一個[4] 用 vim-cmd 的方式來操作註冊的動作結果就成功了,

[root@esx node] vim-cmd solo/registervm /vmfs/volumes/datastore1/node/node.vmx

但是開機時還是有一些問題,可能是我流程還沒跑完一次,是用複製檔案的方式做的吧~

但是他卡在 95% 時就問我問題…問我說是不是 copy 他的映像檔…進 console 就能回答= =我就回答 我 copy it …就開機了?

只是應該要注意共用實體的問題。

參考資源:

  1. 在ESX中把玩VM的虛擬硬碟 http://vaemon.com/article/910.html
  2. Cloning Virtual Machines Utilizing ESX Shell Scripts http://searchsystemschannel.techtarget.com/feature/Cloning-Virtual-Machines-Utilizing-ESX-Shell-Scripts
  3. http://vmetc.com/2009/03/31/esxi-u4-ends-free-version-read-and-write-access-from-the-rcli/
  4. http://www.virtuallyghetto.com/p/vmware-vimsh_9940.html

單字記憶

最近在思考要怎麼樣激起大腦運作,會有這種大腦記憶在運作的感覺通常都是在背單字的時候,

如果一直看著單字書一行一行看~依照我自己的資質…看過等於沒看過,但有時候會在日常生活中突然想起一個字,然後忘記怎麼拼他念他或者意思是什麼,

然後當這個念頭出來後再去查他以後,通常這個字就會記憶的比較深刻。

或者在背題庫時,遮住答案讓自己思考,當大腦運轉一段時間想不起來以後,再去看答案,通常都會有不錯的記憶效果。

其實這種情況大多是在大量閱讀英文書的時候比較常發生…因為背單字書頗無聊…很久沒做了…裡面的例句也比較沒辦法激起自己共鳴

但是腦子通常都會偷懶,想盡辦法不要運作…,就會很想快點看答案或者以其他方式閃躲掉運作…。

還沒有辦法很精準的控制自己與瞭解自己大腦的運作…

 

前陣子看了成寒的一些英文書,他裡面有一套學習英文的方式跟邏輯,有個部份是單字背誦的方式,也大概是上述的遮住記憶,然後用筆記本搭配一個重複複習的模式,來背誦單字。

最近想說可以練習寫個小程式,用基於這種模式來建立自己的單字庫跟複習模式系統,應該會剖有趣的吧,因為有時候自己看到一些特別的單字,想要背卻不曉得要用什麼方式去紀錄跟複習。

 

應該可以仿照現在流行的 twitter or facebook 的方式一小格一小格條列下去…然後另一條是每一天固定要複習的單字…聽起來應該蠻有實現的可能的…如果在搭配聽力@@好像也不錯…聲音化

Python shell history Substitution

在 linux 更新成 Python 2.7 後進入他 shell 以後發現,按上下鍵想要查尋歷史紀錄竟然只出現  ^[[A ,這些符號…感覺有點糟糕…

找了許多才發現原來是少安裝一個函式庫,不曉得是 readline 還是 ncureses ,管他的都裝…= =

ncureses 是一個提供在文字介面操作的 API 函式庫。應該跟文字介面上下左右事件監控有關。


yum install ncurses

yum install ncurses-devel
easy_install readline

ncurses 似乎還蠻有趣的,linux kernel menu config 好像就是用他寫的…
網路[3]上看到一個範例可以跑跑看…

#include <curses.h>
#include <stdlib.h>

#define ENTER 10
#define ESCAPE 27
void init_curses()
{
        initscr();
        start_color();
        init_pair(1,COLOR_WHITE,COLOR_BLUE);
        init_pair(2,COLOR_BLUE,COLOR_WHITE);
        init_pair(3,COLOR_RED,COLOR_WHITE);
        curs_set(0);
        noecho();
        keypad(stdscr,TRUE);
}
void draw_menubar(WINDOW *menubar)
{
        wbkgd(menubar,COLOR_PAIR(2));
        waddstr(menubar,"Menu1");
        wattron(menubar,COLOR_PAIR(3));
        waddstr(menubar,"(F1)");
        wattroff(menubar,COLOR_PAIR(3));
        wmove(menubar,0,20);
        waddstr(menubar,"Menu2");
        wattron(menubar,COLOR_PAIR(3));
        waddstr(menubar,"(F2)");
        wattroff(menubar,COLOR_PAIR(3));
}
WINDOW **draw_menu(int start_col)
{
        int i;
        WINDOW **items;
        items=(WINDOW **)malloc(9*sizeof(WINDOW *));

        items[0]=newwin(10,19,1,start_col);
        wbkgd(items[0],COLOR_PAIR(2));
        box(items[0],ACS_VLINE,ACS_HLINE);
        items[1]=subwin(items[0],1,17,2,start_col+1);
        items[2]=subwin(items[0],1,17,3,start_col+1);
        items[3]=subwin(items[0],1,17,4,start_col+1);
        items[4]=subwin(items[0],1,17,5,start_col+1);
        items[5]=subwin(items[0],1,17,6,start_col+1);
        items[6]=subwin(items[0],1,17,7,start_col+1);
        items[7]=subwin(items[0],1,17,8,start_col+1);
        items[8]=subwin(items[0],1,17,9,start_col+1);
        for (i=1;i<9;i++)
                wprintw(items[i],"Item%d",i);
        wbkgd(items[1],COLOR_PAIR(1));
        wrefresh(items[0]);
        return items;
}
void delete_menu(WINDOW **items,int count)
{
        int i;
        for (i=0;i<count;i++)
                delwin(items[i]);
        free(items);
}
int scroll_menu(WINDOW **items,int count,int menu_start_col)
{
        int key;
        int selected=0;
        while (1) {
                key=getch();
                if (key==KEY_DOWN || key==KEY_UP) {
                        wbkgd(items[selected+1],COLOR_PAIR(2));
                        wnoutrefresh(items[selected+1]);
                        if (key==KEY_DOWN) {
                                selected=(selected+1) % count;
                        } else {
                                selected=(selected+count-1) % count;
                        }
                        wbkgd(items[selected+1],COLOR_PAIR(1));
                        wnoutrefresh(items[selected+1]);
                        doupdate();
                } else if (key==KEY_LEFT || key==KEY_RIGHT) {
                        delete_menu(items,count+1);
                        touchwin(stdscr);
                        refresh();
                        items=draw_menu(20-menu_start_col);
                        return scroll_menu(items,8,20-menu_start_col);
                } else if (key==ESCAPE) {
                        return -1;
                } else if (key==ENTER) {
                        return selected;
                }
        }
}
int main()
{
    int key;
    WINDOW *menubar,*messagebar;

    init_curses();

    bkgd(COLOR_PAIR(1));
    menubar=subwin(stdscr,1,80,0,0);
    messagebar=subwin(stdscr,1,79,23,1);
    draw_menubar(menubar);
    move(2,1);
    printw("Press F1 or F2 to open the menus. ");
    printw("ESC quits.");
    refresh();

    do {
        int selected_item;
        WINDOW **menu_items;
        key=getch();
        werase(messagebar);
        wrefresh(messagebar);
        if (key==KEY_F(1)) {
            menu_items=draw_menu(0);
            selected_item=scroll_menu(menu_items,8,0);
            delete_menu(menu_items,9);
            if (selected_item<0)
                wprintw(messagebar,"You haven't selected any item.");
            else
                wprintw(messagebar,
                  "You have selected menu item %d.",selected_item+1);
            touchwin(stdscr);
            refresh();
        } else if (key==KEY_F(2)) {
            menu_items=draw_menu(20);
            selected_item=scroll_menu(menu_items,8,20);
            delete_menu(menu_items,9);
            if (selected_item<0)
                wprintw(messagebar,"You haven't selected any item.");
            else
                wprintw(messagebar,
                  "You have selected menu item %d.",selected_item+1);
            touchwin(stdscr);
            refresh();
        }
    } while (key!=ESCAPE);

    delwin(menubar);
    delwin(messagebar);
    endwin();
    return 0;
}

參考資源:

cassandra and django and twissandra

一個完整簡潔有力的學習專案,twissandra 用 django 與 cassandra 實作 twitter 最簡單重要的功能,有網頁介面。

此專案展示了 cassandra 資料模型的設計以及 API 的使用,又能大略學習 django 的簡單使用,安裝與運作又十分容易,

後端 API 是採用 high level api pycassa ,原先是 Thrift ,而透過 pycassa 做中介層,幫忙做一些控管讓資料存取更順暢。

資料來源

  1. twissandra https://github.com/ericflo/twissandra
  2. pycassa https://github.com/pycassa/pycassa
  3. django http://djangoproject.com