[DRE-commits] [vagrant-libvirt] 77/104: syntax cleanup
Antonio Terceiro
terceiro at moszumanska.debian.org
Sun Apr 24 13:55:48 UTC 2016
This is an automated email from the git hooks/post-receive script.
terceiro pushed a commit to annotated tag 0.0.11
in repository vagrant-libvirt.
commit 40d862459df6cd6eec8de17dcf2e43d66c9880f4
Author: dima <pronix.service at gmail.com>
Date: Tue Sep 24 20:32:03 2013 +0200
syntax cleanup
---
lib/vagrant-libvirt/action.rb | 66 +++++++++---------
.../action/create_network_interfaces.rb | 10 +--
lib/vagrant-libvirt/action/create_networks.rb | 81 +++++++++++-----------
lib/vagrant-libvirt/action/handle_box_image.rb | 27 ++++----
lib/vagrant-libvirt/errors.rb | 2 +-
lib/vagrant-libvirt/plugin.rb | 16 ++---
lib/vagrant-libvirt/util/libvirt_util.rb | 22 +++---
lib/vagrant-libvirt/version.rb | 2 +-
8 files changed, 113 insertions(+), 113 deletions(-)
diff --git a/lib/vagrant-libvirt/action.rb b/lib/vagrant-libvirt/action.rb
index 589fa53..7444296 100644
--- a/lib/vagrant-libvirt/action.rb
+++ b/lib/vagrant-libvirt/action.rb
@@ -249,40 +249,38 @@ module VagrantPlugins
end
end
-
- action_root = Pathname.new(File.expand_path("../action", __FILE__))
- autoload :ConnectLibvirt, action_root.join("connect_libvirt")
- autoload :IsCreated, action_root.join("is_created")
- autoload :IsRunning, action_root.join("is_running")
- autoload :IsSuspended, action_root.join("is_suspended")
- autoload :MessageAlreadyCreated, action_root.join("message_already_created")
- autoload :MessageNotCreated, action_root.join("message_not_created")
- autoload :MessageNotRunning, action_root.join("message_not_running")
- autoload :MessageNotSuspended, action_root.join("message_not_suspended")
- autoload :HandleStoragePool, action_root.join("handle_storage_pool")
- autoload :HandleBoxUrl, "vagrant/action/builtin/handle_box_url"
- autoload :HandleBoxImage, action_root.join("handle_box_image")
- autoload :SetNameOfDomain, action_root.join("set_name_of_domain")
- autoload :CreateDomainVolume, action_root.join("create_domain_volume")
- autoload :CreateDomain, action_root.join("create_domain")
- autoload :CreateNetworks, action_root.join("create_networks")
- autoload :CreateNetworkInterfaces, action_root.join("create_network_interfaces")
- autoload :DestroyDomain, action_root.join("destroy_domain")
- autoload :DestroyNetworks, action_root.join("destroy_networks")
- autoload :StartDomain, action_root.join("start_domain")
- autoload :HaltDomain, action_root.join("halt_domain")
- autoload :SuspendDomain, action_root.join("suspend_domain")
- autoload :ResumeDomain, action_root.join("resume_domain")
- autoload :ReadState, action_root.join("read_state")
- autoload :ReadSSHInfo, action_root.join("read_ssh_info")
- autoload :TimedProvision, action_root.join("timed_provision")
- autoload :WaitTillUp, action_root.join("wait_till_up")
- autoload :SyncFolders, action_root.join("sync_folders")
- autoload :SSHRun, "vagrant/action/builtin/ssh_run"
- autoload :PrepareNFSSettings, action_root.join("prepare_nfs_settings")
- autoload :PruneNFSExports, action_root.join("prune_nfs_exports")
- autoload :ShareFolders, action_root.join("share_folders")
+ action_root = Pathname.new(File.expand_path('../action', __FILE__))
+ autoload :ConnectLibvirt, action_root.join('connect_libvirt')
+ autoload :IsCreated, action_root.join('is_created')
+ autoload :IsRunning, action_root.join('is_running')
+ autoload :IsSuspended, action_root.join('is_suspended')
+ autoload :MessageAlreadyCreated, action_root.join('message_already_created')
+ autoload :MessageNotCreated, action_root.join('message_not_created')
+ autoload :MessageNotRunning, action_root.join('message_not_running')
+ autoload :MessageNotSuspended, action_root.join('message_not_suspended')
+ autoload :HandleStoragePool, action_root.join('handle_storage_pool')
+ autoload :HandleBoxUrl, 'vagrant/action/builtin/handle_box_url'
+ autoload :HandleBoxImage, action_root.join('handle_box_image')
+ autoload :SetNameOfDomain, action_root.join('set_name_of_domain')
+ autoload :CreateDomainVolume, action_root.join('create_domain_volume')
+ autoload :CreateDomain, action_root.join('create_domain')
+ autoload :CreateNetworks, action_root.join('create_networks')
+ autoload :CreateNetworkInterfaces, action_root.join('create_network_interfaces')
+ autoload :DestroyDomain, action_root.join('destroy_domain')
+ autoload :DestroyNetworks, action_root.join('destroy_networks')
+ autoload :StartDomain, action_root.join('start_domain')
+ autoload :HaltDomain, action_root.join('halt_domain')
+ autoload :SuspendDomain, action_root.join('suspend_domain')
+ autoload :ResumeDomain, action_root.join('resume_domain')
+ autoload :ReadState, action_root.join('read_state')
+ autoload :ReadSSHInfo, action_root.join('read_ssh_info')
+ autoload :TimedProvision, action_root.join('timed_provision')
+ autoload :WaitTillUp, action_root.join('wait_till_up')
+ autoload :SyncFolders, action_root.join('sync_folders')
+ autoload :SSHRun, 'vagrant/action/builtin/ssh_run'
+ autoload :PrepareNFSSettings, action_root.join('prepare_nfs_settings')
+ autoload :PruneNFSExports, action_root.join('prune_nfs_exports')
+ autoload :ShareFolders, action_root.join('share_folders')
end
end
end
-
diff --git a/lib/vagrant-libvirt/action/create_network_interfaces.rb b/lib/vagrant-libvirt/action/create_network_interfaces.rb
index c71540f..cae02cf 100644
--- a/lib/vagrant-libvirt/action/create_network_interfaces.rb
+++ b/lib/vagrant-libvirt/action/create_network_interfaces.rb
@@ -15,7 +15,7 @@ module VagrantPlugins
include Vagrant::Util::ScopedHashOverride
def initialize(app, env)
- @logger = Log4r::Logger.new("vagrant_libvirt::action::create_network_interfaces")
+ @logger = Log4r::Logger.new('vagrant_libvirt::action::create_network_interfaces')
@app = app
end
@@ -91,7 +91,7 @@ module VagrantPlugins
end
end
- # Continue the middleware chain.
+ # Continue the middleware chain.
@app.call(env)
# Configure interfaces that user requested. Machine should be up and
@@ -122,15 +122,15 @@ module VagrantPlugins
networks_to_configure << network
end
- env[:ui].info I18n.t("vagrant.actions.vm.network.configuring")
+ env[:ui].info I18n.t('vagrant.actions.vm.network.configuring')
env[:machine].guest.capability(
- :configure_networks, networks_to_configure)
+ :configure_networks, networks_to_configure)
end
private
def find_empty(array, start=0, stop=8)
- for i in start..stop
+ (start..stop).each do |i|
return i if !array[i]
end
return nil
diff --git a/lib/vagrant-libvirt/action/create_networks.rb b/lib/vagrant-libvirt/action/create_networks.rb
index c1d8ce5..626b25d 100644
--- a/lib/vagrant-libvirt/action/create_networks.rb
+++ b/lib/vagrant-libvirt/action/create_networks.rb
@@ -14,7 +14,8 @@ module VagrantPlugins
include VagrantPlugins::ProviderLibvirt::Util::LibvirtUtil
def initialize(app, env)
- @logger = Log4r::Logger.new("vagrant_libvirt::action::create_networks")
+ mess = 'vagrant_libvirt::action::create_networks'
+ @logger = Log4r::Logger.new(mess)
@app = app
@available_networks = []
@@ -44,22 +45,22 @@ module VagrantPlugins
# (:libvirt__network_name => ...).
@options = scoped_hash_override(options, :libvirt)
@options = {
- :netmask => '255.255.255.0',
- :dhcp_enabled => true,
- :forward_mode => 'nat',
+ netmask: '255.255.255.0',
+ dhcp_enabled: true,
+ forward_mode: 'nat',
}.merge(@options)
# Prepare a hash describing network for this specific interface.
@interface_network = {
- :name => nil,
- :ip_address => nil,
- :netmask => @options[:netmask],
- :network_address => nil,
- :bridge_name => nil,
- :created => false,
- :active => false,
- :autostart => false,
- :libvirt_network => nil,
+ name: nil,
+ ip_address: nil,
+ netmask: @options[:netmask],
+ network_address: nil,
+ bridge_name: nil,
+ created: false,
+ active: false,
+ autostart: false,
+ libvirt_network: nil,
}
if @options[:ip]
@@ -67,16 +68,16 @@ module VagrantPlugins
elsif @options[:network_name]
handle_network_name_option
else
- # TODO Should be smarter than just using fixed 'default' string.
+ # TODO: Should be smarter than just using fixed 'default' string.
@interface_network = lookup_network_by_name('default')
- if not @interface_network
+ if !@interface_network
raise Errors::NetworkNotAvailableError,
- :network_name => 'default'
- end
+ network_name: 'default'
+ end
end
- autostart_network if not @interface_network[:autostart]
- activate_network if not @interface_network[:active]
+ autostart_network if @interface_network[:autostart].nil?
+ activate_network if @interface_network[:active].nil?
end
@app.call(env)
@@ -103,7 +104,7 @@ module VagrantPlugins
# Handle only situations, when ip is specified. Variables @options and
# @available_networks should be filled before calling this function.
def handle_ip_option(env)
- return if not @options[:ip]
+ return if !@options[:ip]
net_address = network_address(@options[:ip], @options[:netmask])
@interface_network[:network_address] = net_address
@@ -129,32 +130,32 @@ module VagrantPlugins
# config match together.
if @options[:network_name] != @interface_network[:name]
raise Errors::NetworkNameAndAddressMismatch,
- :ip_address => @options[:ip],
- :network_name => @options[:network_name]
+ ip_address: @options[:ip],
+ network_name: @options[:network_name]
end
else
# Network is not created, but name is set. We need to check,
# whether network name from config doesn't already exist.
if lookup_network_by_name @options[:network_name]
raise Errors::NetworkNameAndAddressMismatch,
- :ip_address => @options[:ip],
- :network_name => @options[:network_name]
+ ip_address: @options[:ip],
+ network_name: @options[:network_name]
end
# Network with 'name' doesn't exist. Set it as name for new
# network.
@interface_network[:name] = @options[:network_name]
- end
+ end
end
# Do we need to create new network?
- if not @interface_network[:created]
+ if !@interface_network[:created]
- # TODO stop after some loops. Don't create infinite loops.
+ # TODO: stop after some loops. Don't create infinite loops.
# Is name for new network set? If not, generate a unique one.
count = 0
- while @interface_network[:name] == nil do
+ while @interface_network[:name].nil?
# Generate a network name.
network_name = env[:root_path].basename.to_s.dup
@@ -169,7 +170,7 @@ module VagrantPlugins
# Generate a unique name for network bridge.
count = 0
- while @interface_network[:bridge_name] == nil do
+ while @interface_network[:bridge_name].nil?
bridge_name = 'virbr'
bridge_name << count.to_s
count += 1
@@ -188,12 +189,12 @@ module VagrantPlugins
# @options and @available_networks should be filled before calling this
# function.
def handle_network_name_option
- return if @options[:ip] or not @options[:network_name]
+ return if @options[:ip] || !@options[:network_name]
@interface_network = lookup_network_by_name(@options[:network_name])
- if not @interface_network
+ if !@interface_network
raise Errors::NetworkNotAvailableError,
- :network_name => @options[:network_name]
+ network_name: @options[:network_name]
end
end
@@ -214,9 +215,10 @@ module VagrantPlugins
network_address << "#{@interface_network[:netmask]}"
net = IPAddr.new(network_address)
- # First is address of network, second is gateway. Start the range two
+ # First is address of network, second is gateway.
+ # Start the range two
# addresses after network address.
- # TODO Detect if this IP is not set on the interface.
+ # TODO: Detect if this IP is not set on the interface.
start_address = net.to_range.begin.succ.succ
# Stop address must not be broadcast.
@@ -233,13 +235,12 @@ module VagrantPlugins
@interface_network[:libvirt_network] = \
@libvirt_client.define_network_xml(to_xml('private_network'))
rescue => e
- raise Errors::CreateNetworkError,
- :error_message => e.message
+ raise Errors::CreateNetworkError, error_message: e.message
end
created_networks_file = env[:machine].data_dir + 'created_networks'
- message = "Saving information about created network "
+ message = 'Saving information about created network '
message << "#{@interface_network[:name]}, "
message << "UUID=#{@interface_network[:libvirt_network].uuid} "
message << "to file #{created_networks_file}."
@@ -254,8 +255,7 @@ module VagrantPlugins
begin
@interface_network[:libvirt_network].autostart = true
rescue => e
- raise Errors::AutostartNetworkError,
- :error_message => e.message
+ raise Errors::AutostartNetworkError, error_message: e.message
end
end
@@ -263,8 +263,7 @@ module VagrantPlugins
begin
@interface_network[:libvirt_network].create
rescue => e
- raise Errors::ActivateNetworkError,
- :error_message => e.message
+ raise Errors::ActivateNetworkError, error_message: e.message
end
end
diff --git a/lib/vagrant-libvirt/action/handle_box_image.rb b/lib/vagrant-libvirt/action/handle_box_image.rb
index a561bea..6f421bb 100644
--- a/lib/vagrant-libvirt/action/handle_box_image.rb
+++ b/lib/vagrant-libvirt/action/handle_box_image.rb
@@ -5,7 +5,7 @@ module VagrantPlugins
module Action
class HandleBoxImage
def initialize(app, env)
- @logger = Log4r::Logger.new("vagrant_libvirt::action::handle_box_image")
+ @logger = Log4r::Logger.new('vagrant_libvirt::action::handle_box_image')
@app = app
end
@@ -30,7 +30,7 @@ module VagrantPlugins
# Get config options
config = env[:machine].provider_config
- box_image_file = env[:machine].box.directory.join("box.img").to_s
+ box_image_file = env[:machine].box.directory.join('box.img').to_s
env[:box_volume_name] = env[:machine].box.name.to_s.dup
env[:box_volume_name] << '_vagrant_box_image.img'
@@ -40,7 +40,7 @@ module VagrantPlugins
# Box is not available as a storage pool volume. Create and upload
# it as a copy of local box image.
- env[:ui].info(I18n.t("vagrant_libvirt.uploading_volume"))
+ env[:ui].info(I18n.t('vagrant_libvirt.uploading_volume'))
# Create new volume in storage pool
box_image_size = File.size(box_image_file) # B
@@ -49,11 +49,11 @@ module VagrantPlugins
@logger.info(message)
begin
fog_volume = env[:libvirt_compute].volumes.create(
- :name => env[:box_volume_name],
- :allocation => "#{box_image_size/1024/1024}M",
- :capacity => "#{box_virtual_size}G",
- :format_type => box_format,
- :pool_name => config.storage_pool_name)
+ name: env[:box_volume_name],
+ allocation: "#{box_image_size/1024/1024}M",
+ capacity: "#{box_virtual_size}G",
+ format_type: box_format,
+ pool_name: config.storage_pool_name)
rescue Fog::Errors::Error => e
raise Errors::FogCreateVolumeError,
:error_message => e.message
@@ -72,7 +72,7 @@ module VagrantPlugins
# If upload failed or was interrupted, remove created volume from
# storage pool.
- if env[:interrupted] or !ret
+ if env[:interrupted] || !ret
begin
fog_volume.destroy
rescue
@@ -99,7 +99,7 @@ module VagrantPlugins
# Exception ProviderLibvirt::RetrieveError can be raised if buffer is
# longer than length accepted by API send function.
- #
+ #
# TODO: How to find out if buffer is too large and what is the
# length that send function will accept?
@@ -117,8 +117,11 @@ module VagrantPlugins
:error_message => e.message
end
- return true if progress == image_size
- false
+ if progress == image_size
+ return true
+ else
+ return false
+ end
end
end
diff --git a/lib/vagrant-libvirt/errors.rb b/lib/vagrant-libvirt/errors.rb
index cfe660f..0c754b5 100644
--- a/lib/vagrant-libvirt/errors.rb
+++ b/lib/vagrant-libvirt/errors.rb
@@ -4,7 +4,7 @@ module VagrantPlugins
module ProviderLibvirt
module Errors
class VagrantLibvirtError < Vagrant::Errors::VagrantError
- error_namespace("vagrant_libvirt.errors")
+ error_namespace('vagrant_libvirt.errors')
end
# Storage pools and volumes exceptions
diff --git a/lib/vagrant-libvirt/plugin.rb b/lib/vagrant-libvirt/plugin.rb
index 0457b76..fc1b2af 100644
--- a/lib/vagrant-libvirt/plugin.rb
+++ b/lib/vagrant-libvirt/plugin.rb
@@ -1,14 +1,14 @@
begin
require 'vagrant'
rescue LoadError
- raise "The Vagrant Libvirt plugin must be run within Vagrant."
+ raise 'The Vagrant Libvirt plugin must be run within Vagrant.'
end
# This is a sanity check to make sure no one is attempting to install
# this into an early Vagrant version.
if Vagrant::VERSION < '1.1.0'
- raise "The Vagrant Libvirt plugin is only compatible with Vagrant 1.1+"
+ raise 'The Vagrant Libvirt plugin is only compatible with Vagrant 1.1+'
end
module VagrantPlugins
@@ -25,30 +25,30 @@ module VagrantPlugins
Config
end
- provider "libvirt" do
+ provider 'libvirt' do
# Setup logging and i18n
setup_logging
setup_i18n
- require_relative "provider"
+ require_relative 'provider'
Provider
end
# This initializes the internationalization strings.
def self.setup_i18n
- I18n.load_path << File.expand_path("locales/en.yml", ProviderLibvirt.source_root)
+ I18n.load_path << File.expand_path('locales/en.yml', ProviderLibvirt.source_root)
I18n.reload!
end
# This sets up our log level to be whatever VAGRANT_LOG is.
def self.setup_logging
- require "log4r"
+ require 'log4r'
level = nil
begin
- level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
+ level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
rescue NameError
# This means that the logging constant wasn't found,
# which is fine. We just keep `level` as `nil`. But
@@ -64,7 +64,7 @@ module VagrantPlugins
# Set the logging level on all "vagrant" namespaced
# logs as long as we have a valid level.
if level
- logger = Log4r::Logger.new("vagrant_libvirt")
+ logger = Log4r::Logger.new('vagrant_libvirt')
logger.outputters = Log4r::Outputter.stderr
logger.level = level
logger = nil
diff --git a/lib/vagrant-libvirt/util/libvirt_util.rb b/lib/vagrant-libvirt/util/libvirt_util.rb
index 1aaa183..6f357bd 100644
--- a/lib/vagrant-libvirt/util/libvirt_util.rb
+++ b/lib/vagrant-libvirt/util/libvirt_util.rb
@@ -8,7 +8,7 @@ module VagrantPlugins
include Vagrant::Util::NetworkIP
# Return a list of all (active and inactive) libvirt networks as a list
- # of hashes with their name, network address and status (active or not).
+ # of hashes with their name, network address and status (active or not)
def libvirt_networks(libvirt_client)
libvirt_networks = []
@@ -29,22 +29,22 @@ module VagrantPlugins
# Calculate network address of network from ip address and
# netmask.
- if ip and netmask
+ if ip && netmask
network_address = network_address(ip, netmask)
else
network_address = nil
end
libvirt_networks << {
- :name => network_name,
- :ip_address => ip,
- :netmask => netmask,
- :network_address => network_address,
- :bridge_name => libvirt_network.bridge_name,
- :created => true,
- :active => libvirt_network.active?,
- :autostart => libvirt_network.autostart?,
- :libvirt_network => libvirt_network,
+ name: network_name,
+ ip_address: ip,
+ netmask: netmask,
+ network_address: network_address,
+ bridge_name: libvirt_network.bridge_name,
+ created: true,
+ active: libvirt_network.active?,
+ autostart: libvirt_network.autostart?,
+ libvirt_network: libvirt_network
}
end
diff --git a/lib/vagrant-libvirt/version.rb b/lib/vagrant-libvirt/version.rb
index 5095a89..839ce1d 100644
--- a/lib/vagrant-libvirt/version.rb
+++ b/lib/vagrant-libvirt/version.rb
@@ -1,5 +1,5 @@
module VagrantPlugins
module ProviderLibvirt
- VERSION = "0.0.7"
+ VERSION = '0.0.7'
end
end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/vagrant-libvirt.git
More information about the Pkg-ruby-extras-commits
mailing list