Key Pair
Last Updated:2020-07-20
Create a Key Pair
The following code is used to create a key pair:
def create_keypair(self):
#Set a Keypair name
keypair_name = 'your-keypair-name'
# Set key descriptions
keypair_desc = 'your-keypair-desc'
self.assertEqual(
type(self.client.create_keypair(keypair_name=keypair_name,keypair_desc=keypair_desc)),
baidubce.bce_response.BceResponse)
Import a Key Pair
The following code is used to import a key pair:
def create_keypair(self):
# Set a Keypair name
keypair_name = 'your-keypair-name'
# Set key descriptions
keypair_desc = 'your-keypair-desc'
# Set public key contents
public_key = 'your-public-key'
self.assertEqual(
type(self.client.import_keypair(keypair_name=keypair_name,
keypair_desc=keypair_desc,
public_key=public_key)),
baidubce.bce_response.BceResponse)
Query the Key Pair List
The following code is used to query the key pair list:
def list_keypairs(self):
self.assertEqual(
type(self.client.list_keypairs()),
baidubce.bce_response.BceResponse)
Query the Key Pair Details
The following code is used to query the key pair list:
def get_keypair(self):
# Set a keypair id to be queried
keypair_id = 'your-keypair-id'
self.assertEqual(
type(self.client.get_keypair(keypair_id=keypair_id)),
baidubce.bce_response.BceResponse)
Bind a Key Pair
The following code is used to bind the key pair to the instance:
def attach_keypair(self):
# Set a keypair id to be blinded
keypair_id = 'your-keypair-id'
# Set an instance id to be blinded, you can set multi-instance ids.
instance_ids = ['your-instance-id1', 'your-instance-id2']
self.assertEqual(
type(self.client.attach_keypair(keypair_id=keypair_id,instance_ids=instance_ids)),
baidubce.bce_response.BceResponse)
Unbind a Key Pair
The following code is used to unbind the key pair:
def detach_keypair(self):
# Set a keypair id to be unblinded
keypair_id = 'your-keypair-id'
# Set an instance id to be unblinded, you can set multi-instance ids.
instance_ids = ['your-instance-id1', 'your-instance-id2']
self.assertEqual(
type(self.client.detach_keypair(keypair_id=keypair_id,instance_ids=instance_ids)),
baidubce.bce_response.BceResponse)
Delete a Key Pair
The following code is used to delete a key pair:
def delete_keypair(self):
# Set a keypair id to be deleted
keypair_id = 'your-keypair-id'
self.assertEqual(
type(self.client.delete_keypair(keypair_id=keypair_id)),
baidubce.bce_response.BceResponse)
Rename a Key Pair
The following code is used to rename a key pair:
def rename_keypair(self):
# Set a keypair id to be renamed
keypair_id = 'your-keypair-id'
# Set a keypair name to be renamed
keypair_name = 'your-keypair-name'
self.assertEqual(
type(self.client.rename_keypair(keypair_id=keypair_id,keypair_name=keypair_name)),
baidubce.bce_response.BceResponse)
Update the Key Pair Description
The following code is used to update the key pair description:
def update_keypair(self):
# Set the key pair id to update the description
keypair_id = 'your-keypair-id'
# Set the description of the key pair to be updated
keypair_desc = 'your-keypair-desc'
self.assertEqual(
type(self.client.update_keypair_desc(keypair_id=keypair_id,keypair_desc=keypair_desc)),
baidubce.bce_response.BceResponse)