Beispiel #1
0
func TestListExtensions(t *testing.T) {
	client, err := newClient()
	th.AssertNoErr(t, err)

	err = extensions.List(client).EachPage(func(page pagination.Page) (bool, error) {
		t.Logf("--- Page ---")

		exts, err := extensions.ExtractExtensions(page)
		th.AssertNoErr(t, err)

		for i, ext := range exts {
			t.Logf("[%02d]    name=[%s]\n", i, ext.Name)
			t.Logf("       alias=[%s]\n", ext.Alias)
			t.Logf(" description=[%s]\n", ext.Description)
		}

		return true, nil
	})
	th.AssertNoErr(t, err)
}
func (s *StepLoadExtensions) Run(state multistep.StateBag) multistep.StepAction {
	config := state.Get("config").(Config)
	ui := state.Get("ui").(packer.Ui)

	// We need the v2 compute client
	client, err := config.computeV2Client()
	if err != nil {
		err = fmt.Errorf("Error initializing compute client: %s", err)
		state.Put("error", err)
		return multistep.ActionHalt
	}

	ui.Say("Discovering enabled extensions...")
	result := make(map[string]struct{}, 15)
	pager := extensions.List(client)
	err = pager.EachPage(func(p pagination.Page) (bool, error) {
		// Extract the extensions from this page
		exts, err := extensions.ExtractExtensions(p)
		if err != nil {
			return false, err
		}

		for _, ext := range exts {
			log.Printf("[DEBUG] Discovered extension: %s", ext.Alias)
			result[ext.Alias] = struct{}{}
		}

		return true, nil
	})
	if err != nil {
		err = fmt.Errorf("Error loading extensions: %s", err)
		state.Put("error", err)
		return multistep.ActionHalt
	}

	state.Put("extensions", result)
	return multistep.ActionContinue
}