Beispiel #1
0
// newGCECloud creates a new instance of GCECloud.
func newGCECloud() (*GCECloud, error) {
	projectID, zone, err := getProjectAndZone()
	if err != nil {
		return nil, err
	}
	// TODO: if we want to use this on a machine that doesn't have the http://metadata server
	// e.g. on a user's machine (not VM) somewhere, we need to have an alternative for
	// instance id lookup.
	instanceID, err := getInstanceID()
	if err != nil {
		return nil, err
	}
	client, err := serviceaccount.NewClient(&serviceaccount.Options{})
	if err != nil {
		return nil, err
	}
	svc, err := compute.New(client)
	if err != nil {
		return nil, err
	}
	return &GCECloud{
		service:    svc,
		projectID:  projectID,
		zone:       zone,
		instanceID: instanceID,
	}, nil
}
Beispiel #2
0
// Updates the network mask with the real on from the cloud config.
func updateIPNet(ipnet *net.IPNet) error {
	// Retrieve the configuration ids
	projectId, err := fetchProjectId()
	if err != nil {
		return err
	}
	networkId, err := fetchNetworkId()
	if err != nil {
		return err
	}
	// Create a service account connection to the GCE API
	client, err := serviceaccount.NewClient(&serviceaccount.Options{})
	if err != nil {
		return err
	}
	gce, err := compute.New(client)
	if err != nil {
		return err
	}
	// Fetch the network configurations and update the netmask
	network, err := gce.Networks.Get(projectId, networkId).Do()
	if err != nil {
		return err
	}
	_, ipn, err := net.ParseCIDR(network.IPv4Range)
	if err != nil {
		return err
	}
	ipnet.Mask = ipn.Mask
	return nil
}
Beispiel #3
0
func NewGCECloud() (*GCECloud, error) {
	projectID, zone, err := getProjectAndZone()
	if err != nil {
		return nil, err
	}
	client, err := serviceaccount.NewClient(&serviceaccount.Options{})
	if err != nil {
		return nil, err
	}
	svc, err := compute.New(client)
	if err != nil {
		return nil, err
	}
	return &GCECloud{
		service:   svc,
		projectID: projectID,
		zone:      zone,
	}, nil
}
// NewImageProcessor constructs an imageProcessor which listens for input on the provided channel
// and logs to stderr with its name as the prefix.
func NewImageProcessor(c <-chan processImageReq, name string) *imageProcessor {
	client, err := serviceaccount.NewClient(&serviceaccount.Options{
		Transport: &RetryTransport{http.DefaultTransport, 5},
	})
	if err != nil {
		log.Panicf("Failed to create service account client: %v\n", err)
	}
	service, err := storage.New(client)
	if err != nil {
		log.Panicf("Failed to create GCS client: %v\n", err)
	}
	return &imageProcessor{
		c:      c,
		client: client,
		s:      service,
		l:      log.New(os.Stderr, name, log.LstdFlags),
	}

}