2015年9月10日 星期四

透過 Guice 入門 Dependency Injection(二):動態選擇實作類別

作為某些方面可以替代重量級 Spring 的輕量級套件
Guice 可以透過程式碼的設定,動態決定注入介面時,要選擇的實作類別。

透過 Guice 入門 Dependency Injection(一)

Guice 是一個可以用來取代原本 Java 程式設計師習慣使用的 Factory 的套件
某種程度上也可以算是一個輕量級的 Spring,能夠動態地做實作類別的注入。
關於 Guice 的開發動機,可以參考 GitHub 上說明動機的頁面 [1]。
另外如果想知道關於 Guice 開發團隊自己怎麼看 Guice 和 Spring,可以參考 [2]。

2015年9月9日 星期三

[WARNING] Using platform encoding (MS950 actually) to copy filtered resources, i.e. build is platform dependent!

最近突然注意到,Maven 在執行時都會跑出這一段警告訊息
[WARNING] Using platform encoding (MS950 actually) to copy filtered resources, i.e. build is platform dependent!
雖然不影響 Maven 的運作,但就覺得編碼不用 UTF-8 就有點不太對~
很快速地 Google 後,看到別人發表的解法,只要在專案的 pom.xml 裡加入以下的設定
就可以指定 Maven 使用 UTF-8 編碼來執行了。
<project>
    ....
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

參考資料:
  1. Maven compile 出現 [WARNING] Using platform encoding 警告

2015年9月4日 星期五

RabbitMQ 無法使用 guest 帳號登入的問題

 參考資料:
  1. RabbitMQ 3.3.1 can not login with guest/guest

使用 Maven 匯出第三方函式庫

在已經寫好 pom.xml 的情況下,如果需要匯出 pom.xml 上指定的所有第三方函式庫的話
可以使用 Maven 的 copy-dependencies 的功能:
mvn dependency:copy-dependencies
那些第三方函式庫就會被匯出到 ./target/dependency 的目錄裡。

參考資料:
  1. export dependency libs

2015年9月3日 星期四

在 Ubuntu 的 VMware 虛擬機器上安裝 VM Tool

一般安裝 VM Tool 的方法,是參考 [1] 的方式,安裝 VMware Tool
不過在部分作業系統上,因為 VMware 已經支援開源版的 VMware Tool:Open VM Tool 的關係 [2]
可以直接利用指令安裝由虛擬機器自行管理的 VM Tool。

apt-get install open-vm-tools

關於 Open VM Tool 的說明,以下節錄 [2] 的描述:
The primary purpose for open-vm-tools is to enable operating system vendors and/or communities and virtual appliance vendors to bundle VMware Tools into their product releases. open-vm-tools is the open source implementation of VMware Tools and consists of a suite of virtualization utilities that improves the functionality, administration, and management of virtual machines within a VMware environment.

參考資料:
  1. (VMesxi 安裝篇-Day10) Install VMware tools for Linux 
  2. VMware support for open-vm-tools (2073803)

2015年8月31日 星期一

使用 Python 整合 VMware vSphere

pyVmomi [1] 是一個由 VMware 官方釋出的 Python API,可以用來存取 vSphere/vCenter 的資源。
另外有一些簡易的使用範例 [2],可以大略參考要如何開始使用 Python 連接 vSphere/vCenter。
這篇是用來記錄初步介接 vSphere/vCenter 的經驗。

2015年8月27日 星期四

在 gitlab 上更新 fork 出來的專案

在 GitLab 的介面上,可以透過 Fork 的功能,把別人的專案建立一個 fork 到自己的帳號底下
例如原始專案的網址是 http://gitlab/userA/project,fork 出來的專案網址會是 http://gitlab/userB/project。
不過原始專案會由原始專案的專案成員繼續更新,而自己 fork 下來的專案則會停在執行 fork 當時的狀況
如果想要跟著原始專案一起更新的話,需要額外做一點小撇步 [1]。

2015年8月21日 星期五

使用 pyVmomi 時略過 HTTPS 警告

在使用 pyVmomi 連接 VMware 的 API 時,第一個遇到的問題是程式出現以下的警告:
/usr/lib/python2.6/site-packages/requests-2.7.0-py2.6.egg/requests/packages/urllib3/connectionpool.py:768: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html
看起來就是因為連線要使用 HTTPS,但是沒有給予憑證的問題~。
不過簡單地搜尋一下,就看到 [1] 的解法,只要把 requests 這個套件的警告關掉就可以了。
import atexit
import requests
from pyVim import connect

# Disable the checking of certification.
requests.packages.urllib3.disable_warnings()
# Initiate the connection to VMware vSphere.
service_instance = connect.SmartConnect(
        host="192.168.200.200",
        user="administrator@vsphere.local",
        pwd="qwer",
        port=443)
atexit.register(connect.Disconnect, service_instance)

# Get the session ID from the connection.
session_id = service_instance.content.sessionManager.currentSession.key
print("Session ID: %s" % session_id)

程式印出的回覆如下:
Session ID: 521eab6e-7ef1-d7e6-1f67-ba38dd7e2487

參考資料:
  1. Surpress InsecureRequestWarning: Unverified HTTPS request is being made in Python2.6