Ejemplo n.º 1
0
func setup() {
	apiUser := os.Getenv("SL_API_USER")
	apiKey := os.Getenv("SL_API_KEY")

	if apiUser == "" || apiKey == "" {

		fmt.Println("Please don't forget to set SL_API_USER and SL_API_KEY before running command")
		return
	}

	apiClient = slclient.NewSoftLayerClient(apiUser, apiKey)

	accountService, err := apiClient.GetSoftLayer_Account_Service()

	if err != nil {
		fmt.Fprintf(os.Stderr, "Init sl cloud failed due to %s \n", err)
		return
	}

	accountStatus, err := accountService.GetAccountStatus()

	if err != nil {
		fmt.Fprintf(os.Stderr, "Init sl cloud failed due to %s \n", err)
		return
	} else if strings.ToLower(accountStatus.Name) != "active" {
		fmt.Fprintf(os.Stderr, "Account status is %s, not as Active expected \n", accountStatus.Name)
		return
	}

	initDone = true
}
Ejemplo n.º 2
0
// NewSoftlayer creates new Softlayer client for the given credentials.
func NewSoftlayer(username, apiKey string) *Softlayer {
	client := client.NewSoftLayerClient(username, apiKey)
	opts := &Options{
		SLClient: client,
	}
	return NewSoftlayerWithOptions(opts)
}
Ejemplo n.º 3
0
func FindHostname(hostname string) (bool, error) {

	apiUser := os.Getenv(ApiUser)
	apiKey := os.Getenv(ApiKey)

	client := slclient.NewSoftLayerClient(apiUser, apiKey)

	accountService, err := client.GetSoftLayer_Account_Service()
	if err != nil {
		return false, err
	}

	virtualGuests, err := accountService.GetVirtualGuests()

	if err != nil {
		return false, err
	}

	for _, guest := range virtualGuests {
		if strings.Contains(guest.Hostname, hostname) {
			fmt.Printf("Found guest %v ")
			return true, nil
		}
	}

	return true, nil
}
Ejemplo n.º 4
0
func main() {

	apiUser := os.Getenv(ApiUser)
	apiKey := os.Getenv(ApiKey)

	id := 12345

	client := slclient.NewSoftLayerClient(apiUser, apiKey)

	virtualGuestService, err := client.GetSoftLayer_Virtual_Guest_Service()

	if err != nil {
		fmt.Println(err)
		return
	} else {
		fmt.Println("No error found in client.GetSoftLayer_Virtual_Guest_Service()")
	}

	virtualGuest, err := virtualGuestService.GetObject(id)

	if err != nil {
		fmt.Println("errors:", err)
		return
	} else {
		fmt.Println("No error found in virtualGuestService.GetObject(id)")
	}

	spew.Printf("virtualGuest =%#+v\n", virtualGuest)

	vgPowerState, err := virtualGuestService.GetPowerState(id)

	spew.Printf("vgPowerState =%#+v\n", vgPowerState)
}
Ejemplo n.º 5
0
func init() {
	os.Unsetenv("SL_GO_NON_VERBOSE")

	opts.SLClient = slclient.NewSoftLayerClient(
		os.Getenv("KLOUD_TESTACCOUNT_SLUSERNAME"),
		os.Getenv("KLOUD_TESTACCOUNT_SLAPIKEY"),
	)
}
func createSoftLayerClient() (softlayer.Client, error) {
	username := os.Getenv("SL_USERNAME")
	if username == "" {
		return nil, errors.New("stemcells: cannot create SoftLayer client: SL_USERNAME environment variable must be set")
	}

	apiKey := os.Getenv("SL_API_KEY")
	if apiKey == "" {
		return nil, errors.New("stemcells: cannot create SoftLayer client: SL_API_KEY environment variable must be set")
	}

	return slclient.NewSoftLayerClient(username, apiKey), nil
}
Ejemplo n.º 7
0
func GetClient() (softlayer.Client, error) {

	apiUser := os.Getenv("SL_API_USER")
	apiKey := os.Getenv("SL_API_KEY")

	if apiUser == "" || apiKey == "" {

		fmt.Println("Please don't forget to set SL_API_USER and SL_API_KEY before running command")
		return nil, fmt.Errorf("apiUser and key are not setting.")
	}

	return slclient.NewSoftLayerClient(apiUser, apiKey), nil
}
Ejemplo n.º 8
0
func buildDispatcher(config Config, logger boshlog.Logger, fs boshsys.FileSystem, cmdRunner boshsys.CmdRunner) bslcdisp.Dispatcher {
	softLayerClient := slclient.NewSoftLayerClient(config.SoftLayer.Username, config.SoftLayer.ApiKey)

	actionFactory := bslcaction.NewConcreteFactory(
		softLayerClient,
		config.Actions,
		logger,
	)

	caller := bslcdisp.NewJSONCaller()

	return bslcdisp.NewJSON(actionFactory, caller, logger)
}
Ejemplo n.º 9
0
// Uses credentials provided during stack build to create
// a Softlayer machine representation and it's client
func NewMachine(bm *provider.BaseMachine) (provider.Machine, error) {
	c, ok := bm.Credential.(*Credential)
	if !ok {
		return nil, errors.New("not a valid Soflayer credential")
	}

	m := &Machine{
		BaseMachine: bm,
		Client:      softlayerGo.NewSoftLayerClient(c.Username, c.ApiKey),
	}

	return m, nil
}
Ejemplo n.º 10
0
func (c *SoftLayerClient) createSoftLayerClient() (softlayer.Client, error) {
	username := os.Getenv("SL_USERNAME")
	if username == "" {
		return nil, errors.New("You must set environment variable SL_USERNAME for SoftLayer cloud")
	}

	apiKey := os.Getenv("SL_API_KEY")
	if apiKey == "" {
		return nil, errors.New("You must set environment variable SL_API_KEY for SoftLayer cloud")
	}

	return slclient.NewSoftLayerClient(username, apiKey), nil
}
Ejemplo n.º 11
0
func CreateDnsDomainResourceRecordService() (softlayer.SoftLayer_Dns_Domain_ResourceRecord_Service, error) {
	username, apiKey, err := GetUsernameAndApiKey()
	if err != nil {
		return nil, err
	}

	client := slclient.NewSoftLayerClient(username, apiKey)
	dnsDomainResourceRecordService, err := client.GetSoftLayer_Dns_Domain_ResourceRecord_Service()
	if err != nil {
		return nil, err
	}

	return dnsDomainResourceRecordService, nil
}
Ejemplo n.º 12
0
func CreateNetworkStorageService() (softlayer.SoftLayer_Network_Storage_Service, error) {
	username, apiKey, err := GetUsernameAndApiKey()
	if err != nil {
		return nil, err
	}

	client := slclient.NewSoftLayerClient(username, apiKey)
	networkStorageService, err := client.GetSoftLayer_Network_Storage_Service()
	if err != nil {
		return nil, err
	}

	return networkStorageService, nil
}
Ejemplo n.º 13
0
func CreateProductPackageService() (softlayer.SoftLayer_Product_Package_Service, error) {
	username, apiKey, err := GetUsernameAndApiKey()
	if err != nil {
		return nil, err
	}

	client := slclient.NewSoftLayerClient(username, apiKey)
	productPackageService, err := client.GetSoftLayer_Product_Package_Service()
	if err != nil {
		return nil, err
	}

	return productPackageService, nil
}
Ejemplo n.º 14
0
func CreateSecuritySshKeyService() (softlayer.SoftLayer_Security_Ssh_Key_Service, error) {
	username, apiKey, err := GetUsernameAndApiKey()
	if err != nil {
		return nil, err
	}

	client := slclient.NewSoftLayerClient(username, apiKey)
	sshKeyService, err := client.GetSoftLayer_Security_Ssh_Key_Service()
	if err != nil {
		return nil, err
	}

	return sshKeyService, nil
}
Ejemplo n.º 15
0
func CreateVirtualGuestBlockDeviceTemplateGroupService() (softlayer.SoftLayer_Virtual_Guest_Block_Device_Template_Group_Service, error) {
	username, apiKey, err := GetUsernameAndApiKey()
	if err != nil {
		return nil, err
	}

	client := slclient.NewSoftLayerClient(username, apiKey)
	vgbdtgService, err := client.GetSoftLayer_Virtual_Guest_Block_Device_Template_Group_Service()
	if err != nil {
		return nil, err
	}

	return vgbdtgService, nil
}
Ejemplo n.º 16
0
func CreateVirtualGuestService() (softlayer.SoftLayer_Virtual_Guest_Service, error) {
	username, apiKey, err := GetUsernameAndApiKey()
	if err != nil {
		return nil, err
	}

	client := slclient.NewSoftLayerClient(username, apiKey)
	virtualGuestService, err := client.GetSoftLayer_Virtual_Guest_Service()
	if err != nil {
		return nil, err
	}

	return virtualGuestService, nil
}
Ejemplo n.º 17
0
func CreateAccountService() (softlayer.SoftLayer_Account_Service, error) {
	username, apiKey, err := GetUsernameAndApiKey()
	if err != nil {
		return nil, err
	}

	client := slclient.NewSoftLayerClient(username, apiKey)
	accountService, err := client.GetSoftLayer_Account_Service()
	if err != nil {
		return nil, err
	}

	return accountService, nil
}
func (c *Config) Client() (*Client, error) {
	slc := slclient.NewSoftLayerClient(c.Username, c.ApiKey)
	virtualGuestService, err := slc.GetSoftLayer_Virtual_Guest_Service()

	if err != nil {
		return nil, err
	}

	sshKeyService, err := slc.GetSoftLayer_Security_Ssh_Key_Service()

	client := &Client{
		virtualGuestService: virtualGuestService,
		sshKeyService:       sshKeyService,
	}

	log.Println("[INFO] Created SoftLayer client")

	return client, nil
}
Ejemplo n.º 19
0
// Verifies the given Softlayer credential.
// Compared against what is defined in schema.Credential.
func (s *Stack) VerifyCredential(c *stack.Credential) error {
	cred, ok := c.Credential.(*Credential)
	if !ok {
		return fmt.Errorf("credential is not of type softlayer.Credential: %T", c.Credential)
	}

	if err := cred.Valid(); err != nil {
		return err
	}

	// Do a quick check to verify the credentials are valid for
	// communitcating with the SoftLayer apis
	client := softlayer.NewSoftLayerClient(cred.Username, cred.ApiKey)
	account, err := client.GetSoftLayer_Account_Service()
	if err != nil {
		return err
	}

	_, err = account.GetAccountStatus()
	return err
}
Ejemplo n.º 20
0
// New creates new Softlayer command client.
func New(conf *SLConfig) (*SLImages, error) {
	// To suppress softlayer-go debug printfs...
	if err := os.Setenv("SL_GO_NON_VERBOSE", "YES"); err != nil {
		return nil, err
	}
	client := slclient.NewSoftLayerClient(conf.Username, conf.APIKey)
	account, err := client.GetSoftLayer_Account_Service()
	if err != nil {
		return nil, err
	}

	block, err := client.GetSoftLayer_Virtual_Guest_Block_Device_Template_Group_Service()
	if err != nil {
		return nil, err
	}

	return &SLImages{
		client:  client,
		account: account,
		block:   block,
	}, nil
}
		virtualGuest  datatypes.SoftLayer_Virtual_Guest
		createdSshKey datatypes.SoftLayer_Security_Ssh_Key

		rootTemplatePath, strVGID string

		replacementMap map[string]string
	)

	BeforeEach(func() {
		username = os.Getenv("SL_USERNAME")
		Expect(username).ToNot(Equal(""), "username cannot be empty, set SL_USERNAME")

		apiKey = os.Getenv("SL_API_KEY")
		Expect(apiKey).ToNot(Equal(""), "apiKey cannot be empty, set SL_API_KEY")

		client = slclient.NewSoftLayerClient(username, apiKey)
		Expect(client).ToNot(BeNil())

		accountService, err = testhelpers.CreateAccountService()
		Expect(err).ToNot(HaveOccurred())

		virtualGuestService, err = testhelpers.CreateVirtualGuestService()
		Expect(err).ToNot(HaveOccurred())

		testhelpers.TIMEOUT = 35 * time.Minute
		testhelpers.POLLING_INTERVAL = 10 * time.Second
	})

	Context("set_vm_metadata", func() {
		BeforeEach(func() {
			err = testhelpers.FindAndDeleteTestSshKeys()