185
machineStatus := status.StatusPending
184
machineStatus := status.Pending
187
186
if statusInfo, err := m.Status(); err != nil {
188
187
logger.Warningf("cannot get current machine status for machine %v: %v", m.Id(), err)
195
194
// the extra condition below (checking allocating/pending) is here to improve user experience
196
195
// without it the instance status will say "pending" for +10 minutes after the agent comes up to "started"
197
if instInfo.status.Status != status.StatusAllocating && instInfo.status.Status != status.StatusPending {
198
if len(instInfo.addresses) > 0 && machineStatus == status.StatusStarted {
196
if instInfo.status.Status != status.Allocating && instInfo.status.Status != status.Pending {
197
if len(instInfo.addresses) > 0 && machineStatus == status.Started {
199
198
// We've got at least one address and a status and instance is started, so poll infrequently.
200
199
pollInterval = LongPoll
201
200
} else if pollInterval < LongPoll {
240
239
instId, err := m.InstanceId()
241
240
// We can't ask the machine for its addresses if it isn't provisioned yet.
242
241
if params.IsCodeNotProvisioned(err) {
242
return instanceInfo{}, err
246
return instInfo, fmt.Errorf("cannot get machine's instance id: %v", err)
245
return instanceInfo{}, errors.Annotate(err, "cannot get machine's instance id")
248
247
instInfo, err = context.instanceInfo(instId)
250
249
// TODO (anastasiamac 2016-02-01) This does not look like it needs to be removed now.
251
250
if params.IsCodeNotImplemented(err) {
251
return instanceInfo{}, err
254
253
logger.Warningf("cannot get instance info for instance %q: %v", instId, err)
255
254
return instInfo, nil
257
instStat, err := m.InstanceStatus()
256
if instStat, err := m.InstanceStatus(); err != nil {
259
257
// This should never occur since the machine is provisioned.
260
258
// But just in case, we reset polled status so we try again next time.
261
259
logger.Warningf("cannot get current instance status for machine %v: %v", m.Id(), err)
262
instInfo.status = instance.InstanceStatus{status.StatusUnknown, ""}
260
instInfo.status = instance.InstanceStatus{status.Unknown, ""}
264
262
// TODO(perrito666) add status validation.
265
263
currentInstStatus := instance.InstanceStatus{
270
268
logger.Infof("machine %q instance status changed from %q to %q", m.Id(), currentInstStatus, instInfo.status)
271
269
if err = m.SetInstanceStatus(instInfo.status.Status, instInfo.status.Message, nil); err != nil {
272
270
logger.Errorf("cannot set instance status on %q: %v", m, err)
276
providerAddresses, err := m.ProviderAddresses()
280
if !addressesEqual(providerAddresses, instInfo.addresses) {
281
logger.Infof("machine %q has new addresses: %v", m.Id(), instInfo.addresses)
282
if err = m.SetProviderAddresses(instInfo.addresses...); err != nil {
283
logger.Errorf("cannot set addresses on %q: %v", m, err)
271
return instanceInfo{}, err
275
if m.Life() != params.Dead {
276
providerAddresses, err := m.ProviderAddresses()
278
return instanceInfo{}, err
280
if !addressesEqual(providerAddresses, instInfo.addresses) {
281
logger.Infof("machine %q has new addresses: %v", m.Id(), instInfo.addresses)
282
if err := m.SetProviderAddresses(instInfo.addresses...); err != nil {
283
logger.Errorf("cannot set addresses on %q: %v", m, err)
284
return instanceInfo{}, err
289
291
// addressesEqual compares the addresses of the machine and the instance information.