當前位置: 首頁>>代碼示例>>Golang>>正文


Golang keypairs.Delete函數代碼示例

本文整理匯總了Golang中github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs.Delete函數的典型用法代碼示例。如果您正苦於以下問題:Golang Delete函數的具體用法?Golang Delete怎麽用?Golang Delete使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Delete函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Cleanup

func (s *StepKeyPair) Cleanup(state multistep.StateBag) {
	// If we used an SSH private key file, do not go about deleting
	// keypairs
	if s.PrivateKeyFile != "" {
		return
	}
	// If no key name is set, then we never created it, so just return
	if s.keyName == "" {
		return
	}

	config := state.Get("config").(Config)
	ui := state.Get("ui").(packer.Ui)

	// We need the v2 compute client
	computeClient, err := config.computeV2Client()
	if err != nil {
		ui.Error(fmt.Sprintf(
			"Error cleaning up keypair. Please delete the key manually: %s", s.keyName))
		return
	}

	ui.Say("Deleting temporary keypair...")
	err = keypairs.Delete(computeClient, s.keyName).ExtractErr()
	if err != nil {
		ui.Error(fmt.Sprintf(
			"Error cleaning up keypair. Please delete the key manually: %s", s.keyName))
	}
}
開發者ID:rodm,項目名稱:packer,代碼行數:29,代碼來源:step_key_pair.go

示例2: TestCreateServerWithKeyPair

func TestCreateServerWithKeyPair(t *testing.T) {
	client, err := newClient()
	th.AssertNoErr(t, err)

	if testing.Short() {
		t.Skip("Skipping test that requires server creation in short mode.")
	}

	privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
	publicKey := privateKey.PublicKey
	pub, err := ssh.NewPublicKey(&publicKey)
	th.AssertNoErr(t, err)
	pubBytes := ssh.MarshalAuthorizedKey(pub)
	pk := string(pubBytes)

	kp, err := keypairs.Create(client, keypairs.CreateOpts{
		Name:      keyName,
		PublicKey: pk,
	}).Extract()
	th.AssertNoErr(t, err)
	t.Logf("Created key pair: %s\n", kp)

	choices, err := ComputeChoicesFromEnv()
	th.AssertNoErr(t, err)

	name := tools.RandomString("Gophercloud-", 8)
	t.Logf("Creating server [%s] with key pair.", name)

	serverCreateOpts := servers.CreateOpts{
		Name:      name,
		FlavorRef: choices.FlavorID,
		ImageRef:  choices.ImageID,
	}

	server, err := servers.Create(client, keypairs.CreateOptsExt{
		serverCreateOpts,
		keyName,
	}).Extract()
	th.AssertNoErr(t, err)
	defer servers.Delete(client, server.ID)
	if err = waitForStatus(client, server, "ACTIVE"); err != nil {
		t.Fatalf("Unable to wait for server: %v", err)
	}

	server, err = servers.Get(client, server.ID).Extract()
	t.Logf("Created server: %+v\n", server)
	th.AssertNoErr(t, err)
	th.AssertEquals(t, server.KeyName, keyName)

	t.Logf("Deleting key pair [%s]...", kp.Name)
	err = keypairs.Delete(client, keyName).ExtractErr()
	th.AssertNoErr(t, err)

	t.Logf("Deleting server [%s]...", name)
}
開發者ID:cdosso,項目名稱:machine,代碼行數:55,代碼來源:keypairs_test.go

示例3: resourceComputeKeypairV2Delete

func resourceComputeKeypairV2Delete(d *schema.ResourceData, meta interface{}) error {
	config := meta.(*Config)
	computeClient, err := config.computeV2Client(d.Get("region").(string))
	if err != nil {
		return fmt.Errorf("Error creating OpenStack compute client: %s", err)
	}

	err = keypairs.Delete(computeClient, d.Id()).ExtractErr()
	if err != nil {
		return fmt.Errorf("Error deleting OpenStack keypair: %s", err)
	}
	d.SetId("")
	return nil
}
開發者ID:pyhrus,項目名稱:terraform,代碼行數:14,代碼來源:resource_openstack_compute_keypair_v2.go

示例4: resourceComputeKeypairDelete

func resourceComputeKeypairDelete(d *schema.ResourceData, meta interface{}) error {
	computeClient, err := meta.(*Config).computeClient()
	if err != nil {
		return fmt.Errorf("Error creating ConoHa compute client: %s", err)
	}

	err = keypairs.Delete(computeClient, d.Id()).ExtractErr()
	if err != nil {
		return fmt.Errorf("Error deleting ConoHa keypair: %s", err)
	}

	d.SetId("")

	return nil
}
開發者ID:hanazuki,項目名稱:terraform-provider-conoha,代碼行數:15,代碼來源:resource_compute_keypair.go

示例5: DeleteKeyPair

func (c *GenericClient) DeleteKeyPair(d *Driver, name string) error {
	if result := keypairs.Delete(c.Compute, name); result.Err != nil {
		return result.Err
	}
	return nil
}
開發者ID:rhendric,項目名稱:machine,代碼行數:6,代碼來源:client.go

示例6: Delete

// Delete requests the deletion of a previous stored KeyPair from the server.
func Delete(client *gophercloud.ServiceClient, name string) os.DeleteResult {
	return os.Delete(client, name)
}
開發者ID:Clarifai,項目名稱:kubernetes,代碼行數:4,代碼來源:delegate.go


注:本文中的github.com/rackspace/gophercloud/openstack/compute/v2/extensions/keypairs.Delete函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。