fog-vmfusion-0.1.0/0000755000076400007640000000000012511723145013164 5ustar pravipravifog-vmfusion-0.1.0/spec/0000755000076400007640000000000012511723145014116 5ustar pravipravifog-vmfusion-0.1.0/spec/minitest_helper.rb0000644000076400007640000000150312511723145017635 0ustar pravipravirequire 'minitest/spec' require 'minitest/autorun' require 'turn' Turn.config do |c| # use one of output formats: # :outline - turn's original case/test outline mode [default] # :progress - indicates progress with progress bar # :dotted - test/unit's traditional dot-progress mode # :pretty - new pretty reporter # :marshal - dump output as YAML (normal run mode only) # :cue - interactive testing # c.format = :outline # turn on invoke/execute tracing, enable full backtrace c.trace = 20 # use humanized test names (works only with :outline format) c.natural = true end if ENV['COVERAGE'] require 'coveralls' require 'simplecov' SimpleCov.start do add_filter '/spec/' end end require File.join(File.dirname(__FILE__), '../lib/fog/vmfusion.rb') Coveralls.wear! if ENV['COVERAGE'] fog-vmfusion-0.1.0/fog-vmfusion.gemspec0000644000076400007640000000245512511723145017156 0ustar pravipravi# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'fog/vmfusion/version' Gem::Specification.new do |spec| spec.name = "fog-vmfusion" spec.version = Fog::Vmfusion::VERSION spec.authors = %q(Paulo Henrique Lopes Ribeiro) spec.email = %q(plribeiro3000@gmail.com) spec.summary = %q{Module for the 'fog' gem to support VMWARE FUSION.} spec.description = %q{This library can be used as a module for `fog` or as standalone provider to use the VMWARE FUSION in applications.} spec.homepage = "" spec.license = "MIT" files = `git ls-files -z`.split("\x0") files.delete(".hound.yml") spec.files = files spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.add_dependency "fog-core" spec.add_dependency "fission" spec.add_development_dependency "rake" spec.add_development_dependency "minitest" spec.add_development_dependency "turn" spec.add_development_dependency "pry" if RUBY_VERSION.to_f > 1.9 spec.add_development_dependency "coveralls" spec.add_development_dependency "rubocop" end end fog-vmfusion-0.1.0/LICENSE.md0000644000076400007640000000220112511723145014563 0ustar pravipraviThe MIT License (MIT) Copyright (c) 2014-2014 [CONTRIBUTORS.md](https://github.com/fog/fog-vmfusion/blob/master/CONTRIBUTORS.md) 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.fog-vmfusion-0.1.0/CONTRIBUTING.md0000644000076400007640000000155512511723145015423 0ustar pravipravi## Getting Involved New contributors are always welcome, when it doubt please ask questions. We strive to be an open and welcoming community. Please be nice to one another. ### Coding * Pick a task: * Offer feedback on open [pull requests](https://github.com/fog/fog-vmfusion/pulls). * Review open [issues](https://github.com/fog/fog-vmfusion/issues) for things to help on. * [Create an issue](https://github.com/fog/fog-vmfusion/issues/new) to start a discussion on additions or features. * Fork the project, add your changes and tests to cover them in a topic branch. * Commit your changes and rebase against `fog/fog-vmfusion` to ensure everything is up to date. * [Submit a pull request](https://github.com/fog/fog-vmfusion/compare/) ### Non-Coding * Offer feedback on open [issues](https://github.com/fog/fog-vmfusion/issues). * Organize or volunteer at events.fog-vmfusion-0.1.0/.rubocop.yml0000644000076400007640000000047412511723145015443 0ustar pravipraviMetrics/LineLength: Enabled: false Style/EachWithObject: Enabled: false Style/Encoding: EnforcedStyle: when_needed Style/FormatString: Enabled: false Style/HashSyntax: EnforcedStyle: hash_rockets Style/SignalException: EnforcedStyle: only_raise Style/StringLiterals: EnforcedStyle: double_quotes fog-vmfusion-0.1.0/.travis.yml0000644000076400007640000000066212511723145015301 0ustar pravipravimatrix: include: - rvm: 1.8.7 gemfile: gemfiles/Gemfile.1.9.2- - rvm: 1.9.2 gemfile: gemfiles/Gemfile.1.9.2- - rvm: 1.9.3 gemfile: gemfiles/Gemfile.1.9.3+ - rvm: 2.0.0 gemfile: gemfiles/Gemfile.1.9.3+ - rvm: 2.1.4 gemfile: gemfiles/Gemfile.1.9.3+ env: COVERAGE=true - rvm: ree gemfile: gemfiles/Gemfile.1.9.2- - rvm: jruby gemfile: gemfiles/Gemfile.1.9.3+ fog-vmfusion-0.1.0/CONTRIBUTORS.md0000644000076400007640000000056412511723145015450 0ustar pravipravi* Carlos Sanchez * Cody Herriges * James Herdman * Lance Ivy * Kyle Rames * Patrick Debois * Paul Thornthwaite * Paulo Henrique Lopes Ribeiro * Wesley Beary fog-vmfusion-0.1.0/README.md0000644000076400007640000000247012511723145014446 0ustar pravipravi# Fog::Vmfusion [![Gem Version](https://badge.fury.io/rb/fog-vmfusion.svg)](http://badge.fury.io/rb/fog-vmfusion) [![Build Status](https://travis-ci.org/fog/fog-vmfusion.svg?branch=master)](https://travis-ci.org/fog/fog-vmfusion) [![Dependency Status](https://gemnasium.com/fog/fog-vmfusion.svg)](https://gemnasium.com/fog/fog-vmfusion) [![Coverage Status](https://img.shields.io/coveralls/fog/fog-vmfusion.svg)](https://coveralls.io/r/fog/fog-vmfusion?branch=master) [![Code Climate](https://codeclimate.com/github/fog/fog-vmfusion.png)](https://codeclimate.com/github/fog/fog-vmfusion) Module for the 'fog' gem to support VMWARE Fusion ## Help Needed This gem needs a maintainer. If you want to work on it, please contact [@geemus](mailto:geemus@gmail.com) or [@plribeiro3000](mailto:plribeiro3000@gmail.com) ## Installation Add this line to your application's Gemfile: ```ruby gem 'fog-vmfusion' ``` And then execute: $ bundle Or install it yourself as: $ gem install fog-vmfusion ## Usage TODO: Write usage instructions here ## Contributing 1. Fork it ( https://github.com/fog/fog-vmfusion/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request fog-vmfusion-0.1.0/Gemfile0000644000076400007640000000014112511723145014453 0ustar pravipravisource 'https://rubygems.org' # Specify your gem's dependencies in fog-vmfusion.gemspec gemspec fog-vmfusion-0.1.0/.ruby-version0000644000076400007640000000000512511723145015624 0ustar pravipravi2.1.4fog-vmfusion-0.1.0/.ruby-gemset0000644000076400007640000000001412511723145015423 0ustar pravipravifog-vmfusionfog-vmfusion-0.1.0/metadata.yml0000644000076400007640000001043212511723145015467 0ustar pravipravi--- !ruby/object:Gem::Specification name: fog-vmfusion version: !ruby/object:Gem::Version version: 0.1.0 platform: ruby authors: - Paulo Henrique Lopes Ribeiro autorequire: bindir: bin cert_chain: [] date: 2015-04-04 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: fog-core requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: fission requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: minitest requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: turn requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: pry requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: coveralls requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rubocop requirement: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' description: |- This library can be used as a module for `fog` or as standalone provider to use the VMWARE FUSION in applications. email: plribeiro3000@gmail.com executables: [] extensions: [] extra_rdoc_files: [] files: - ".gitignore" - ".rubocop.yml" - ".ruby-gemset" - ".ruby-version" - ".travis.yml" - CONTRIBUTING.md - CONTRIBUTORS.md - Gemfile - LICENSE.md - README.md - Rakefile - fog-vmfusion.gemspec - gemfiles/Gemfile.1.9.2- - gemfiles/Gemfile.1.9.3+ - lib/fog/bin/vmfusion.rb - lib/fog/compute/vmfusion.rb - lib/fog/compute/vmfusion/server.rb - lib/fog/compute/vmfusion/servers.rb - lib/fog/vmfusion.rb - lib/fog/vmfusion/version.rb - spec/minitest_helper.rb homepage: '' licenses: - MIT metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.4.2 signing_key: specification_version: 4 summary: Module for the 'fog' gem to support VMWARE FUSION. test_files: - spec/minitest_helper.rb fog-vmfusion-0.1.0/lib/0000755000076400007640000000000012511723145013732 5ustar pravipravifog-vmfusion-0.1.0/lib/fog/0000755000076400007640000000000012511723145014505 5ustar pravipravifog-vmfusion-0.1.0/lib/fog/vmfusion.rb0000644000076400007640000000042212511723145016676 0ustar pravipravirequire "fog/core" require File.expand_path("../vmfusion/version", __FILE__) module Fog module Vmfusion extend Fog::Provider service(:compute, "Compute") end module Compute autoload :Vmfusion, File.expand_path("../compute/vmfusion", __FILE__) end end fog-vmfusion-0.1.0/lib/fog/compute/0000755000076400007640000000000012511723145016161 5ustar pravipravifog-vmfusion-0.1.0/lib/fog/compute/vmfusion.rb0000644000076400007640000000117612511723145020361 0ustar pravipravimodule Fog module Compute class Vmfusion < Fog::Service autoload :Server, File.expand_path("../vmfusion/server", __FILE__) autoload :Servers, File.expand_path("../vmfusion/servers", __FILE__) model_path "fog/compute/vmfusion" model :server collection :servers class Mock def initialize(_options = {}) Fog::Mock.not_implemented end end class Real def initialize(_options = {}) require "fission" rescue LoadError => e retry if require("rubygems") raise e.message end end end end end fog-vmfusion-0.1.0/lib/fog/compute/vmfusion/0000755000076400007640000000000012511723145020027 5ustar pravipravifog-vmfusion-0.1.0/lib/fog/compute/vmfusion/servers.rb0000644000076400007640000000147212511723145022051 0ustar pravipravimodule Fog module Compute class Vmfusion class Servers < Fog::Collection model Fog::Compute::Vmfusion::Server def all(filter = nil) data = [] states = ::Fission::VM.all_with_status.data filter = {} if filter.nil? unless filter.key?(:name) vms=::Fission::VM.all.data vms.each do |vm| data << { :raw => { :fission => vm, :state => states[vm.name] } } end else data << { :raw => { :fission => ::Fission::VM.new(filter[:name]), :state => states[filter[:name]] } } end load(data) end def get(name) self.all(:name => name).first end end end end end fog-vmfusion-0.1.0/lib/fog/compute/vmfusion/server.rb0000644000076400007640000001601012511723145021660 0ustar pravipravirequire "fog/compute/models/server" module Fog module Compute class Vmfusion class Server < Fog::Compute::Server identity :name attribute :ipaddress attribute :power_state attribute :mac_addresses attribute :path attr_accessor :password # There is currently no documented model of creating VMs from scratch # sans Fusion's wizard. def save raise Fog::Errors::Error.new("Creating a new vm is not yet supported") end # Fussion doesn't have the concept of templates so one just clones # regular VMs. def clone(name) requires :raw ::Fission::VM.clone(@raw[:fission].name,name) return service.servers.get(name) end # Destroy, deletes the VM from the local disk but only hard stops the VM # before doing so if you set :force to true. def destroy(options = { :force => false }) requires :raw if ready? if options[:force] stop end end @raw[:fission].delete end # Start is pretty self explanatory...if you pass :headless as true you # won't get a console on launch. def start(options = { :headless => false }) requires :raw unless ready? @raw[:fission].start(:headless => options[:headless]) return true else return false end end # We're covering a lot of bases here with the different ways one can # stop a VM from running. # Stop is a hard stop, like pulling out the power cord. def stop requires :raw if ready? @raw[:fission].stop(:hard => true) return true else return false end end # Halt and poweroff are just synonyms for stop. def halt stop end def poweroff stop end # This is a graceful shutdown but Fusion is only capable of a graceful # shutdown if tools are installed. Fusion does the right thing though # and if graceful can't be initiated it just does a hard stop. def shutdown requires :raw if ready? @raw[:fission].stop return true else return false end end # Attempt a graceful shutdown, wait for the VM to completely shutdown # and then start it again. def reboot if ready? shutdown wait_for { ! ready? } start return true else return false end end # Resuming from suspend is the same thing as start to Fusion. def resume start end def suspend requires :raw if ready? @raw[:fission].suspend return true else return false end end # Fusion VM Metadata. # The power state of the VM is commonly going to be three values; # running, not running, or suspended. def power_state requires :raw @raw[:fission].state.data end def ready? requires :raw @raw[:fission].running?.data end # Path to the VM's vmx file on the local disk. def path requires :raw @raw[:fission].path end # We obtain the first ipaddress. This should generally be a safe # assumption for Fusion. Even if an address is provided via NAT, # bridge, or host only it will by accessible from the host machine the # VM resides on. def ipaddress requires :raw ip(@raw[:fission]) end # Keeping these three methods around for API compatibility reasons. # Makes the vmfusion provider function similar to cloud providers and # the vsphere provider. Future goal is to add an actual private and # public concept. Needs changes to fission and a determination what is # a public or private address here; bridge, nat, host-only. def public_ip_address ipaddress end def private_ip_address ipaddress end def state power_state end # Collecting all mac_addresses the VM has...mostly just because we are # doing the same thing for the vSphere provider. def mac_addresses requires :raw macs(@raw[:fission]) end # Sets up a convenient way to SSH into a Fusion VM using credentials # stored in your .fog file. # Simply spawn an SSH session. def ssh(commands) super(commands, password ? {:password => password} : {}) end # SCP something to our VM. def scp(local_path, remote_path, upload_options = {}) requires :ssh_ip_address, :username scp_options = {} scp_options[:password] = password unless self.password.nil? scp_options[:key_data] = [private_key] if self.private_key Fog::SCP.new(ssh_ip_address, username, scp_options).upload(local_path, remote_path, upload_options) end # Sets up a new SSH key on the VM so one doesn't need to use a password # ever again. def setup(credentials = {}) requires :public_key, :ssh_ip_address, :username credentials[:password] = password unless self.password.nil? credentails[:key_data] = [private_key] if self.private_key commands = [ %{mkdir .ssh}, ] if public_key commands << %{echo "#{public_key}" >> ~/.ssh/authorized_keys} end # wait for domain to be ready Timeout::timeout(360) do begin Timeout::timeout(8) do Fog::SSH.new(ssh_ip_address, username, credentials.merge(:timeout => 4)).run("pwd") end rescue Errno::ECONNREFUSED sleep(2) retry rescue Net::SSH::AuthenticationFailed, Timeout::Error retry end end Fog::SSH.new(ssh_ip_address, username, credentials).run(commands) end private def ip(fission) first_int = fission.network_info.data.keys.first fission.network_info.data[first_int]["ip_address"] end def macs(fission) fission.mac_addresses.data end def raw @raw end def raw=(new_raw) @raw = new_raw raw_attributes = { :name => new_raw[:fission].name, :power_state => new_raw[:state], :ipaddress => ip(new_raw[:fission]), :mac_addresses => macs(new_raw[:fission]), :path => new_raw[:fission].path } merge_attributes(raw_attributes) end end end end end fog-vmfusion-0.1.0/lib/fog/bin/0000755000076400007640000000000012511723145015255 5ustar pravipravifog-vmfusion-0.1.0/lib/fog/bin/vmfusion.rb0000644000076400007640000000301612511723145017450 0ustar pravipravimodule Vmfusion # deviates from other bin stuff to accomodate gem class << self def class_for(key) case key when :compute Fog::Compute::Vmfusion else raise ArgumentError, "Unrecognized service: #{key}" end end def [](service) @@connections ||= Hash.new do |hash, key| hash[key] = case key when :compute Fog::Logger.warning("Vmfusion[:compute] is not recommended, use Compute[:vmfusion] for portability") Fog::Compute.new(:provider => "Vmfusion") else raise ArgumentError, "Unrecognized service: #{key.inspect}" end end @@connections[service] end def available? begin availability=true unless Gem::Specification::find_by_name("fission").nil? rescue Gem::LoadError availability=false rescue availability_gem=Gem.available?("fission") end if availability for service in services for collection in self.class_for(service).collections unless self.respond_to?(collection) self.class_eval <<-EOS, __FILE__, __LINE__ def self.#{collection} self[:#{service}].#{collection} end EOS end end end end availability end def collections services.map {|service| self[service].collections}.flatten.sort_by {|service| service.to_s} end def services Fog::Vmfusion.services end end end fog-vmfusion-0.1.0/lib/fog/vmfusion/0000755000076400007640000000000012511723145016353 5ustar pravipravifog-vmfusion-0.1.0/lib/fog/vmfusion/version.rb0000644000076400007640000000007512511723145020367 0ustar pravipravimodule Fog module Vmfusion VERSION = "0.1.0" end end fog-vmfusion-0.1.0/gemfiles/0000755000076400007640000000000012511723145014757 5ustar pravipravifog-vmfusion-0.1.0/gemfiles/Gemfile.1.9.2-0000644000076400007640000000021012511723145016766 0ustar pravipravisource :rubygems gem 'mime-types', '< 2.0' gem 'nokogiri', '< 1.6' gem 'rest-client', '~> 1.6.8' gem 'fog-core' gemspec :path => '../'fog-vmfusion-0.1.0/gemfiles/Gemfile.1.9.3+0000644000076400007640000000016712511723145017000 0ustar pravipravisource :rubygems gem 'activesupport', '>= 3.0', '< 4' gem 'mime-types', '< 2.0' gem 'fog-core' gemspec :path => '../'fog-vmfusion-0.1.0/Rakefile0000644000076400007640000000033012511723145014625 0ustar pravipravirequire 'bundler/gem_tasks' require 'rake/testtask' Rake::TestTask.new do |t| t.libs.push %w(spec) t.test_files = FileList['spec/**/*_spec.rb'] t.verbose = true end desc 'Default Task' task :default => :test fog-vmfusion-0.1.0/.gitignore0000644000076400007640000000031012511723145015146 0ustar pravipravi*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp *.bundle *.so *.o *.a mkmf.log gemfiles/*.lock