コード例 #1
0
ファイル: configure_port_layer.go プロジェクト: vmware/vic
func configureAPI(api *operations.PortLayerAPI) http.Handler {
	if options.PortLayerOptions.Debug {
		log.SetLevel(log.DebugLevel)
	}

	ctx := context.Background()

	sessionconfig := &session.Config{
		Service:        options.PortLayerOptions.SDK,
		Insecure:       options.PortLayerOptions.Insecure,
		Keepalive:      options.PortLayerOptions.Keepalive,
		DatacenterPath: options.PortLayerOptions.DatacenterPath,
		ClusterPath:    options.PortLayerOptions.ClusterPath,
		PoolPath:       options.PortLayerOptions.PoolPath,
		DatastorePath:  options.PortLayerOptions.DatastorePath,
	}

	sess, err := session.NewSession(sessionconfig).Create(ctx)
	if err != nil {
		log.Fatalf("configure_port_layer ERROR: %s", err)
	}

	// Configure the func invoked if the PL panics or is restarted by vic-init
	api.ServerShutdown = func() {
		log.Infof("Shutting down port-layer-server")

		// Logout the session
		if err := sess.Logout(ctx); err != nil {
			log.Warnf("unable to log out of session: %s", err)
		}
	}

	// initialize the port layer
	if err = portlayer.Init(ctx, sess); err != nil {
		log.Fatalf("could not initialize port layer: %s", err)
	}

	// configure the api here
	api.ServeError = errors.ServeError

	api.BinConsumer = httpkit.ByteStreamConsumer()

	api.JSONConsumer = httpkit.JSONConsumer()

	api.JSONProducer = httpkit.JSONProducer()

	api.TxtProducer = httpkit.TextProducer()

	handlerCtx := &handlers.HandlerContext{
		Session: sess,
	}
	for _, handler := range portlayerhandlers {
		handler.Configure(api, handlerCtx)
	}

	return setupGlobalMiddleware(api.Serve(setupMiddlewares))
}
コード例 #2
0
ファイル: container_proxy.go プロジェクト: kjplatz/vic
func (c *ContainerProxy) createNewAttachClientWithTimeouts(connectTimeout, responseTimeout, responseHeaderTimeout time.Duration) (*client.PortLayer, *httpclient.Transport) {
	runtime := httptransport.New(c.portlayerAddr, "/", []string{"http"})
	transport := &httpclient.Transport{
		ConnectTimeout:        connectTimeout,
		ResponseHeaderTimeout: responseHeaderTimeout,
		RequestTimeout:        responseTimeout,
	}
	runtime.Transport = transport

	plClient := client.New(runtime, nil)
	runtime.Consumers["application/octet-stream"] = httpkit.ByteStreamConsumer()
	runtime.Producers["application/octet-stream"] = httpkit.ByteStreamProducer()

	return plClient, transport
}
コード例 #3
0
ファイル: storage.go プロジェクト: vmware/vic
// WriteImage writes the image to given image store
func WriteImage(host string, image *ImageWithMeta, data io.ReadCloser) error {
	defer trace.End(trace.Begin(image.ID))

	transport := httptransport.New(host, "/", []string{"http"})
	client := apiclient.New(transport, nil)

	transport.Consumers["application/json"] = httpkit.JSONConsumer()
	transport.Producers["application/json"] = httpkit.JSONProducer()
	transport.Consumers["application/octet-stream"] = httpkit.ByteStreamConsumer()
	transport.Producers["application/octet-stream"] = httpkit.ByteStreamProducer()

	key := new(string)
	blob := new(string)

	*key = metadata.MetaDataKey
	*blob = image.Meta

	r, err := client.Storage.WriteImage(
		storage.NewWriteImageParamsWithContext(ctx).
			WithImageID(image.ID).
			WithParentID(*image.Parent).
			WithStoreName(image.Store).
			WithMetadatakey(key).
			WithMetadataval(blob).
			WithImageFile(data).
			WithSum(image.Layer.BlobSum),
	)
	if err != nil {
		log.Debugf("Creating an image failed: %s", err)
		return err
	}
	log.Printf("Created an image %#v", r.Payload)

	return nil

}