deprecatesになったBoot2DockerをDocker MachineにMigrationする

たまたまDockerの公式サイトをみたところ以下のような注意書きが。

Note: This release of Docker deprecates the Boot2Docker command line in favor of Docker Machine. Use the Docker Toolbox to install Docker Machine as well as the other Docker tools.

どうやらBoot2Dockerは、deprecatesになったようだ・・。

今はBoot2Dockerに代わってDocker Machineを使用するようなので、公式サイトのBoot2DockerからのMigration方法を参考にMigrationする。

docs.docker.com

Docker Machineをインストールする

Docker Toolboxをダウンロードし、インストールする。インストールを進めていくとDocker Quickstart TerminalまたはKitematicの選択を求められるが、どちらも選択しない。これでdocker-machineコマンドを利用できるようになる。

Boot2DockerからDocker MachineへのMigration

Boot2DockerからのMigration方法に書いてある通り、以下のコマンドを実行する。

$ docker-machine create -d virtualbox --virtualbox-import-boot2docker-vm boot2docker-vm docker-vm

docker-machneのコマンドを叩き、使用できるvmを表示する。

$ docker-machine ls
NAME        ACTIVE   DRIVER       STATE     URL                         SWARM
docker-vm   *        virtualbox   Running   tcp://192.168.1.1:1234

docker-vm環境変数をenvコマンドで取得する。

$ docker-machine env docker-vm
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.1.1:1234"
export DOCKER_CERT_PATH="/Users/horie/.docker/machine/machines/docker-vm"
export DOCKER_MACHINE_NAME="docker-vm"
# Run this command to configure your shell:
# eval "$(docker-machine env docker-vm)"

eval "$(docker-machine env docker-vm)"を実行し、環境変数を定義する。これでdocker clientからdocker-vmを利用してdocker containerを作成できるようになった。毎回↑のコマンドを入力するのは面倒なので、.bashrcや.zshrcなどのshellの設定ファイルにeval "$(docker-machine env docker-vm)"を追加しておく。

hello-world containerを起動する

$ docker run hello-world
Hello from Docker.
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (Assuming it was not already locally available.)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

For more examples and ideas, visit:
 http://docs.docker.com/userguide/

問題なさそう。

参考

Kali LinuxをVirtual Boxにインストールする

サイバーセキュリティプログラミング――Pythonで学ぶハッカーの思考を買った。 読む上でKali Linuxの環境が必要になってくるのでVirtual Box上に用意してみる。

Kali LinuxのISOイメージ用意

f:id:horie1024:20151107150509p:plain

Kali LinuxのサイトからISOイメージ(kali-linux-2.0-amd64.iso)をダウンロードする。

Kali Linuxのインストール

ダウンロードが完了したら以下のサイトを参考にVitrual Boxの仮想マシンを作成し、Kali Linuxをインストールする。

www.websec-room.com

インストールできた。

f:id:horie1024:20151107171047p:plain

AsyncTaskでtimeoutを指定する方法

AsyncTaskを利用してAPIへリクエストする際にTimeOutを指定したい場合がある。そのやり方のメモ。

final SampleTask task = new SampleTask();
task.execute();

// TimeOut処理
new Thread(new Runnable() {
    @Override
    public void run() {
        try {
            // TimeOutに10秒を指定
            // 10秒以内にTaskが終了しなければTimeoutExceptionを投げる
            task.get(10000, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            // Exceptionをキャッチしtaskをキャンセルする
            task.cancel(true);
            e.printStackTrace();
        }
    }
}).start();

Cloud Test Labドキュメントのざっくり翻訳

概要

Cloud Test Labのドキュメントが公開されていたのでトップページだけざっくり翻訳してみた(英語は得意じゃない)。

原文

cloud.google.com

[翻訳] Google Cloud Test Lab

Google Cloud Test Labは、クラウドベースのAndroidアプリテスト環境を提供します。あなたは、たった一つの操作で、あなたのアプリに関するデバイスとデバイス設定を跨いだ幅広いテストを実行できるでしょう。テストの結果は、ログや動画、スクリーンショットを含み、Google Developers Consoleのあなたのプロジェクトから参照可能です。もしあなたがアプリに関するテストコードを書いていないのであれば、Cloud Test Labはあなたのアプリを自動的に動かし、クラッシュを発見するでしょう。

テストを実行する複数の方法

あなたは、アプリをテストする方法を選択できます。

  • Android Studio Pluginの利用して開発環境からアプリが正しい挙動をしているかテストします。
  • Command line interfaceを利用してインタラクティブに実行します。また、あなたの自動ビルド・テストプロセスの一部に組み込めます。
  • Google Developers Consoleに組み込まれたWeb UIを利用し、どこからでもAPKのアップロード、テストを実行できます。

デバイスタイプの選択

Virtual devices

Virtual devicesAndroid端末を正確にシミュレーションします。それらの端末は、テスト実行のスケジューリングについて高可用性を持ち、日々の開発や継続的テストに適しています。

Physical devices

Physical devicesではGoogleのデーターセンターにあるAndroid端末の実機にインストールされ実行されます。実機でのテストはリリース前のテストに適しており、Virtual devicesでのテストでは発見できなかった問題を発見する手助けになるでしょう。

テスト方法の選択

2種類のテスト方法が利用可能です。

Instrumentation tests

Instrumentation testsでは、あなたがEspressoやRobotiumを利用して書いたテストを実行します。

Robo tests

あなたがinstrumentation testsを書いていないのならば、 Robo tests を選択することでシュミレートされたユーザーのアクションによってあなたのアプリをテストできます。Robo testsについての詳細はこちらをご覧ください。

結果を確認する

テストの実行結果を逐次気にしなくても全てのテスト結果はCloud Test Labに集められ、失敗したテストの詳細やログ、動画、スクリーンショットをオンラインで確認できます。より詳しい内容は Analyzing Cloud Test Lab Resultsをご覧ください。

また、AndroidStudioからテストを実行したのであれば、テスト結果をAndroidStudio内から確認できます。

SORACOMのAir SIMの帯域をRubyスクリプトから変更する

概要

ソラコムAir SIMの帯域変更をRubyスクリプトから試した。

SORACOM SDK for Rubyのインストール

$ gem install soracom

Clientの準備

require 'soracom'

client = Soracom::Client.new(email: 'YOUR_EMAIL_ADDRESS', password: 'YOUR_PASSWORD')

emailとpasswordは、それぞれ環境変数SORACOM_EMAILとSORACOM_PASSWORDを定義することでSDKが自動で読み込む。その場合は以下のようになる。

require 'soracom'

client = Soracom::Client.new

SIM一覧取得

require 'soracom'
require 'pp'

client = Soracom::Client.new(email: 'YOUR_EMAIL_ADDRESS', password: 'YOUR_PASSWORD')

# 管理しているSIM一覧を取得
sims = client.list_subscribers

pp sims

実行すると以下のような結果を得れる。

$ ruby soracom.rb
[{"imsi"=>"123456789",
  "msisdn"=>"0987654321",
  "ipAddress"=>"192.168.1.1",
  "apn"=>"soracom.io",
  "type"=>"s1.fast",
  "groupId"=>"12345-6789-abcd-efghijk",
  "createdAt"=>12345,
  "lastModifiedAt"=>6789abc,
  "expiredAt"=>nil,
  "terminationEnabled"=>false,
  "status"=>"active",
  "tags"=>{"name"=>"example"},
  "sessionStatus"=>
   {"lastUpdatedAt"=>123456,
    "imei"=>"123456789",
    "location"=>nil,
    "ueIpAddress"=>"192.168.1.1",
    "dnsServers"=>["192.168.1.1", "192.168.1.1"],
    "online"=>true},
  "speedClass"=>"s1.fast",
  "moduleType"=>"nano",
  "plan"=>0,
  "expiryTime"=>nil,
  "operatorId"=>"1234567",
  "createdTime"=> 12345,
  "lastModifiedTime"=> 6789abc}]

IMSI識別番号の取得

SIM個別に操作するためにIMSIを取得する。

require 'soracom'
require 'pp'

client = Soracom::Client.new(email: 'YOUR_EMAIL_ADDRESS', password: 'YOUR_PASSWORD')

# 管理しているSIM一覧を取得
sims = client.list_subscribers

# IMSI識別番号の取得
imsis = sims.map { |sim| sim['imsi'] }

pp imsis

実行するとIMSIの配列を得られる。

$ ruby soracom.rb
["123456789"]

SIMの通信帯域を制御

SORACOMには4つの速度クラスがあり、それらをユーザーコンソールから変更できる。今回はs1.fastからs1.minimumに変更する。

require 'soracom'

client = Soracom::Client.new(email: 'YOUR_EMAIL_ADDRESS', password: 'YOUR_PASSWORD')

# SIM一覧を取得
sims = client.list_subscribers

p sims.map { |sim| sim['speedClass'] }

# IMSI識別番号の取得
imsis = sims.map { |sim| sim['imsi'] }

client.update_subscriber_speed_class(imsis, 's1.minimum')

# SIMの情報を再取得
p client.list_subscribers.map { |sim| sim['speedClass'] }

実行すると速度クラスが変更され、帯域を制御できた。

$ ruby soracom.rb
["s1.fast"]
["s1.minimum"]

参考