cocoa*life
Upgrading VMWare vSphere Hypervisor (ESXi) 4.1 to 4.1 Update 1 through SSH
- 2011-05-22 (Sun)
- UN*X
I upgraded VMWare vSphere Hypervisor (ESXi) 4.1 to 4.1 Update 1 through ssh, and here’s the way.
First, you must enable SSH by the console or vSphere Client. The following web page shows the detail process for it, but I have not set up the non-root user yet.
After that, you can login as root user (if you’ve set up non-root user, use it).
$ ssh root@esxi-server-ip
To enter the maintenance mode, shutdown all virtual machines. I don’t know the way of shutting down all at once, and execute the command many times.
# vim-cmd vmsvc/power.shutdown <vmid>
You can use this command in order to know the vmid.
# vim-cmd vmsvc/getallvms
Enter the maintenance mode.
# vim-cmd hostsvc/maintenance_mode_enter
Download the update file (update-from-esxi4.1-4.1_update01.zip), and send it by SCP. Since ESXi server, however, doesn’t have ‘unzip’ program, I unzipped the files on my Mac and send the directory.
$ scp -r update-from-esxi4 root@esxi-server-ip:/vmfs/volumes/Your-Data-Storage-Name
You can check the data storage name by the command `ls /vmfs/volumes/`.
The preparation step is done, and go!
# cd /vmfs/volumes/Your-Data-Storage-Name/update-from-esxi4 # esxupdate update -m metadata.zip
After updated, you must exit maintenance mode and reboot the machine.
# vim-cmd hostsvc/maintenance_mode_exit # reboot
Finally, you can check the current version of Hypervisor by the following command.
# vmware -v VMware ESXi 4.1.0 build-348481
References
- ESXi (ESX 4i) Enable SSH
- ESXiにSSHでログインしてよく使うコマンド | ホゲホゲロック (in Japanese)
- VMware/ESXi/VMware Infrastructure Remote CLIを利用する – きのさいと (in Japanese)
- [VMware] VMware ESXiを4.0.0から4.1.0へアップデートする方法: Akito’s IT技術 メモ (in Japanese)
- ehsia.com – my stuff and reviews » SCP to ESXi in Mac OS X
- VMware Communities: how to check esx version from command…
- Comments: 0
- Trackbacks: 0
Get current time in UTC, suitable for file name
- 2011-04-12 (Tue)
- UN*X
Using the following ‘date’ command, we can get current time in UTC whose format is suitable for such as file name.
$ date -u "+%Y%m%d%H%M%S" $ 20110412065955
- Comments: 0
- Trackbacks: 0
How to use Xcode 3 color themes in Xcode 4
- 2011-03-30 (Wed)
- Cocoa
I’m using either MyBlackboard (In Japanese) or Railscasts color themes in Xcode 3, these color themes, however, couldn’t be used in Xcode 4.
I want to convert 3′s xccolortheme files into 4′s dvtcolortheme files, and found the just script which converted it.
mrevilme’s gist: 488120 — Gist
The usage of this tiny python script is very simple like the following command.
$ xcode3_theme_to_xcode4.py MyBlackBoard.xcolortheme
This step is very quick, and finally, I moved the dvtcolortheme file to the directory.
mkdir -p ~/Library/Developer/Xcode/UserData/FontAndColorThemes/ mv MyBlackBoard.dvtcolortheme ~/Library/Developer/Xcode/UserData/FontAndColorThemes/
If you’ve already started Xcode, restart it and you’ll find the theme at the preference of Xcode.
References
- Comments: 1
- Trackbacks: 0
Plantronics Discovery 975 Bluetooth Headset の Tips
- 2011-02-06 (Sun)
- Technology
Plantronics Discovery 975 Bluetooth Headset という Bluetooth で使うヘッドセットを購入しました。

微妙にいくつかの点ではまったので、備忘録を残しておくことにします。
- 2010年のマニュアルは一部情報が削除されている。MyHeadset.jp | Bluetooth イヤーピース Discovery 975で見られるマニュアルを参照する。
- デフォルトではオフになっているマルチポイント接続機能をオンにしないと2台で使えない。
- ペアリングは電源を切ってから。コントロールボタンを長押しすれば、赤白に点滅してペアリングモードに入れる。
- Amazon.com で購入した方が安い。
ヘッドセットを購入したのはこれが初めてですが、普通のイヤホンであれば落ちてしまう自分の耳からも落ちずにクリアな音で使えるのがとてもいいと思いました。
参考文献
- Comments: 0
- Trackbacks: 0
How to create OAuth / xAuth Service Provider in Ruby on Rails with devise
- 2011-02-04 (Fri)
- Ruby on Rails
At previous entiry I wrote a sample how to support xAuth in Ruby Application.
In this entry, I write how to create the OAuth/xAuth Service Provider in Ruby on Rails project which uses devise plugin for authentication.
OAuth support when you use devise plugin
Installation
First of all, I’m about to write the way of supporting OAuth using OAuth plugin.
pelle/oauth-plugin – GitHub
OAuth plugin supports Rails 3 after version 0.4.0.pre1, and add Gemfile the following line.
gem "oauth-plugin", ">=0.4.0.pre1"
The installation tutorials are written in the github plugin page.
devise plugin support
In addition, to use OAuth plugin in the project which utilize devise, you need to support two methods “login_required” and “logged_in?” Devise uses such helper methods as “authenticate_#{model_name}” and “#{model_name}_signed_in?”, I wrote two helper methods.
[lib/lindoc/oauth_helpers.rb]
module Lindoc
module OauthHelpers
def self.included(recipient)
recipient.extend(ClassMethods)
recipient.class_eval do
include InstanceMethods
end
end
module InstanceMethods
def login_required
authenticate_user!
end
def logged_in?
user_signed_in?
end
end
end
end
At the controllers associated with OAuth, add this helper methods like the this.
[$RAILS_ROOT/app/oauth_clients_controller.rb]
class OauthClientsController < ApplicationController include Lindoc::OauthHelpers ... end
[$RAILS_ROOT/app/oauth_controller.rb]
require 'oauth/controllers/provider_controller' class OauthController < ApplicationController include OAuth::Controllers::ProviderController include Lindoc::OauthHelpers ... end
Since I want to use OAuth / xAuth authentication at API of our service, also added :oauth_required filter.
[app/controllers/api/v1/api_controller.rb]
class Api::V1::ApiController < ApplicationController include Lindoc::OauthHelpers before_filter :oauth_required ... end
Rails nested parameters support
Client applications often post data in nested parameters like “foo[bar]=baz” to Rails application, but OAuth plugin doesn’t currently support this type of parameters. The reason why OAuth plugin doesn’t, is that this plugin doesn’t consider this type when it calculates a signature the way of which is written in the specification of OAuth, and answers a bad/invalid signature. So, you need to add support by overriding the method which helps calculate it.
This solution is written at Issue page of OAuth plugin.
parameter normalisation issues Nesting parameters causes problems.
[config/initializers/oauth.rb]
module OAuth
module Helper
# see https://github.com/pelle/oauth/issues#issue/8
def normalize(params)
params.sort.map do |k, values|
if values.is_a?(Array)
# multiple values were provided for a single key
values.sort.collect do |v|
[escape(k),escape(v)] * "="
end
elsif values.is_a?(Hash)
key = k
values.sort.collect do |k, v|
[escape("#{key}[#{k}]"),escape(v)] * "="
end
else
[escape(k),escape(values)] * "="
end
end * "&"
end
end
end]
xAuth support
xAuth is the authentication method which is used in twitter to support desktop/mobile applications. If you want to know how to use xAuth in your applications, you should read this document.
Using xAuth | dev.twitter.com
client application restriction
Like twitter, I want to restrict client applications which can use xAuth authentication, and I add column to decide it.
[db/migrate/xxx_create_oauth_table.rb]
class CreateOauthTables < ActiveRecord::Migration
def self.up
create_table :client_applications do |t|
...
t.boolean :xauth_enabled, :default => false
t.timestamps
end
...
end
end
/oauth/access_token signature verification method change
In OAuth 1.0 specification, service provider must verify a signature which consists of both Authentication header and GET or POST parameters called “Signature Base String”, and signed by both Consumer Secret and Access Token Secret. This verification step is implemented as filter “two_legged” or “oauth10_request_token” in OAuth plugin, OAuth::Controllers::ProviderController.
[oauth-plugin/lib/oauth/controllers/provider_controller.rb]
module OAuth
module Controllers
module ProviderController
def self.included(controller)
controller.class_eval do
...
oauthenticate :strategies => :two_legged, :interactive => false, :only => [:request_token]
oauthenticate :strategies => :oauth10_request_token, :interactive => false, :only => [:access_token]
...
The simplified difference of these two methods is to use or not to use request token. You need to change signature verification method of /oauth/access_token when you request Access Token by xAuth, because unlike OAuth clients, xAuth clients don’t have request token.
For that reason, to support xAuth, if request has “x_auth_mode=client_auth” in POST parametes which indicate client applications want to authenticate by xAuth, “two_legged” filter should be applied. I used “alias_method_chain” to seperate xAuth and OAuth authentication.
[config/initializers/oauth.rb]
module OAuth
module Controllers
module ApplicationControllerMethods
class Authenticator
def oauth10_request_token_with_xauth
if params[:x_auth_mode] == 'client_auth'
# xAuth authentication
two_legged
else
# OAuth authentication
oauth10_request_token_without_xauth
end
end
alias_method_chain :oauth10_request_token, :xauth
end
end
end
end
/oauth/access_token user verification
In /oauth/access_token request, you also verify the user using his username and password. If there is a “x_auth_mode=client_auth” POST parameter in request, verify the user and response Access Token.
[$RAILS_ROOT/app/oauth_controller.rb]
require 'oauth/controllers/provider_controller'
class OauthController < ApplicationController
include OAuth::Controllers::ProviderController
include Lindoc::OauthHelpers
....
private
def access_token_with_xauth
# To use custom failure response with devise, you need the following line.
# see https://github.com/plataformatec/devise/wiki/How-To:-Provide-a-custom-failure-response-with-Warden
warden.custom_failure!
if params[:x_auth_mode] == 'client_auth'
render_unauthorized = Proc.new do
render :nothing => true, :status => 401
end
# We support screen name and email to login
user = User.find_for_database_authentication({ :screen_name_or_email => params[:x_auth_username] })
if user &&
user.valid_password?(params[:x_auth_password]) &&
current_client_application.xauth_enabled
@token = AccessToken.where(:user_id.eq => user,
:client_application_id.eq => current_client_application,
:invalidated_at.eq => nil).limit(1).first
@token = AccessToken.create(:user => user, :client_application => current_client_application) if @token.blank?
if @token
render :text => @token.to_query
else
render_unauthorized.call
end
else
render_unauthorized.call
end
else
access_token_without_xauth
end
end
alias_method_chain :access_token, :xauth
end
References
- Comments: 4
- Trackbacks: 1
How to support OAuth in ASIHTTPRequest
- 2011-01-24 (Mon)
- Cocoa
ASIHTTPRequest is a brilliant library, when you want to handle HTTP requests.
At this time, however, this library doesn’t support OAuth.
You can support it easily with OAuthCore library which is developed by atebits who is the developer of Tweetie a.k.a. Twitter for Mac/iPhone.
atebits / OAuthCore / overview – Bitbucket
A sample code is following.
#import "OAuthCore.h"
NSString * const CONSUMER_KEY = @"YOUR_CONSUMER_KEY";
NSString * const CONSUMER_SECRET = @"YOUR_CONSUMER_SECRET";
NSString * const ACCESS_TOKEN = @"YOUR_ACCESS_TOKEN";
NSString * const ACCESS_TOKEN_SECRET = @"YOUR_ACCESS_TOKEN_SECRET";
NSURL *URL = [NSURL URLWithString:@"http://example.com/api"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:URL];
[request setPostValue:@"test" forKey:@"test_value"];
[request buildPostBody];
NSString *header = OAuthorizationHeader([request url],
[request requestMethod],
[request postBody],
CONSUMER_KEY,
CONSUMER_SECRET,
ACCESS_TOKEN,
ACCESS_TOKEN_SECRET);
[request addRequestHeader:@"Authorization" value:header];
If you want to get “Access Token” and “Access Toke Secret”, such as you authorize with xAuth, you should set both ACCESS_TOKEN and ACCESS_TOKEN_SECRET, not nil but @”".
References
- Comments: 0
- Trackbacks: 0
xAuth Consumer Sample using Ruby
- 2011-01-21 (Fri)
- Ruby
I’m developing OAuth/xAuth Service Provider using OAuth / OAuth-Plugin.
pelle/oauth-plugin – GitHub
Since OAuth-Plugin doesn’t support xAuth, I decided to create a program to support it.
I’ll write an entry about xAuth support, before that, I write this entry about sample of using xAuth in Ruby.
You need to install Ruby OAuth Gem.
require 'oauth'
CONSUMER_KEY = 'Your-Consumer-Key'
CONSUMER_SECRET = 'Your-Consumer-Secret'
def get_access_token
consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => 'Your-OAUTH-Provider-URL')
access_token = consumer.get_access_token(nil, {}, { :x_auth_mode => 'client_auth', :x_auth_username => 'Your-User-Name', :x_auth_password => 'Your-Password' })
[access_token.token, access_token.secret]
end
def access_api(token, secret)
consumer = OAuth::Consumer.new(CONSUMER_KEY, CONSUMER_SECRET, :site => 'Your-OAuth-Provider-URL')
access_token = OAuth::AccessToken.new(consumer, token, secret)
access_token.get('Your-API-URL')
end
token, secret = get_access_token
p "token: #{token}"
p "secret: #{secret}"
response = access_api(token, secret)
p response
References
- Comments: 0
- Trackbacks: 1
Find Skype Chat ID with rb-skypemac
- 2011-01-10 (Mon)
- Ruby
Each Skype chat has an unique chat ID like “#hogehoge/XXXXXXXXXXXXXXXX”.
This ID has very important role when you handle Skype with another programs/scripts like rb-skypemac (Ruby Gem).
rb skypemac
There is a very simple method to find IDs with rb-skypemac.
irb > require 'rb-skypemac' => true irb > SkypeMac::Skype.send_(:command => 'SEARCH RECENTCHATS') => "CHATS #hogehoge/XXXXXXXXXXXXXXXX, #piyopiyo/XXXXXXXXXXXXXXXX"
After this command, you should select the appropriate ID.
- Comments: 0
- Trackbacks: 0
Remove extra white-spaces using zsh function
- 2011-01-07 (Fri)
- UN*X
I want to remove easily extra white-spaces and tabs from source codes.
There are a lot of samples using shell scirpts, and I write a tiny script using a zsh function.
I utilize this sample (In Japanese).
funciton rw() {
for i
do
mv $i $i.tmp
sed -e 's/[[:blank:]]*$//' $i.tmp > $i
rm $i.tmp
done
}
This function should be written in your .zshrc file.
To use this script, only you have to do is to type like this.
rw /path/to/*.rb
References
- Comments: 0
- Trackbacks: 0
Installing Chef Server with RVM
- 2010-12-23 (Thu)
- Ruby
Chef is a systems integration framework, built to bring the benefits of configuration management to your entire infrastructure.
The tutorials of install, and basic usage are written here.
I want to use it with RVM’s Ruby on Ubuntu Server 10.10.
RVM Installation
I use RVM with system wide install, whose instruction is here.
RVM: Ruby Version Manager – Installing RVM System Wide
chef-server# apt-get install curl git-core chef-server# bash < <( curl -L http://bit.ly/rvm-install-system-wide )
Ruby 1.9.2 Installation
After installed RVM, you need to install Ruby 1.9.2 with RVM.
chef-server# apt-get install build-essential libssl-dev zlib1g-dev libreadline-dev chef-server# source '/usr/local/lib/rvm' chef-server# rvm install 1.9.2 -C --with-readline-dir=/usr --with-openssl-dir=/usr --with-zlib-dir=/usr
Bootstrap Chef-Server Installation
Now, you are prepared for installing Chef.
There is a nice tutorial for bootstrap installation of Chef-Server.
Bootstrap Chef RubyGems Installation – Chef – Opscode Open Source Wiki
Chef Solo Attributes Configuration
chef-server$ vi ~/chef.json
{
"chef": {
"server_url": "http://localhost:4000"
},
"run_list": [ "recipe[chef::bootstrap_server]" ]
}
Temporary PATH configuration
Before using Rubygems, you should set PATH configuration temporary, because I want to use chef to set all configurations.
chef-server# source '/usr/local/lib/rvm' chef-server# rvm use 1.9.2 chef-server# gem install chef
Other Necessary Packages Installation
chef-server# apt-get install wget ssl-cert chef-server# gem install chef
Chef Solo Installation
chef-server# mkdir -p /etc/chef chef-server# vi /etc/chef/solo.rb
The content of “/etc/chef/solo.rb” is following.
file_cache_path "/tmp/chef-solo" cookbook_path "/tmp/chef-solo/cookbooks"
You can use `chef-solo` command to install chef-server.
chef-server# chef-solo -c /etc/chef/solo.rb -j ~/chef.json -r http://s3.amazonaws.com/chef-solo/bootstrap-latest.tar.gz
chef-client, chef-server, chef-solr, chef-solr-indexer run script PATH configuration
Having finished installing, you will notice that chef-* fail to start on looking at logs “/etc/sv/chef-*/logs/main/current”.
The reason of this failure is that Ruby and Gems PATH are not set correctly, so you should set them like this.
chef-server# vi /etc/sv/{chef-client, chef-server, chef-solr, chef-solr-indexer}/run
- PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin --- + export PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/rvm/gems/ruby-1.9.2-p0/bin + export GEM_HOME=/usr/local/rvm/gems/ruby-1.9.2-p0 + export GEM_PATH=/usr/local/rvm/gems/ruby-1.9.2-p0
These chef processes are watched by “runit”, and after you rewrite them, all processes will start correctly.
If you want to start/stop/restart manually, use `/etc/init.d/chef-* {start/stop/restart}` command.
要は、PATH の設定だけちゃんとやっておけば RVM でインストールした Ruby でも Chef はインストールできますよということです。
References
- Bootstrap Chef RubyGems Installation – Chef – Opscode Open Source Wiki
- Chefを試してみた – ひげろぐ (Japanese)
- chef-soloで作業環境構築の自動化 – ひげろぐ (Japanese)
- Chefを最速で使いこなすためのいくつかのポイント – Masatomo Nakano Blog (Japanese)
- [chef] – pochiのメモ帳 (Japanese)
- Comments: 0
- Trackbacks: 1
