vagrant-sakura 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 945fc69723e0d563c7daeb0ae6a40271166dbcf6
4
- data.tar.gz: c7ce8eaf073dc58e7408507907bc1c695a8005ae
2
+ SHA256:
3
+ metadata.gz: 8710a8b87c7c07ffeb170510c46699d89a2b24da2dbf92928c1e655cfa333d88
4
+ data.tar.gz: 5969024cdd2bc5db362b811ee69b1a3b1dd4df5d6b277909eea45122d6bebfe2
5
5
  SHA512:
6
- metadata.gz: f75e242e6e681c00957bef08bfbc9d0843d07fd0dc99e8492f8c2adce5bd287a414634078afcd1e5555810ec682167933954929ee06585ea4df0b5b09e75032d
7
- data.tar.gz: 870c6fb96b0cc5ae989ebbe6ae73c18c4fa50fb87de7d159341235edbcbe852274339f62f8d8ac0a359194d819f0d7bc82c6abe53742c00250bea7dac16e82a0
6
+ metadata.gz: cb1570c46e1d5135fe342b227e41bd91303af5d993cc43c2f490136cf2ae3806d1d47ee17206c3505eb1817df68b55c2bd46754f541cfcdbf36d4e6dee59c54a
7
+ data.tar.gz: ca48864c5e4de22d8838cd97d813c5ec1463cdf0805641fa2cb3649d6036888ccade416220d04985ec15a640c83bb0fafc74a9e1069ce9d1e68bb6ec2bcdc4d5
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ spec/reports
17
17
  test/tmp
18
18
  test/version_tmp
19
19
  tmp
20
+ vendor/
data/.travis.yml ADDED
@@ -0,0 +1,30 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+
5
+ addons:
6
+ apt:
7
+ packages:
8
+ - bsdtar
9
+ rvm:
10
+ - 2.3.7
11
+ - 2.4.4
12
+ - 2.5.0
13
+ - 2.5.1
14
+
15
+ env:
16
+ global:
17
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
18
+
19
+ script: bundle exec rake test
20
+
21
+ deploy:
22
+ provider: rubygems
23
+ api_key:
24
+ secure: dPtjpKnaDadiUGiO/ZZG+CK0GRChirb6qbr5UawJff3X1POtU/Q7AXOfwYkMEZv55NT098jvtqPDcAA7ilqQu6Pb1YO51FnHqXk5UPqksCMcAucQX6ByL3V1X8Vliw2rbvKw8BTg9IoNotu6bDIFMDdU0Gz0iU35U9efkxIX+Rc=
25
+ on:
26
+ tags: true
27
+
28
+ notifications:
29
+ slack:
30
+ secure: d9jmDMPRbEHfKTmY+FqYNovtDTag+NNBVE2W3YYkGLp4QCGiaHSlV6rCDDmX02fUOtLgA1FrsJJpS17/3sBG6JX3aWh4wIWW8XCzrzUmItWa25J/Fj3KutbJN0pYXeEVDR8Cw0OoAZpzlgBOBbe5mcCpPhHhe3gTUaRBxqCiQII=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.1.0 (2018/09/10)
4
+
5
+ - Use usacloud config (#28)
6
+ - Use TravisCI (#29)
7
+ - Add startup script config (#31)
8
+ - Add packer filter config (#32)
9
+ - Add os_type config (#33)
10
+ - Add sakura-reinstall command (#36)
11
+ - Add enable_pw_auth config (#37)
12
+
3
13
  ## 0.0.9 (2018/07/13)
4
14
 
5
15
  ### General
data/Gemfile CHANGED
@@ -3,6 +3,8 @@ source 'https://rubygems.org'
3
3
  group :development do
4
4
  gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git", :tag => 'v2.1.2'
5
5
  gem "test-unit", "~> 3.2.3"
6
+ # gem "test-unit-rr", "~> 1.0.5"
7
+ gem "rake", "~> 12.0.0"
6
8
  end
7
9
 
8
10
  group :plugins do
data/README.md CHANGED
@@ -1,7 +1,8 @@
1
1
  # Vagrant Sakura Provider
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/vagrant-sakura.png)](http://badge.fury.io/rb/vagrant-sakura)
4
-
4
+ [![Build Status](https://travis-ci.org/sacloud/vagrant-sakura.svg?branch=master)](https://travis-ci.org/sacloud/vagrant-sakura)
5
+ [![Slack](https://slack.usacloud.jp/badge.svg)](https://slack.usacloud.jp/)
5
6
 
6
7
  この gem は [Vagrant](http://www.vagrantup.com) に
7
8
  [さくらのクラウド](http://cloud.sakura.ad.jp)上のサーバを操作する
@@ -57,8 +58,8 @@ Vagrant.configure("2") do |config|
57
58
  config.ssh.username = "ubuntu"
58
59
 
59
60
  config.vm.provider :sakura do |sakura|
60
- sakura.access_token = 'YOUR ACCESS TOKEN'
61
- sakura.access_token_secret = 'YOUR ACCESS TOKEN SECRET'
61
+ sakura.access_token = '<YOUR ACCESS TOKEN>'
62
+ sakura.access_token_secret = '<YOUR ACCESS TOKEN SECRET>'
62
63
  sakura.use_insecure_key = true
63
64
  end
64
65
  end
@@ -66,24 +67,64 @@ end
66
67
 
67
68
  そして ``vagrant up --provider=sakura`` を実行してください。
68
69
 
69
- サーバのディスクソースを ``sakura.disk_source_archive`` で指定しなかった
70
- 場合のデフォルトは ``113000423772`` で
71
- Ubuntu Server 16.04.4 LTS 64bit(石狩第2ゾーン)
72
- です。
70
+ サーバのディスクソース(OS)は ``sakura.disk_source_archive`` または``sakura.os_type``で指定します。
71
+ デフォルトでは``sakura.os_type="ubuntu"``となっています。
72
+
73
+ > 注: ディスクソースに指定するOSに応じて`config.ssh.username`を適切に指定する必要があります。
74
+ 詳細は`os_type`の説明を参照してください。
75
+
76
+ ## APIキーの指定
77
+
78
+ さくらのクラウド API を利用するための APIキー(トークン/シークレット/ゾーン)は 以下の3通りの方法で指定できます。
73
79
 
74
- > ※注: アーカイブのIDはゾーンごとに異なります
80
+ 1. Vagrantfileに直接記載
81
+ 2. さくらのクラウド CLI [Usacloud](https://github.com/sacloud/usacloud)の設定ファイル
82
+ 3. 環境変数
75
83
 
76
- このディスクソースのログインアカウントは ``root`` ではないため、
77
- ``config.ssh.username`` で指定してやる必要があります。
84
+ > 複数指定されている場合はより上に記載されているものが優先されます。
78
85
 
79
- なお、さくらのクラウド API を利用するための API キー(ACCESS TOKEN)と
80
- シークレットトークン(ACCESS TOKEN SECRET)は環境変数
81
- ``SAKURA_ACCESS_TOKEN`` と ``SAKURA_ACCESS_TOKEN_SECRET``で指定することも
82
- できます。
86
+ ### 1. Vagrantfileに直接記載
87
+
88
+ 以下のようにVagrantfileに直接記載する方法です。
89
+
90
+ ```Ruby
91
+ config.vm.provider :sakura do |sakura|
92
+ sakura.access_token = '<YOUR ACCESS TOKEN>'
93
+ sakura.access_token_secret = '<YOUR ACCESS TOKEN SECRET>'
94
+ sakura.zone_id = '< is1a / is1b / tk1a >'
95
+
96
+ # ...
97
+ end
98
+ ```
99
+
100
+ ### 2. さくらのクラウド CLI Usacloudの設定ファイル
101
+
102
+ [Usacloud](https://github.com/sacloud/usacloud)の設定ファイルを利用する方法です。
103
+ UsacloudにてAPIキーの設定(`usacloud config`コマンドの実行など)を行なっておけばvagrant-sakura が自動的にUsacloudの設定ファイルを読み込みます。
104
+ この機能を利用すればVagrantfileにAPIキー関連の設定を記載する必要はありません。
105
+
106
+ デフォルトでは`~/.usacloud/<current_profile>/config.json`ファイルが利用されます。
107
+ 任意のUsacloud設定ファイルを利用したい場合、Vagrantfileに`config_path`を指定することで利用する設定ファイルを指定できます。
108
+
109
+ ```Ruby
110
+ config.vm.provider :sakura do |sakura|
111
+ sakura.config_path = 'your/config/file.json'
112
+ # ...
113
+ end
114
+ ```
115
+
116
+ ### 3. 環境変数
117
+
118
+ 環境変数でAPIキーを指定可能です。
119
+ Usacloudや[Packer for さくらのクラウド](https://github.com/sacloud/packer-builder-sakuracloud)、[Terraform for さくらのクラウド](https://github.com/sacloud/terraform-provider-sakuracloud)と共通の環境変数を利用できます。
120
+
121
+ - API アクセストークン: `SAKURACLOUD_ACCESS_TOKEN` または `SAKURA_ACCESS_TOKEN`
122
+ - API シークレット: `SAKURACLOUD_ACCESS_TOKEN_SECRET` または `SAKURA_ACCESS_TOKEN_SECRET`
123
+ - ゾーン: `SAKURACLOUD_ZONE`
83
124
 
84
125
  ## SSH 鍵の指定方法
85
126
 
86
- vagrant-sakura では、サーバにログインするための SSH 公開鍵を 3通りの方法で
127
+ vagrant-sakura では、サーバにログインするための SSH 公開鍵を 以下の3通りの方法で
87
128
  設定できます。
88
129
 
89
130
  1. コントロールパネルで設定済みの SSH 公開鍵をリソース ID で指定する。
@@ -111,6 +152,18 @@ vagrant-sakura では、サーバにログインするための SSH 公開鍵を
111
152
 
112
153
 
113
154
  ## コマンド
155
+
156
+ #### OSの再インストール
157
+
158
+ `sakura-reinstall` コマンドを使って、ディスクに対しOSの再インストールを行うことができます。
159
+
160
+ ```
161
+ $ vagrant sakura-reinstall
162
+ ...
163
+ ```
164
+
165
+ #### 各種IDの一覧表示
166
+
114
167
  `sakura-list-id` コマンドを使って、`Vagrantfile` で指定するリソース ID
115
168
  を調べることができます。
116
169
  ```
@@ -125,13 +178,30 @@ $ vagrant sakura-list-id
125
178
  - ``access_token`` - さくらのクラウド API にアクセスするための API キー
126
179
  - ``access_token_secret`` - API キーのシークレットトークン
127
180
  - ``disk_plan`` - サーバで利用するディスクのプラン ID
128
- - ``disk_source_archive`` - サーバで利用するディスクのベースとするアーカイブ
181
+ - ``os_type`` - サーバで利用するディスクのベースとするアーカイブの種別 (※ `disk_source_archive`とは同時に指定できません)
182
+ 指定可能な値は以下の通りです。
183
+
184
+ |指定可能な値|SSHユーザー名|Vagrantfileの例|備考|
185
+ |---|---|:---:|---|
186
+ |`ubuntu`(デフォルト)|`ubuntu`| [example](examples/ubuntu.md) | - |
187
+ |`centos`|`root`| [example](examples/centos.md) | - |
188
+ |`centos6`|`root`| [example](examples/centos6.md) | - |
189
+ |`debian`|`root`| [example](examples/debian.md) | - |
190
+ |`coreos`|`core`| [example](examples/coreos.md) | - |
191
+ |`freebsd`|`root`| [example](examples/freebsd.md) | - |
192
+ |`rancheros`|`rancher`| [example](examples/rancheros.md) | メモリ2GB以上のプランが必要 |
193
+
194
+ - ``disk_source_archive`` - サーバで利用するディスクのベースとするアーカイブのID (※`os_type`とは同時に指定できません)
129
195
  - ``server_name`` - サーバ名
130
196
  - ``server_plan`` - 作成するサーバのプラン ID
197
+ - ``packet_filter`` - 作成するサーバに適用するパケットフィルタ ID
198
+ - ``startup_scripts`` - 作成するサーバに適用するスタートアップスクリプト ID(リスト)
199
+ - ``enable_pw_auth`` - パスワード認証の有効化(デフォルト: `false`)
131
200
  - ``tags`` - 作成するサーバ/ディスクのタグ(リスト)
132
201
  - ``description`` - 作成するサーバ/ディスクの説明
133
202
  - ``sshkey_id`` - サーバへのログインに利用する SSH 公開鍵のリソース ID
134
203
  - ``zone_id`` - ゾーン ID (石狩第1=`is1a`, 石狩第2=`is1b`、東京第1=`tk1a`、デフォルトは`is1b`)
204
+ - ``config_path`` - APIキーが記載されたUsacloud設定ファイルのパス
135
205
 
136
206
  ## ネットワーク
137
207
  ``vagrant-sakura`` は ``config.vm.network`` を利用したネットワークの構築を
data/Rakefile CHANGED
@@ -1,3 +1,8 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  Bundler::GemHelper.install_tasks
4
+
5
+ require "rake/testtask"
6
+ Rake::TestTask.new do |test|
7
+ test.warning = false
8
+ end
@@ -0,0 +1,15 @@
1
+ # Vagrantfileの例(CentOS7を利用する場合)
2
+
3
+ ```bash
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "dummy"
6
+ config.ssh.username = "root"
7
+
8
+ config.vm.provider :sakura do |sakura, override|
9
+ sakura.os_type = "centos"
10
+
11
+ sakura.public_key_path = File.expand_path("~/.ssh/id_rsa.pub")
12
+ override.ssh.private_key_path = File.expand_path("~/.ssh/id_rsa")
13
+ end
14
+ end
15
+ ```
@@ -0,0 +1,15 @@
1
+ # Vagrantfileの例(CentOS6を利用する場合)
2
+
3
+ ```bash
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "dummy"
6
+ config.ssh.username = "root"
7
+
8
+ config.vm.provider :sakura do |sakura, override|
9
+ sakura.os_type = "centos6"
10
+
11
+ sakura.public_key_path = File.expand_path("~/.ssh/id_rsa.pub")
12
+ override.ssh.private_key_path = File.expand_path("~/.ssh/id_rsa")
13
+ end
14
+ end
15
+ ```
@@ -0,0 +1,15 @@
1
+ # Vagrantfileの例(CoreOS/ContainerLinuxを利用する場合)
2
+
3
+ ```bash
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "dummy"
6
+ config.ssh.username = "core"
7
+
8
+ config.vm.provider :sakura do |sakura, override|
9
+ sakura.os_type = "coreos"
10
+
11
+ sakura.public_key_path = File.expand_path("~/.ssh/id_rsa.pub")
12
+ override.ssh.private_key_path = File.expand_path("~/.ssh/id_rsa")
13
+ end
14
+ end
15
+ ```
@@ -0,0 +1,15 @@
1
+ # Vagrantfileの例(Debianを利用する場合)
2
+
3
+ ```bash
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "dummy"
6
+ config.ssh.username = "root"
7
+
8
+ config.vm.provider :sakura do |sakura, override|
9
+ sakura.os_type = "debian"
10
+
11
+ sakura.public_key_path = File.expand_path("~/.ssh/id_rsa.pub")
12
+ override.ssh.private_key_path = File.expand_path("~/.ssh/id_rsa")
13
+ end
14
+ end
15
+ ```
@@ -0,0 +1,17 @@
1
+ # Vagrantfileの例(FreeBSDを利用する場合)
2
+
3
+ ```bash
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "dummy"
6
+ config.ssh.username = "root"
7
+ config.ssh.shell = "sh"
8
+ config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
9
+
10
+ config.vm.provider :sakura do |sakura, override|
11
+ sakura.os_type = "freebsd"
12
+
13
+ sakura.public_key_path = File.expand_path("~/.ssh/id_rsa.pub")
14
+ override.ssh.private_key_path = File.expand_path("~/.ssh/id_rsa")
15
+ end
16
+ end
17
+ ```
@@ -0,0 +1,17 @@
1
+ # Vagrantfileの例(RancherOSを利用する場合)
2
+
3
+ ```bash
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "dummy"
6
+ config.ssh.username = "rancher"
7
+ config.vm.synced_folder ".", "/vagrant", id: "vagrant-root", disabled: true
8
+
9
+ config.vm.provider :sakura do |sakura, override|
10
+ sakura.os_type = "rancheros"
11
+ sakura.server_plan = 4002 # 2core/4GBメモリ プラン
12
+
13
+ sakura.public_key_path = File.expand_path("~/.ssh/id_rsa.pub")
14
+ override.ssh.private_key_path = File.expand_path("~/.ssh/id_rsa")
15
+ end
16
+ end
17
+ ```
@@ -0,0 +1,15 @@
1
+ # Vagrantfileの例(Ubuntuを利用する場合)
2
+
3
+ ```bash
4
+ Vagrant.configure("2") do |config|
5
+ config.vm.box = "dummy"
6
+ config.ssh.username = "ubuntu"
7
+
8
+ config.vm.provider :sakura do |sakura, override|
9
+ sakura.os_type = "ubuntu"
10
+
11
+ sakura.public_key_path = File.expand_path("~/.ssh/id_rsa.pub")
12
+ override.ssh.private_key_path = File.expand_path("~/.ssh/id_rsa")
13
+ end
14
+ end
15
+ ```
@@ -0,0 +1,38 @@
1
+ require 'log4r'
2
+ require 'vagrant-sakura/driver/api'
3
+ require "vagrant-sakura/os_type"
4
+
5
+ module VagrantPlugins
6
+ module Sakura
7
+ module Action
8
+ class CompleteArchiveId
9
+ def initialize(app, env)
10
+ @app = app
11
+ @logger = Log4r::Logger.new("vagrant_sakura::action::complete_archive_id")
12
+ end
13
+
14
+ def call(env)
15
+ config = env[:machine].provider_config
16
+ if config.disk_source_mode == :os_type
17
+ api = env[:sakura_api]
18
+
19
+ filter = VagrantPlugins::Sakura::OSType::OS_TYPE_QUERIES[config.os_type]
20
+ raise 'invalid os_type' if filter.nil?
21
+
22
+ data = {
23
+ "Filter" => filter
24
+ }
25
+ response = api.get("/archive", data)
26
+ raise "os_type `#{config.os_type}` is not found" if response.nil? || response["Archives"].nil? || response["Archives"].empty?
27
+
28
+ config.disk_source_archive = response["Archives"][0]["ID"]
29
+ else
30
+ config.os_type = ""
31
+ end
32
+ @app.call(env)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,114 @@
1
+ require 'vagrant/util/retryable'
2
+
3
+ require 'vagrant-sakura/driver/api'
4
+ #require 'vagrant-sakura/util/timer'
5
+ require 'log4r'
6
+
7
+ module VagrantPlugins
8
+ module Sakura
9
+ module Action
10
+ class Reinstall
11
+ include Vagrant::Util::Retryable
12
+
13
+ def initialize(app, env)
14
+ @app = app
15
+ @logger = Log4r::Logger.new("vagrant_sakura::action::run_instance")
16
+ end
17
+
18
+ def call(env)
19
+ disk_source_archive = env[:machine].provider_config.disk_source_archive
20
+ os_type = env[:machine].provider_config.os_type
21
+ sshkey_id = env[:machine].provider_config.sshkey_id
22
+ public_key_path = env[:machine].provider_config.public_key_path
23
+ use_insecure_key = env[:machine].provider_config.use_insecure_key
24
+ enable_pw_auth = env[:machine].provider_config.enable_pw_auth
25
+ startup_scripts = env[:machine].provider_config.startup_scripts
26
+
27
+ api = env[:sakura_api]
28
+ serverid = env[:machine].id
29
+ diskid = env[:machine].provider_config.disk_id
30
+
31
+ unless env[:machine].provider_config.disk_id
32
+ begin
33
+ response = api.get("/server/#{serverid}")
34
+ rescue Driver::NotFoundError
35
+ raise 'server not found'
36
+ end
37
+ diskid = response["Server"]["Disks"][0]["ID"]
38
+ end
39
+
40
+ env[:ui].info(I18n.t("vagrant_sakura.reinstalling_disk"))
41
+ env[:ui].info(" -- Target Disk ID: #{diskid}") if os_type
42
+ env[:ui].info(" -- Disk Source OS Type: #{os_type}") if os_type
43
+ env[:ui].info(" -- Disk Source Archive: #{disk_source_archive}")
44
+ env[:ui].info(" -- Startup Scripts: #{startup_scripts.map {|item| item["ID"]}}") unless startup_scripts.empty?
45
+
46
+ data = {
47
+ "Disk" => {
48
+ "SourceArchive" => {
49
+ "ID" => disk_source_archive
50
+ },
51
+ }
52
+ }
53
+ response = api.put("/disk/#{diskid}/install", data)
54
+
55
+ while true
56
+ response = api.get("/disk/#{diskid}")
57
+ case response["Disk"]["Availability"]
58
+ when "available"
59
+ break
60
+ when "migrating"
61
+ migrated = response["Disk"]["MigratedMB"]
62
+ size = response["Disk"]["SizeMB"]
63
+ env[:ui].info("Disk #{diskid} is migrating (#{migrated}/#{size})")
64
+ else
65
+ status = presponse["Disk"]["Availability"]
66
+ env[:ui].info("Disk #{diskid} is #{status}")
67
+ end
68
+ sleep 3
69
+ end
70
+
71
+ data = {
72
+ "UserSubnet" => {},
73
+ "Notes" => startup_scripts,
74
+ "DisablePWAuth" => !enable_pw_auth
75
+ }
76
+ if sshkey_id
77
+ data["SSHKey"] = { "ID" => sshkey_id }
78
+ elsif public_key_path
79
+ data["SSHKey"] = { "PublicKey" => File.read(public_key_path) }
80
+ elsif use_insecure_key
81
+ pubkey = Vagrant.source_root.join("keys", "vagrant.pub").read.chomp
82
+ data["SSHKey"] = { "PublicKey" => pubkey }
83
+ else
84
+ raise 'failsafe'
85
+ end
86
+
87
+ response = api.put("/disk/#{diskid}/config", data)
88
+ # Config
89
+
90
+ response = api.put("/server/#{serverid}/power")
91
+ # Power On
92
+
93
+ if !env[:interrupted]
94
+ # Wait for SSH to be ready.
95
+ env[:ui].info(I18n.t("vagrant_sakura.waiting_for_ssh"))
96
+ while true
97
+ break if env[:interrupted]
98
+ break if env[:machine].communicate.ready?
99
+ sleep 2
100
+ end
101
+
102
+ #@logger.info("Time for SSH ready: #{env[:metrics]["instance_ssh_time"]}")
103
+
104
+ # Ready and booted!
105
+ env[:ui].info(I18n.t("vagrant_sakura.ready"))
106
+ end
107
+
108
+ @app.call(env)
109
+ end
110
+
111
+ end
112
+ end
113
+ end
114
+ end