Class: Bosh::Director::InstanceUpdater::VmUpdater::VmCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/bosh/director/instance_updater/vm_updater.rb

Instance Method Summary collapse

Constructor Details

#initialize(instance, cloud, logger) ⇒ VmCreator

Returns a new instance of VmCreator.



81
82
83
84
85
# File 'lib/bosh/director/instance_updater/vm_updater.rb', line 81

def initialize(instance, cloud, logger)
  @instance = instance
  @cloud = cloud
  @logger = logger
end

Instance Method Details

#create(new_disk_id) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/bosh/director/instance_updater/vm_updater.rb', line 87

def create(new_disk_id)
  @logger.info('Creating VM')

  deployment = @instance.job.deployment
  resource_pool = @instance.job.resource_pool

  vm_model = Bosh::Director::VmCreator.create(
    deployment.model,
    resource_pool.stemcell.model,
    resource_pool.cloud_properties,
    @instance.network_settings,
    [@instance.model.persistent_disk_cid, new_disk_id].compact,
    resource_pool.env,
  )

  begin
    @instance.model.vm = vm_model
    @instance.model.save

    agent_client = AgentClient.with_defaults(vm_model.agent_id)
    agent_client.wait_until_ready
  rescue Exception => e
    @logger.error("Failed to create/contact VM #{vm_model.cid}: #{e.inspect}")
    VmDeleter.new(@instance, vm_model, @cloud, @logger).delete
    raise e
  end

  [vm_model, agent_client]
end