
class Wakame::Command::PropagateService
  include Wakame::Command

  #command_name='launch_cluster'

  def parse(args)
    @resource
  end

  def run(rule)
    prop = nil
    prop = rule.service_cluster.properties[@options["service"]]
    if prop.nil?
      raise "UnknownProperty: #{@options["service"]}" 
    end

    @num = nil
    @num = @options["num"] || 1

    unless /^(\d){1,32}$/ =~ @num.to_s
      raise "The number is not appropriate: #{@num}"
    end

    instance = rule.master.service_cluster.dump_status[:properties][@options["service"]]
    if @num.to_i > (instance[:max_instances].to_i - instance[:instances].count.to_i)
      raise "The number is not appropriate: #{@num}"
    end

    rule.trigger_action(Wakame::Actions::PropagateInstances.new(prop, @num.to_i))
  end
end


class Wakame::Command::PropagateService
  include Wakame::Command
  include Wakame

  command_name='propagate_service'

  def run(trigger)
    refsvc = Service::ServiceInstance.find(@options["service_id"]) || raise("Unknown ServiceInstance: #{@options["service_id"]}")

    host_id = @options["host_id"]
    unless host_id.nil?
      host = Service::Host.find(host_id) || raise("Specified host was not found: #{host_id}")
      raise "Same resouce type is already assigned: #{refsvc.resource.class} on #{host_id}" if host.has_resource_type?(refsvc.resource)
    end

    num = @options["number"] || 1
    raise "Invalid format of number: #{num}" unless /^(\d+)$/ =~ num.to_s
    num = num.to_i

    if num < 1 || refsvc.resource.max_instances < trigger.cluster.instance_count(refsvc.resource) + num
      raise "The number must be between 1 and #{refsvc.resource.max_instances - trigger.cluster.instance_count(refsvc.resource)} (max limit: #{refsvc.resource.max_instances})"
    end

    num.times {
      trigger.trigger_action(Wakame::Actions::PropagateService.new(refsvc))
    }
  end
end

Update to recognize new propergate_service command options.
Update to recognize new propergate_service command options.
