Ejemplo n.º 1
0
func NewConcreteFactory(softLayerClient sl.Client, options ConcreteFactoryOptions, logger boshlog.Logger, uuidGenerator boshuuid.Generator, fs boshsys.FileSystem) concreteFactory {

	stemcellFinder := bslcstem.NewSoftLayerFinder(softLayerClient, logger)

	agentEnvServiceFactory := bslcvm.NewSoftLayerAgentEnvServiceFactory(options.AgentEnvService, options.Registry, logger)

	vmCreator := bslcvm.NewSoftLayerCreator(
		softLayerClient,
		agentEnvServiceFactory,
		options.Agent,
		logger,
		uuidGenerator,
		fs,
	)

	vmFinder := bslcvm.NewSoftLayerFinder(
		softLayerClient,
		agentEnvServiceFactory,
		logger,
		uuidGenerator,
		fs,
	)

	bmCreator := bslcbm.NewBaremetalCreator(softLayerClient, logger)
	bmFinder := bslcbm.NewBaremetalFinder(softLayerClient, logger)

	diskCreator := bslcdisk.NewSoftLayerDiskCreator(
		softLayerClient,
		logger,
	)

	diskFinder := bslcdisk.NewSoftLayerDiskFinder(
		softLayerClient,
		logger,
	)

	return concreteFactory{
		availableActions: map[string]Action{
			// Stemcell management
			"create_stemcell": NewCreateStemcell(stemcellFinder),
			"delete_stemcell": NewDeleteStemcell(stemcellFinder, logger),

			// VM management
			"create_vm":          NewCreateVM(stemcellFinder, vmCreator),
			"delete_vm":          NewDeleteVM(vmFinder),
			"has_vm":             NewHasVM(vmFinder),
			"reboot_vm":          NewRebootVM(vmFinder),
			"set_vm_metadata":    NewSetVMMetadata(vmFinder),
			"configure_networks": NewConfigureNetworks(vmFinder),

			// Disk management
			"create_disk": NewCreateDisk(diskCreator),
			"delete_disk": NewDeleteDisk(diskFinder),
			"attach_disk": NewAttachDisk(vmFinder, diskFinder),
			"detach_disk": NewDetachDisk(vmFinder, diskFinder),

			"establish_bare_metal_env": NewEstablishBareMetalEnv(bmCreator, bmFinder),

			// Not implemented (disk related):
			//   snapshot_disk
			//   delete_snapshot
			//   get_disks

			// Not implemented (others):
			//   current_vm_id
			//   ping
		},
	}
}
	fakeslclient "github.com/maximilien/softlayer-go/client/fakes"
)

var _ = Describe("BaremetalCreator", func() {
	var (
		softLayerClient *fakeslclient.FakeSoftLayerClient
		logger          boshlog.Logger
		creator         bm.BaremetalCreator
	)

	BeforeEach(func() {
		softLayerClient = fakeslclient.NewFakeSoftLayerClient("fake-username", "fake-api-key")
		logger = boshlog.NewLogger(boshlog.LevelNone)

		creator = bm.NewBaremetalCreator(
			softLayerClient,
			logger,
		)
		testhelpers.SetTestFixtureForFakeSoftLayerClient(softLayerClient, "SoftLayer_Hardware_Service_createObject.json")
	})

	Describe("Create", func() {
		Context("succeeded", func() {
			It("returns a new Softlayer Hardware without an error", func() {
				baremetal, err := creator.Create(2, 1, 10, "fake-host", "fake-domain", "fake-os", "fake-data-center")
				Expect(err).ToNot(HaveOccurred())
				Expect(baremetal.GlobalIdentifier).To(Equal("fake-id"))
				Expect(baremetal.BareMetalInstanceFlag).To(Equal(0))
				Expect(baremetal.ProvisionDate).To(BeNil())
				Expect(baremetal.PrimaryIpAddress).To(Equal(""))
			})
		})