pulumi/pkg/compiler/backends/provider.go
joeduffy 5f33292496 Move assertion/failure functions
This change just moves the assertion/failure functions from the pkg/util
package to pkg/util/contract, so things read a bit nicer (i.e.,
`contract.Assert(x)` versus `util.Assert(x)`).
2017-01-15 14:26:48 -08:00

50 lines
1.5 KiB
Go

// Copyright 2016 Marapongo, Inc. All rights reserved.
package backends
import (
"github.com/marapongo/mu/pkg/compiler/backends/clouds"
"github.com/marapongo/mu/pkg/compiler/backends/clouds/aws"
"github.com/marapongo/mu/pkg/compiler/backends/schedulers"
"github.com/marapongo/mu/pkg/compiler/backends/schedulers/awsecs"
"github.com/marapongo/mu/pkg/compiler/core"
"github.com/marapongo/mu/pkg/diag"
"github.com/marapongo/mu/pkg/util/contract"
)
func New(arch Arch, d diag.Sink) core.Backend {
// Bind to the cloud provider.
var cloud clouds.Cloud
switch arch.Cloud {
case clouds.AWS:
// TODO(joe): come up with a way to get options from CLI/workspace/etc. to here.
cloud = aws.New(d, aws.Options{})
case clouds.None:
contract.FailM("Expected a non-None cloud architecture")
default:
contract.FailMF("Cloud architecture '%v' not yet supported", clouds.Names[arch.Cloud])
}
contract.Assert(cloud != nil)
contract.Assert(cloud.Arch() == arch.Cloud)
// Set the backend to the cloud provider.
var be core.Backend = cloud
// Now bind to the scheduler, if any, wrapping the cloud and replacing the backend.
var scheduler schedulers.Scheduler
switch arch.Scheduler {
case schedulers.None:
// Nothing to do.
case schedulers.AWSECS:
scheduler = awsecs.New(d, cloud)
default:
contract.FailMF("Scheduler architecture '%v' not yet supported", schedulers.Names[arch.Scheduler])
}
if scheduler != nil {
contract.Assert(scheduler.Arch() == arch.Scheduler)
be = scheduler
}
return be
}