密钥对

创建密钥对

以下代码用于创建密钥对:

def create_keypair(self):

      #设置密钥对名称

      keypair_name = 'your-keypair-name'

      #设置密钥对描述

      keypair_desc = 'your-keypair-desc'

      self.assertEqual(

            type(self.client.create_keypair(keypair_name=keypair_name,

                                                             keypair_desc=keypair_desc)), 

            baidubce.bce_response.BceResponse)

导入密钥对

以下代码用于导入密钥对:

def create_keypair(self):

      #设置密钥对名称

      keypair_name = 'your-keypair-name'

      #设置密钥对描述

      keypair_desc = 'your-keypair-desc'

      #设置公钥内容

      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)

查询密钥对列表

以下代码用于查询密钥对列表:

def list_keypairs(self):

      self.assertEqual(

            type(self.client.list_keypairs()), 

            baidubce.bce_response.BceResponse)

查询密钥对详情

以下代码用于查询密钥对列表:

def get_keypair(self):

      #设置被查询密钥对id

      keypair_id = 'your-keypair-id'

      self.assertEqual(

            type(self.client.get_keypair(keypair_id=keypair_id)), 

            baidubce.bce_response.BceResponse)

绑定密钥对

以下代码用于绑定密钥对到实例:

def attach_keypair(self):

      #设置被绑定密钥对id

      keypair_id = 'your-keypair-id'

      #设置被绑定实例id,可多个

      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)

解绑密钥对

以下代码用于解绑密钥对:

def detach_keypair(self):

      #设置要解绑的密钥对id

      keypair_id = 'your-keypair-id'

      #设置要解绑的实例id,可多个

      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)

删除密钥对

以下代码用于删除密钥对:

def delete_keypair(self):

      #设置要删除的密钥对id

      keypair_id = 'your-keypair-id'

      self.assertEqual(

            type(self.client.delete_keypair(keypair_id=keypair_id)), 

            baidubce.bce_response.BceResponse)

密钥对重命名

以下代码用于密钥对重命名:

def rename_keypair(self):

      #设置要重命名的密钥对id

      keypair_id = 'your-keypair-id'

      #设置要重命名的密钥对名称

      keypair_name = 'your-keypair-name'

      self.assertEqual(

            type(self.client.rename_keypair(keypair_id=keypair_id,

                                                               keypair_name=keypair_name)), 

            baidubce.bce_response.BceResponse)

更新密钥对描述

以下代码用于更新密钥对描述:

def update_keypair(self):

      #设置要更新描述的密钥对id

      keypair_id = 'your-keypair-id'

      #设置要更新的密钥对描述

      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)