<commit_before>// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package gce

import (
	"code.google.com/p/google-api-go-client/compute/v1"
	"github.com/juju/errors"

	"github.com/juju/juju/instance"
	"github.com/juju/juju/network"
)

type environInstance struct {
	id         instance.Id
	env        *environ
	zone       string
	rootDiskMB uint64

	// TODO(ericsnow) rename this to "raw"?
	gce *compute.Instance
}

var _ instance.Instance = (*environInstance)(nil)

func newInstance(raw *compute.Instance, env *environ) *environInstance {
	inst := environInstance{
		id:   instance.Id(raw.Name),
		env:  env,
		zone: zoneName(raw),
	}
	inst.update(raw)
	return &inst
}

func (inst *environInstance) Id() instance.Id {
	return inst.id
}

func (inst *environInstance) Status() string {
	return inst.gce.Status
}

func (inst *environInstance) update(raw *compute.Instance) {
	inst.gce = raw

	attached := rootDisk(raw)
	if diskSize, ok := inst.diskSize(attached); ok {
		inst.rootDiskMB = diskSize
	}
}

func (inst *environInstance) diskSize(attached *compute.AttachedDisk) (uint64, bool) {
	diskSizeGB, err := diskSizeGB(attached)
	if err != nil {
		logger.Errorf("error while getting root disk size: %v", err)
		disk, err := inst.env.gce.disk(attached.Source)
		if err != nil {
			logger.Errorf("error while getting root disk: %v", err)
			// Leave it what it was.
			return 0, false
		}
		diskSizeGB = disk.SizeGb
	}
	return uint64(diskSizeGB) * 1024, true
}

func (inst *environInstance) Refresh() error {
	env := inst.env.getSnapshot()

	raw, err := env.gce.instance(inst.zone, string(inst.id))
	if err != nil {
		return errors.Trace(err)
	}

	// TODO(ericsnow) Drop the hack of carrying over InitializeParams?
	if rootDisk(raw).InitializeParams == nil {
		rootDisk(raw).InitializeParams = rootDisk(inst.gce).InitializeParams
	}
	inst.update(raw)
	return nil
}
<commit_msg>provider/gce: Log warnings instead of errors.<commit_after>// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package gce

import (
	"code.google.com/p/google-api-go-client/compute/v1"
	"github.com/juju/errors"

	"github.com/juju/juju/instance"
	"github.com/juju/juju/network"
)

type environInstance struct {
	id         instance.Id
	env        *environ
	zone       string
	rootDiskMB uint64

	// TODO(ericsnow) rename this to "raw"?
	gce *compute.Instance
}

var _ instance.Instance = (*environInstance)(nil)

func newInstance(raw *compute.Instance, env *environ) *environInstance {
	inst := environInstance{
		id:   instance.Id(raw.Name),
		env:  env,
		zone: zoneName(raw),
	}
	inst.update(raw)
	return &inst
}

func (inst *environInstance) Id() instance.Id {
	return inst.id
}

func (inst *environInstance) Status() string {
	return inst.gce.Status
}

func (inst *environInstance) update(raw *compute.Instance) {
	inst.gce = raw

	attached := rootDisk(raw)
	if diskSize, ok := inst.diskSize(attached); ok {
		inst.rootDiskMB = diskSize
	}
}

func (inst *environInstance) diskSize(attached *compute.AttachedDisk) (uint64, bool) {
	diskSizeGB, err := diskSizeGB(attached)
	if err != nil {
		logger.Warningf("error while getting root disk size: %v", err)
		disk, err := inst.env.gce.disk(attached.Source)
		if err != nil {
			logger.Warningf("error while getting root disk: %v", err)
			// Leave it what it was.
			return 0, false
		}
		diskSizeGB = disk.SizeGb
	}
	return uint64(diskSizeGB) * 1024, true
}

func (inst *environInstance) Refresh() error {
	env := inst.env.getSnapshot()

	raw, err := env.gce.instance(inst.zone, string(inst.id))
	if err != nil {
		return errors.Trace(err)
	}

	// TODO(ericsnow) Drop the hack of carrying over InitializeParams?
	if rootDisk(raw).InitializeParams == nil {
		rootDisk(raw).InitializeParams = rootDisk(inst.gce).InitializeParams
	}
	inst.update(raw)
	return nil
}

{'fraction_non_alphanumeric': 0.12874097007223942, 'fraction_numerical': 0.008771929824561403, 'mean_word_length': 3.9325699745547076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5866990', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1373, 'n_words': 343}