Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9466845
Include Ruby 2.2, 2.3, and 2.4 in Travis tests
HashNotAdam Feb 23, 2017
58ac795
Remove test on Fixnum since it has been removed from Ruby 2.4
HashNotAdam Feb 23, 2017
a0a4e39
Include XMLRPC gem if running on Ruby 2.4+
HashNotAdam Feb 23, 2017
f3f7d98
Replace outdated Rubocop parameter
HashNotAdam Feb 24, 2017
38056d3
Reduce duplication when defining methods
HashNotAdam Feb 24, 2017
944ed55
Exclude spec directory in Rubocop checks
HashNotAdam Feb 24, 2017
e9f9239
:cop: Use double-quoted strings
HashNotAdam Feb 24, 2017
f5999d2
:cop: Remove useless method arguments
HashNotAdam Feb 24, 2017
d489f3d
:cop: Remove useless assignment to a local variable
HashNotAdam Feb 24, 2017
e6efad4
:cop: Ensure there is only one space between a method name and the fi…
HashNotAdam Feb 24, 2017
7f9813b
:cop: Clarify ambiguous splat operator
HashNotAdam Feb 24, 2017
9396779
:cop: Replace gsub with tr for simple string comparisons
HashNotAdam Feb 24, 2017
eca53b6
:cop: Disable test for class length on Fog::Compute::XenServer
HashNotAdam Feb 24, 2017
cf0faab
:cop: Underscore unused block argument
HashNotAdam Feb 24, 2017
25f1feb
:cop: Reduce cyclomatic complexity
HashNotAdam Feb 24, 2017
42d2574
:cop: Reduce duplication
HashNotAdam Feb 24, 2017
54a3323
Remove debug code incorrectly commited
HashNotAdam Feb 24, 2017
03d8775
Remove %i since it is not supported in Ruby < 2.0
HashNotAdam Feb 24, 2017
afdcf9d
:cop: Reduce duplication
HashNotAdam Feb 24, 2017
73c2911
Integrate get_by_reference_or_name_or_uuid into method_missing
HashNotAdam Feb 26, 2017
325e077
:cop: Use Ruby 1.9 hash syntax
HashNotAdam Feb 26, 2017
b903c05
:cop: Make Hound use the Rubocop settings
HashNotAdam Feb 26, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .hound.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .hound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ruby:
config_file: .rubocop.yml
6 changes: 4 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
AllCops:
DisabledByDefault: true
Exclude:
- 'spec/**/*'

#################### Lint ################################

Expand Down Expand Up @@ -657,7 +659,7 @@
Prefer Ruby 1.9 hash syntax { a: 1, b: 2 } over 1.8 syntax
{ :a => 1, :b => 2 }.
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-literals'
Enabled: false
Enabled: true

Style/IfUnlessModifier:
Description: >-
Expand Down Expand Up @@ -716,7 +718,7 @@
line end.
Enabled: false

Style/MethodCallParentheses:
Style/MethodCallWithoutArgsParentheses:
Description: 'Do not use parentheses for method calls with no arguments.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
Enabled: false
Expand Down
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ before_install:

matrix:
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.2+
- rvm: 2.0.0
gemfile: gemfiles/Gemfile.1.9.2+
- rvm: 2.1.4
- rvm: 2.1.10
gemfile: gemfiles/Gemfile.1.9.2+
- rvm: 2.2.6
gemfile: gemfiles/Gemfile.1.9.2+
- rvm: 2.3.3
gemfile: gemfiles/Gemfile.1.9.2+
- rvm: 2.4.0
gemfile: gemfiles/Gemfile.1.9.2+
env: COVERAGE=true
- rvm: ree
gemfile: gemfiles/Gemfile.1.9.2-
- rvm: jruby
gemfile: gemfiles/Gemfile.1.9.2+
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in fog-xenserver.gemspec
gemspec
10 changes: 5 additions & 5 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
require 'bundler/gem_tasks'
require 'rake/testtask'
require "bundler/gem_tasks"
require "rake/testtask"

Rake::TestTask.new do |t|
t.libs.push %w(spec)
t.test_files = FileList['spec/**/*_spec.rb']
t.test_files = FileList["spec/**/*_spec.rb"]
t.verbose = true
end

desc 'Default Task'
task :default => [ :test ]
desc "Default Task"
task default: [ :test ]
34 changes: 17 additions & 17 deletions fog-xenserver.gemspec
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'fog/xenserver/version'
require "fog/xenserver/version"

Gem::Specification.new do |spec|
spec.name = 'fog-xenserver'
spec.name = "fog-xenserver"
spec.version = Fog::XenServer::VERSION
spec.authors = %q(Paulo Henrique Lopes Ribeiro)
spec.email = %q(plribeiro3000@gmail.com)
spec.description = %q{Module for the 'fog' gem to support XENSERVER.}
spec.summary = %q{This library can be used as a module for `fog` or as standalone provider
to use the XENSERVER in applications.}
spec.homepage = 'https://github.com/fog/fog-xenserver'
spec.license = 'MIT'
spec.homepage = "https://github.com/fog/fog-xenserver"
spec.license = "MIT"

files = `git ls-files -z`.split("\x0")
files.delete(".hound.yml")
Expand All @@ -22,20 +22,20 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = %w(lib)

spec.add_dependency 'fog-xml'
spec.add_dependency 'fog-core'
spec.add_dependency "fog-xml"
spec.add_dependency "fog-core"
spec.add_dependency "xmlrpc" if RUBY_VERSION =~ /^2\.[^0-3].*$/

spec.add_development_dependency 'coveralls'
spec.add_development_dependency 'json' if RUBY_VERSION =~ /^1\.8.*$/
spec.add_development_dependency 'minitest'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'turn'
spec.add_development_dependency 'webmock'
spec.add_development_dependency "coveralls"
spec.add_development_dependency "minitest"
spec.add_development_dependency "rake"
spec.add_development_dependency "pry"
spec.add_development_dependency "turn"
spec.add_development_dependency "webmock"

if RUBY_VERSION =~ /^1\.(8.*|9.[0-2])$/
spec.add_development_dependency 'vcr', '< 3.0.0'
if RUBY_VERSION =~ /^1\.9\.[0-2]$/
spec.add_development_dependency "vcr", "< 3.0.0"
else
spec.add_development_dependency 'vcr'
spec.add_development_dependency "vcr"
end
end
2 changes: 1 addition & 1 deletion lib/fog/bin/xenserver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def [](service)
hash[key] = case key
when :compute
Fog::Logger.warning("XenServer[:compute] is not recommended, use Compute[:xenserver] for portability")
Fog::Compute.new(:provider => "XenServer")
Fog::Compute.new(provider: "XenServer")
else
raise ArgumentError, "Unrecognized service: #{key.inspect}"
end
Expand Down
7 changes: 4 additions & 3 deletions lib/fog/compute/xen_server.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# rubocop:disable Metrics/ClassLength
require "fog/core"

module Fog
Expand Down Expand Up @@ -150,7 +151,7 @@ class XenServer < Fog::Service
request :create_network
request :create_new_blob_network
request :set_default_locking_mode_network

# PBD
request :create_pbd
request :plug_pbd
Expand All @@ -167,7 +168,7 @@ class XenServer < Fog::Service
request :reconfigure_ipv6_pif
request :scan_pif
request :set_primary_address_type_pif

# pool
request :apply_edition_pool
request :certificate_install_pool
Expand Down Expand Up @@ -325,7 +326,7 @@ class XenServer < Fog::Service
request :start_server
request :suspend_server
request :unpause_server

# SR
request :assert_can_host_ha_statefile_sr
request :assert_supports_database_replication_sr
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/compute/xen_server/mock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ def initialize(options={})
@connection.authenticate(@username, @password)
end

def method_missing(method_name, *args)
def method_missing(*)
Fog::Mock.not_implemented
end
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/fog/compute/xen_server/models/blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class Blob < Model

identity :reference

attribute :description, :aliases => :name_description
attribute :description, aliases: :name_description
attribute :last_updated
attribute :mime_type
attribute :name, :aliases => :name_label
attribute :name, aliases: :name_label
attribute :public
attribute :size
attribute :uuid
Expand Down
24 changes: 18 additions & 6 deletions lib/fog/compute/xen_server/models/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,28 @@ module Compute
class XenServer
module Models
module ClassMethods
def provider_class(provider_class = nil)
return @provider_class if provider_class.nil?
@provider_class = provider_class.to_s
end

def collection_name(collection_name = nil)
return @collection_name if collection_name.nil?
@collection_name = collection_name
end

def define_methods(methods)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ 💙 💚 💛 💜

# would be much simpler just call __callee__ on request without reference
# instead of __method__ and set an alias for each method defined on
# methods, just creating a method for each one, so we can keep compatability
# with ruby 1.8.7 that does not have __callee__
methods.each do |method|
define_method(method) do |*args|
service.send("#{__method__}_#{provider_class.downcase}", *args)
end
end
end

def provider_class(provider_class = nil)
return @provider_class if provider_class.nil?
@provider_class = provider_class.to_s
end

def require_before_save(*args)
return @require_before_save || [] if args.empty?
@require_before_save = args
Expand All @@ -21,4 +33,4 @@ def require_before_save(*args)
end
end
end
end
end
29 changes: 14 additions & 15 deletions lib/fog/compute/xen_server/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,28 @@ def get(ref)
nil
end

def get_by_name(name)
ref = service.get_by_name(name, model.provider_class)
return nil if ref.nil?
get(ref)
rescue Fog::XenServer::NotFound, Fog::XenServer::RequestFailed
nil
def method_missing(method, *args)
case method
when :get_by_reference_or_name_or_uuid
query = args[0]
get(query) || get_by("name", query) || get_by("uuid", query)
when /^(find|get)_by_(name|uuid)$/
get_by(method, args[0])
else
super
end
end

alias_method :find_by_name, :get_by_name
private

def get_by_uuid(uuid)
ref = service.get_by_uuid(uuid, model.provider_class)
def get_by(method, value)
method = method.to_s.sub("find_by_", "get_by_")
ref = service.send(method, value, model.provider_class)
return nil if ref.nil?
get(ref)
rescue Fog::XenServer::NotFound, Fog::XenServer::RequestFailed
nil
end

alias_method :find_by_uuid, :get_by_uuid

def get_by_reference_or_name_or_uuid(query)
get(query) || get_by_name(query) || get_by_uuid(query)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/compute/xen_server/models/console.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Console < Model
attribute :protocol
attribute :uuid

has_one_identity :vm, :servers, :aliases => :VM, :as => :VM
has_one_identity :vm, :servers, aliases: :VM, as: :VM
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/compute/xen_server/models/crash_dump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class CrashDump < Model
attribute :other_config
attribute :uuid

has_one_identity :vdi, :vdis, :aliases => :VDI, :as => :VDI
has_one_identity :vm, :servers, :aliases => :VM, :as => :VM
has_one_identity :vdi, :vdis, aliases: :VDI, as: :VDI
has_one_identity :vm, :servers, aliases: :VM, as: :VM
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/compute/xen_server/models/dr_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DrTask < Model

attribute :uuid

has_many_identities :introduced_srs, :storage_repositories, :aliases => :introduced_SRs, :as => :introduced_SRs
has_many_identities :introduced_srs, :storage_repositories, aliases: :introduced_SRs, as: :introduced_SRs
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/compute/xen_server/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Event < Model

identity :reference

attribute :klass, :aliases => :class, :as => :class
attribute :klass, aliases: :class, as: :class
attribute :id
attribute :obj_uuid
attribute :operation
Expand Down
10 changes: 5 additions & 5 deletions lib/fog/compute/xen_server/models/gpu_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class GpuGroup < Model

identity :reference

attribute :description, :aliases => :name_description
attribute :gpu_types, :aliases => :GPU_types, :as => :GPU_types
attribute :name, :aliases => :name_label
attribute :description, aliases: :name_description
attribute :gpu_types, aliases: :GPU_types, as: :GPU_types
attribute :name, aliases: :name_label
attribute :other_config
attribute :uuid

has_many_identities :pgpus, :pgpus, :aliases => :PGPUs, :as => :PGPUs
has_many_identities :vgpus, :vgpus, :aliases => :VGPUs, :as => :VGPUs
has_many_identities :pgpus, :pgpus, aliases: :PGPUs, as: :PGPUs
has_many_identities :vgpus, :vgpus, aliases: :VGPUs, as: :VGPUs
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/fog/compute/xen_server/models/guest_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class GuestMetrics < Model
attribute :os_version
attribute :other
attribute :other_config
attribute :pv_drivers_up_to_date, :aliases => :PV_drivers_up_to_date, :as => :PV_drivers_up_to_date
attribute :pv_drivers_version, :aliases => :PV_drivers_version, :as => :PV_drivers_version
attribute :pv_drivers_up_to_date, aliases: :PV_drivers_up_to_date, as: :PV_drivers_up_to_date
attribute :pv_drivers_version, aliases: :PV_drivers_version, as: :PV_drivers_version
attribute :uuid
end
end
Expand Down
Loading