Class: Bosh::Director::DeploymentPlan::InstanceProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/deployment_plan/compilation_instance_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(deployment_plan, vm_creator, logger) ⇒ InstanceProvider

Returns a new instance of InstanceProvider.



105
106
107
108
109
# File 'lib/bosh/director/deployment_plan/compilation_instance_pool.rb', line 105

def initialize(deployment_plan, vm_creator, logger)
  @deployment_plan = deployment_plan
  @vm_creator = vm_creator
  @logger = logger
end

Instance Method Details

#create_instance(instance_plan) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
# File 'lib/bosh/director/deployment_plan/compilation_instance_pool.rb', line 141

def create_instance(instance_plan)
  instance_model = instance_plan.instance.model
  parent_id = add_event(instance_model.deployment.name, instance_model.name)
  @deployment_plan.ip_provider.reserve(instance_plan.network_plans.first.reservation)
  @vm_creator.create_for_instance_plan(instance_plan, [])
  instance_plan.instance
rescue Exception => e
  raise e
ensure
  add_event(instance_model.deployment.name, instance_model.name, parent_id, e )
end

#create_instance_plan(stemcell) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/bosh/director/deployment_plan/compilation_instance_pool.rb', line 111

def create_instance_plan(stemcell)
  if @deployment_plan.compilation.vm_type
    vm_type = @deployment_plan.compilation.vm_type
  else
    vm_type = CompilationVmType.new(@deployment_plan.compilation.cloud_properties)
  end

  vm_extensions = @deployment_plan.compilation.vm_extensions

  env = Env.new(@deployment_plan.compilation.env)

  compile_job = CompilationJob.new(vm_type, vm_extensions, stemcell, env, @deployment_plan.compilation.network_name)
  availability_zone = @deployment_plan.compilation.availability_zone
  instance = Instance.create_from_job(compile_job, 0, 'started', @deployment_plan.model, {}, availability_zone, @logger)
  instance.bind_new_instance_model

  compilation_network = @deployment_plan.network(@deployment_plan.compilation.network_name)
  reservation = DesiredNetworkReservation.new_dynamic(instance.model, compilation_network)
  desired_instance = DeploymentPlan::DesiredInstance.new(compile_job, nil)
  instance_plan = DeploymentPlan::InstancePlan.new(
    existing_instance: instance.model,
    instance: instance,
    desired_instance: desired_instance,
    network_plans: [DeploymentPlan::NetworkPlanner::Plan.new(reservation: reservation)]
  )

  compile_job.add_instance_plans([instance_plan])
  instance_plan
end