lib/kytoon/providers/xenserver/server_group.rb in kytoon-1.2.4 vs lib/kytoon/providers/xenserver/server_group.rb in kytoon-1.2.5
- old
+ new
@@ -46,21 +46,23 @@
attr_accessor :broadcast
attr_accessor :network_type
attr_accessor :bridge
attr_accessor :public_ip_bridge
attr_accessor :dns_nameserver
+ attr_accessor :cleanup_before_create
def initialize(options={})
- @id = options[:id] || Time.now.to_i
+ @id = options[:id] || Time.now.to_f
@name = options[:name]
@netmask = options[:netmask]
@gateway = options[:gateway]
@broadcast = options[:broadcast]
@network_type = options[:network_type]
@bridge = options[:bridge]
@public_ip_bridge = options[:public_ip_bridge]
@dns_nameserver = options[:dns_nameserver]
+ @cleanup_before_create = options[:cleanup_before_create]
@gateway_ip = options[:gateway_ip]
@gateway_ip = ENV['GATEWAY_IP'] if @gateway_ip.nil?
raise ConfigException, "Please specify a GATEWAY_IP" if @gateway_ip.nil?
@servers=[]
@@ -91,10 +93,11 @@
:gateway_ip => json_hash['gateway_ip'],
:broadcast => json_hash['broadcast'],
:dns_nameserver => json_hash['dns_nameserver'],
:network_type => json_hash['network_type'],
:public_ip_bridge => json_hash['public_ip_bridge'],
+ :cleanup_before_create => json_hash['cleanup_before_create'],
:bridge => json_hash['bridge']
)
json_hash["servers"].each do |server_hash|
sg.servers << {
'hostname' => server_hash['hostname'],
@@ -143,10 +146,11 @@
'netmask' => @netmask,
'gateway' => @gateway,
'gateway_ip' => @gateway_ip,
'broadcast' => @broadcast,
'dns_nameserver' => @dns_nameserver,
+ 'cleanup_before_create' => @cleanup_before_create,
'network_type' => @network_type,
'public_ip_bridge' => @public_ip_bridge,
'bridge' => @bridge,
'servers' => []
}
@@ -166,9 +170,10 @@
out_file=File.join(@@data_dir, "#{@id}.json")
File.delete(out_file) if File.exists?(out_file)
end
def self.create(sg)
+ ServerGroup.cleanup_instances(sg.gateway_ip) if sg.cleanup_before_create
sg.cache_to_disk
init_host(sg)
status, host_ssh_public_key = Kytoon::Util.remote_exec(%{
if [ -f /root/.ssh/id_rsa.pub ]; then
cat /root/.ssh/id_rsa.pub