Skip to content

Commit

Permalink
Merge pull request #89 from Temikus/named_ip
Browse files Browse the repository at this point in the history
Introducing named IP addresses support.
  • Loading branch information
erjohnso committed Jul 13, 2015
2 parents 24d7742 + 7784570 commit c312946
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 69 deletions.
3 changes: 2 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ inherit_from: .rubocop_todo.yml

AllCops:
Exclude:
- './Vagrantfile'
- './Vagrantfile'
- './vagrant-google.gemspec'
65 changes: 16 additions & 49 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-07-13 12:21:18 +0000 using RuboCop version 0.31.0.
# on 2015-07-13 18:02:44 +0000 using RuboCop version 0.31.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -17,12 +17,12 @@ Lint/ParenthesesAsGroupedExpression:
Lint/RescueException:
Enabled: false

# Offense count: 5
# Offense count: 4
# Cop supports --auto-correct.
Lint/UnusedBlockArgument:
Enabled: false

# Offense count: 15
# Offense count: 14
# Cop supports --auto-correct.
Lint/UnusedMethodArgument:
Enabled: false
Expand All @@ -31,33 +31,33 @@ Lint/UnusedMethodArgument:
Lint/UselessAssignment:
Enabled: false

# Offense count: 13
# Offense count: 12
Metrics/AbcSize:
Max: 163
Max: 155

# Offense count: 2
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 152
Max: 156

# Offense count: 5
# Offense count: 4
Metrics/CyclomaticComplexity:
Max: 22

# Offense count: 65
# Offense count: 62
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 132

# Offense count: 16
# Offense count: 15
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 132
Max: 124

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 142
Max: 141

# Offense count: 4
Metrics/PerceivedComplexity:
Expand All @@ -73,7 +73,7 @@ Style/AccessorMethodName:
Style/AndOr:
Enabled: false

# Offense count: 17
# Offense count: 18
Style/Documentation:
Enabled: false

Expand Down Expand Up @@ -117,7 +117,7 @@ Style/FirstParameterIndentation:
Style/GuardClause:
Enabled: false

# Offense count: 37
# Offense count: 33
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
Style/HashSyntax:
Expand All @@ -128,32 +128,16 @@ Style/HashSyntax:
Style/InfiniteLoop:
Enabled: false

# Offense count: 9
# Cop supports --auto-correct.
Style/LeadingCommentSpace:
Enabled: false

# Offense count: 3
# Cop supports --auto-correct.
Style/MethodCallParentheses:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/MultilineOperationIndentation:
Enabled: false

# Offense count: 21
# Offense count: 19
# Cop supports --auto-correct.
Style/NegatedIf:
Enabled: false

# Offense count: 1
# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
Style/Next:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Style/NilComparison:
Expand All @@ -164,11 +148,6 @@ Style/NilComparison:
Style/Not:
Enabled: false

# Offense count: 1
# Cop supports --auto-correct.
Style/PerlBackrefs:
Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Expand All @@ -180,12 +159,6 @@ Style/RedundantReturn:
Style/RedundantSelf:
Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
Style/RegexpLiteral:
Enabled: false

# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Expand All @@ -198,7 +171,7 @@ Style/SignalException:
Style/SpaceAroundEqualsInParameterDefault:
EnforcedStyle: no_space

# Offense count: 2
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/SpaceBeforeBlockBraces:
Expand All @@ -209,13 +182,7 @@ Style/SpaceBeforeBlockBraces:
Style/SpaceBeforeComma:
Enabled: false

# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
Style/SpaceInsideBlockBraces:
Enabled: false

# Offense count: 378
# Offense count: 342
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/StringLiterals:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Added support for service account definitions [tcr]
* Added support for preemptible instances [jcdang]
* Implemented auto_restart and on_host_maintenance options [jcdang]
* Added support for IP address specification by name [temikus]
* Implemented vagrant halt and reload actions [temikus]
* Switched to fog-google metagem [temikus]
* Added a linter and custom acceptance tests [temikus]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ This provider exposes quite a few provider-specific configuration options:
* `tags` - An array of tags to apply to this instance.
* `zone` - The zone name where the instance will be created.
* `can_ip_forward` - Boolean whether to enable IP Forwarding.
* `external_ip` - The external IP address to use.
* `external_ip` - The external IP address to use (supports names).
* `preemptible` - Boolean whether to enable preemptibility. Default is false.
* `auto_restart` - Boolean whether to enable auto_restart. Default is true.
* `on_host_maintenance` - What to do on host maintenance. Default is "MIGRATE".
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-google/action/connect_google.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def initialize(app, env)
def call(env)
provider_config = env[:machine].provider_config

#Build fog config
# Build fog config
fog_config = {
:provider => :google,
:google_project => provider_config.google_project_id,
Expand Down
30 changes: 18 additions & 12 deletions lib/vagrant-google/action/run_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,13 @@ def call(env)
env[:ui].info(" -- Scopes: #{service_accounts}")
begin
request_start_time = Time.now().to_i
#Warn on ssh-key overrides
# Warn on ssh-key overrides
if env[:machine].config.ssh.username.nil?
env[:ui].warn(I18n.t("vagrant_google.warn_ssh_vagrant_user"))
end
#Check if specified external ip is available
if !external_ip.nil?
address = env[:google_compute].addresses.get_by_ip_address(external_ip)
if !address.nil?
if address.in_use?
raise Errors::ExternalIpError,
:externalip => external_ip
end
end
end
#Check if disk type is available in the zone
# Check if specified external ip is available
external_ip = get_external_ip(env, external_ip) if external_ip
# Check if disk type is available in the zone
if !disk_type.nil?
disk_type_obj = env[:google_compute].list_disk_types(zone).body['items'].select { |dt| dt['name'] == disk_type } || []
if !disk_type_obj.empty?
Expand Down Expand Up @@ -201,6 +193,20 @@ def terminate(env)
destroy_env[:force_confirm_destroy] = true
env[:action_runner].run(Action.action_destroy, destroy_env)
end

def get_external_ip(env, external_ip)
address = env[:google_compute].addresses.get_by_ip_address_or_name(external_ip)
if address.nil?
raise Errors::ExternalIpDoesNotExistError,
:externalip => external_ip
end
if address.in_use?
raise Errors::ExternalIpInUseError,
:externalip => external_ip
end
# Resolve the name to IP address
address.address
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/vagrant-google/action/warn_networks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def initialize(app, env)
end

def call(env)
#Default SSH forward always exists so "> 1"
# Default SSH forward always exists so "> 1"
if env[:machine].config.vm.networks.length > 1
env[:ui].warn(I18n.t("vagrant_google.warn_networks"))
end
Expand Down
6 changes: 5 additions & 1 deletion lib/vagrant-google/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ class FogError < VagrantGoogleError
error_key(:fog_error)
end

class ExternalIpError < VagrantGoogleError
class ExternalIpInUseError < VagrantGoogleError
error_key(:external_ip_error)
end

class ExternalIpDoesNotExistError < VagrantGoogleError
error_key(:external_ip_does_not_exist_error)
end

class InstanceReadyTimeout < VagrantGoogleError
error_key(:instance_ready_timeout)
end
Expand Down
9 changes: 6 additions & 3 deletions locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ en:
"vagrant up" will timeout while trying to estabilish an ssh connection
to the instance.
NOTE! Adding Vagrant private key to GCE metadata is heavily discouraged,
since it potentially allows anyone to connect to your instances,
including those not managed by Vagrant.
since it potentially allows anyone to connect to your instances,
including those not managed by Vagrant.
will_not_destroy: |-
The instance '%{name}' will not be destroyed, since the confirmation
was declined.
Expand Down Expand Up @@ -93,7 +93,10 @@ en:
Guest path: %{guestpath}
Error: %{stderr}
external_ip_error: |-
Specified external IP address is invalid or already in use.
Specified external IP address is already in use.
IP address requested: %{externalip}
external_ip_does_not_exist_error: |-
Specified external IP address is invalid or does not exist.
IP address requested: %{externalip}
disk_type_error: |-
Specified disk type is not available in the region selected.
Expand Down

0 comments on commit c312946

Please sign in to comment.