Expect(err).ToNot(HaveOccurred())
			Expect(action).To(Equal(NewCreateStemcell(stemcellFinder)))
		})

		It("delete_stemcell", func() {
			action, err := factory.Create("delete_stemcell")
			Expect(err).ToNot(HaveOccurred())
			Expect(action).To(Equal(NewDeleteStemcell(stemcellFinder)))
		})
	})

	Context("VM methods", func() {
		It("create_vm", func() {
			vmCreator := bslcvm.NewSoftLayerCreator(
				softLayerClient,
				agentEnvServiceFactory,
				options.Agent,
				logger,
			)

			action, err := factory.Create("create_vm")
			Expect(err).ToNot(HaveOccurred())
			Expect(action).To(Equal(NewCreateVM(stemcellFinder, vmCreator)))
		})

		It("delete_vm", func() {
			action, err := factory.Create("delete_vm")
			Expect(err).ToNot(HaveOccurred())
			Expect(action).To(Equal(NewDeleteVM(vmFinder)))
		})

		It("has_vm", func() {
Пример #2
0
func NewConcreteFactory(softLayerClient sl.Client, options ConcreteFactoryOptions, logger boshlog.Logger) concreteFactory {
	stemcellFinder := bslcstem.NewSoftLayerFinder(softLayerClient, logger)

	agentEnvServiceFactory := bslcvm.NewSoftLayerAgentEnvServiceFactory(softLayerClient, logger)

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

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

	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),

			// 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
		},
	}
}