Skip to content

Commit

Permalink
on the way to arm support
Browse files Browse the repository at this point in the history
  • Loading branch information
devigned committed Mar 27, 2016
1 parent 1c0916c commit 8d7dd2f
Show file tree
Hide file tree
Showing 44 changed files with 878 additions and 991 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ modules/
*.pem
.ruby-version
*.ps1
.env
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
11 changes: 5 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#--------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the Apache License, Version 2.0.
# See License.txt in the project root for license information.
#--------------------------------------------------------------------------
# encoding: utf-8
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License in the project root for license information.

source 'https://rubygems.org'

Expand All @@ -12,7 +10,8 @@ group :development do
# We depend on Vagrant for development, but we don't add it as a
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git', tag: 'v1.7.3'
gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git', tag: 'v1.7.4'
gem 'dotenv'
end

group :plugins do
Expand Down
25 changes: 21 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
The MIT License (MIT)

Copyright (c) 2015 Microsoft

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 3 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#--------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the Apache License, Version 2.0.
# See License.txt in the project root for license information.
#--------------------------------------------------------------------------
# encoding: utf-8
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License in the project root for license information.

require 'rubygems'
require 'bundler/setup'
Expand Down
13 changes: 4 additions & 9 deletions lib/vagrant-azure.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
#--------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the Apache License, Version 2.0.
# See License.txt in the project root for license information.
#--------------------------------------------------------------------------
# encoding: utf-8
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License in the project root for license information.
require 'pathname'
require 'vagrant-azure/plugin'

module VagrantPlugins
module WinAzure
module Azure
lib_path = Pathname.new(File.expand_path('../vagrant-azure', __FILE__))
autoload :Action, lib_path.join('action')
autoload :Errors, lib_path.join('errors')
autoload :Driver, lib_path.join('driver')

CLOUD_SERVICE_SEMAPHORE = Mutex.new

# This returns the path to the source of this plugin.
#
Expand Down
173 changes: 49 additions & 124 deletions lib/vagrant-azure/action.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#--------------------------------------------------------------------------
# Copyright (c) Microsoft Open Technologies, Inc.
# All Rights Reserved. Licensed under the Apache License, Version 2.0.
# See License.txt in the project root for license information.
#--------------------------------------------------------------------------
# encoding: utf-8
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License in the project root for license information.
require 'pathname'

require 'vagrant/action/builder'
require 'vagrant/action/builtin/wait_for_communicator'

module VagrantPlugins
module WinAzure
module Azure
module Action
# Include the built-in modules so we can use them as top-level things.
include Vagrant::Action::Builtin
Expand All @@ -18,9 +16,9 @@ module Action
def self.action_halt
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsState, :NotCreated do |env, b2|
if env[:result]
b2.use Message, I18n.t('vagrant_azure.not_created')
b.use Call, IsCreated do |env, b2|
unless env[:result]
b2.use MessageNotCreated
next
end

Expand All @@ -36,22 +34,17 @@ def self.action_destroy
b.use Call, DestroyConfirm do |env, b2|
if env[:result]
b2.use ConfigValidate
b2.use Call, IsState, :NotCreated do |env2, b3|
if env2[:result]
b3.use Message, I18n.t('vagrant_azure.not_created')
b2.use Call, IsCreated do |env2, b3|
unless env2[:result]
b3.use MessageNotCreated
next
end
b3.use ConnectAzure
b3.use TerminateInstance
b3.use ProvisionerCleanup if defined?(ProvisionerCleanup)
end

b2.use ConnectAzure
b2.use TerminateInstance
b2.use ProvisionerCleanup if defined?(ProvisionerCleanup)
else
env[:machine].id =~ /@/
b2.use Message, I18n.t(
'vagrant_azure.will_not_destroy',
:name => $`
)
b2.use MessageWillNotDestroy
end
end
end
Expand All @@ -60,18 +53,14 @@ def self.action_destroy
# This action is called when `vagrant provision` is called.
def self.action_provision
Vagrant::Action::Builder.new.tap do |b|
b.use ConnectAzure
b.use ConfigValidate
b.use OSType
b.use ReadWinrmInfo
b.use Call, IsState, :NotCreated do |env, b2|
if env[:result]
b2.use Message, I18n.t('vagrant_azure.not_created')
b.use Call, IsCreated do |env, b2|
unless env[:result]
b2.use MessageNotCreated
next
end

b2.use Provision
b2.use SyncFolders
end
end
end
Expand All @@ -82,27 +71,13 @@ def self.action_read_ssh_info
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use ConnectAzure
b.use ReadSSHInfo, 22
end
end

def self.action_read_rdp_info
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use ConnectAzure
b.use ReadSSHInfo, 3389
end
end

def self.action_read_winrm_info
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use ConnectAzure
b.use OSType
b.use ReadWinrmInfo
b.use ReadSSHInfo
end
end

# This action is called to read the state of the machine. The
# resulting state is expected to be put into the `:machine_state_id`
# key.
def self.action_read_state
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
Expand All @@ -111,14 +86,13 @@ def self.action_read_state
end
end

# This action is called to SSH into the machine
# This action is called to SSH into the machine.
def self.action_ssh
Vagrant::Action::Builder.new.tap do |b|
b.use ConnectAzure
b.use ConfigValidate
b.use Call, IsState, :NotCreated do |env, b2|
if env[:result]
b2.use Message, I18n.t('vagrant_azure.not_created')
b.use Call, IsCreated do |env, b2|
unless env[:result]
b2.use MessageNotCreated
next
end

Expand All @@ -127,49 +101,12 @@ def self.action_ssh
end
end

def self.action_powershell_run
Vagrant::Action::Builder.new.tap do |b|
b.use action_read_winrm_info
b.use Call, IsState, :NotCreated do |env, b2|
if env[:result]
b2.use Message, I18n.t('vagrant_azure.not_created')
next
end

b2.use PowerShellRun
end
end
end

def self.action_rdp
Vagrant::Action::Builder.new.tap do |b|
b.use ConnectAzure
b.use ConfigValidate
b.use Call, IsState, :NotCreated do |env1, b1|
if env1[:result]
b1.use Message, I18n.t('vagrant_azure.not_created')
next
end

b1.use Call, IsState, :ReadyRole do |env2, b2|
if !env2[:result]
b2.use Message, I18n.t('vagrant_azure.rdp_not_ready')
next
end

b2.use Rdp
end
end
end
end

def self.action_ssh_run
Vagrant::Action::Builder.new.tap do |b|
b.use ConnectAzure
b.use ConfigValidate
b.use Call, IsState, :NotCreated do |env, b2|
if env[:result]
b2.use Message, I18n.t('vagrant_azure.not_created')
b.use Call, IsCreated do |env, b2|
unless env[:result]
b2.use MessageNotCreated
next
end

Expand All @@ -180,42 +117,31 @@ def self.action_ssh_run

def self.action_prepare_boot
Vagrant::Action::Builder.new.tap do |b|
b.use Call, WaitForState, :ReadyRole do |env, b1|
if env[:result]
env[:machine].id =~ /@/
b1.use Message, I18n.t(
'vagrant_azure.vm_started', :name => $`
)
b1.use action_read_winrm_info
b1.use WaitForCommunicator
b1.use action_provision
end
end
b.use Provision
b.use SyncedFolders
end
end

# This action is called to bring the box up from nothing
# This action is called to bring the box up from nothing.
def self.action_up
Vagrant::Action::Builder.new.tap do |b|
b.use HandleBox
b.use ConfigValidate
b.use BoxCheckOutdated
b.use ConnectAzure
b.use OSType
b.use Call, IsState, :NotCreated do |env1, b1|
if !env1[:result]
b1.use Call, IsState, :StoppedDeallocated do |env2, b2|
b.use Call, IsCreated do |env1, b1|
if env1[:result]
b1.use Call, IsStopped do |env2, b2|
if env2[:result]
b2.use StartInstance # start this instance again
b2.use action_prepare_boot
b2.use StartInstance # restart this instance
else
b2.use Message, I18n.t(
'vagrant_azure.already_status', :status => 'created'
)
b2.use MessageAlreadyCreated
end
end
else
b1.use RunInstance # Launch a new instance
b1.use action_prepare_boot
b1.use RunInstance # launch a new instance
end
end
end
Expand All @@ -225,20 +151,18 @@ def self.action_reload
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use ConnectAzure
b.use Call, IsState, :NotCreated do |env, b2|
if env[:result]
b2.use Message, I18n.t('vagrant_azure.not_created')
b.use Call, IsCreated do |env, b2|
unless env[:result]
b2.use MessageNotCreated
next
end

b2.use action_halt
b2.use Call, WaitForState, :StoppedDeallocated do |env2, b3|
b2.use Call, WaitForState, :stopped, 120 do |env2, b3|
if env2[:result]
env2[:machine].id =~ /@/
b3.use Message, I18n.t('vagrant_azure.vm_stopped', name: $`)
b3.use action_up
else
b3.use Message, 'Not able to stop the machine. Please retry.'
# ??? it didn't stop
end
end
end
Expand All @@ -248,18 +172,19 @@ def self.action_reload
# The autoload farm
action_root = Pathname.new(File.expand_path('../action', __FILE__))
autoload :ConnectAzure, action_root.join('connect_azure')
autoload :Rdp, action_root.join('rdp')
autoload :IsCreated, action_root.join('is_created')
autoload :IsStopped, action_root.join('is_stopped')
autoload :MessageAlreadyCreated, action_root.join('message_already_created')
autoload :MessageNotCreated, action_root.join('message_not_created')
autoload :MessageWillNotDestroy, action_root.join('message_will_not_destroy')
autoload :ReadSSHInfo, action_root.join('read_ssh_info')
autoload :ReadWinrmInfo, action_root.join('read_winrm_info')
autoload :PowerShellRun, action_root.join('powershell_run')
autoload :OSType, action_root.join('os_type')
autoload :ReadState, action_root.join('read_state')
autoload :RestartVM, action_root.join('restart_vm')
autoload :RunInstance, action_root.join('run_instance')
autoload :StartInstance, action_root.join('start_instance')
autoload :StopInstance, action_root.join('stop_instance')
autoload :SyncFolders, action_root.join('sync_folders')
autoload :TerminateInstance, action_root.join('terminate_instance')
autoload :TimedProvision, action_root.join('timed_provision')
autoload :WaitForState, action_root.join('wait_for_state')
end
end
Expand Down
Loading

0 comments on commit 8d7dd2f

Please sign in to comment.