Skip to content

Commit

Permalink
Reserver a /18 a let some spare ips
Browse files Browse the repository at this point in the history
  • Loading branch information
msimonin committed Apr 16, 2017
1 parent e874bc9 commit 9d7511e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ end
```

> Due to the dynamic nature of the subnet reserved on Grid'5000, IPs of the VMs will change accross reboots
> a /18 is reserved but only the first 1024 ips are reserved for the VMs. That means you can use the remaining ips without any conflict.
## Note on resource demand

Expand Down
18 changes: 8 additions & 10 deletions lib/vagrant-g5k/network/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module G5K
module Network

class Bridge

include VagrantPlugins::G5K

def initialize(env, driver, oar_driver)
Expand All @@ -21,7 +21,7 @@ def initialize(env, driver, oar_driver)
def generate_net()
lockable(:lock => VagrantPlugins::G5K.subnet_lock) do
subnet_job_id = _find_subnet
if subnet_job_id.nil?
if subnet_job_id.nil?
subnet_job_id = _create_subnet
@oar_driver.wait_for(subnet_job_id)
# we can't call this inside the launcher script
Expand All @@ -33,7 +33,7 @@ def generate_net()
return "BRIDGE #{_subnet_file}"
end
end

def check_state(job_id)
subnet_job_id = _find_subnet()
return :subnet_missing if subnet_job_id.nil?
Expand Down Expand Up @@ -69,7 +69,7 @@ def _cwd()
def _create_subnet()
options = []
options << "--name '#{@project_id}-net'"
options << "-l 'slash_22=1, walltime=#{@walltime}'"
options << "-l 'slash_18=1, walltime=#{@walltime}'"
@oar_driver.submit_job('sleep 84400', options )
end

Expand All @@ -87,18 +87,18 @@ def _find_subnet()
nil
end

# Update the subnet use
# Update the subnet use
# op is a string "+" or "-"
# if after the update the subnet use is 0
# the subnet in use is also deleted
# if after the update the subnet use is 0
# the subnet in use is also deleted
def _update_subnet_use(op)
cmd = []
cmd << "c=$(cat #{_subnet_count});"
cmd << "echo $(($c #{op} 1)) > #{_subnet_count};"
cmd << "cat #{_subnet_count}"
count = @driver.exec(cmd.join(" "))
@logger.info("subnet_count = #{count}")
if count.to_i <= 0
if count.to_i <= 0
@logger.info("deleteting the associated subnet")
subnet_id = _find_subnet()
@oar_driver.delete_job(subnet_id)
Expand All @@ -111,5 +111,3 @@ def _update_subnet_use(op)
end
end
end


4 changes: 2 additions & 2 deletions lib/vagrant-g5k/util/launch_vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This script is originally borrowed to pmorillo
# Thanks to him !
# I've made some addition though :)
# I've made some addition though :)

# ARGS
# $1: cpu demand
Expand All @@ -17,7 +17,7 @@ set -x
function net_bridge() {
SUBNET_FILE=$1
# As we chose a stateless designe,let's calculate here the ip and mac
# assuming we got a slash_22
# assuming we got at least a slash_22
ipnumber=$(($OAR_JOB_ID % 1022))
IP_MAC=$(cat $SUBNET_FILE|head -n $((ipnumber + 1))|tail -n 1)
IP_ADDR=$(echo $IP_MAC|awk '{print $1}')
Expand Down

0 comments on commit 9d7511e

Please sign in to comment.