【问题标题】:List file shares on AWS Storage Gateway with boto3使用 boto3 列出 AWS Storage Gateway 上的文件共享
【发布时间】:2022-01-26 00:22:18
【问题描述】:

我正在尝试列出特定存储网关上的所有文件共享,如下所示:

import boto3

sg = boto3.client('storagegateway', 'us-east-1')
aws = sg.list_file_shares(
    GatewayARN = "arn:aws:storagegateway:us-east-1:........."
)
for fileshare in aws:
    print(
    "Id: {0}\nFileShareType: {1}\nFileShareARN: {2}\nFileShareId: {3}\nFileShareStatus".format(
    FileShareInfolist[fileshareType], fileshare.FileShareARN, fileshare.FileShareId, fileshare.FileShareStatus
    )

我不知道如何获得我需要的信息。请帮忙。

【问题讨论】:

  • 您是说代码产生错误(如果有,请出示)? “您需要的信息”是什么?你的实际问题是什么?
  • 我需要显示以下信息:fileshare.FileShareARN、fileshare.FileShareId、fileshare.FileShareStatus 显示为每个共享的列

标签: amazon-web-services amazon-ec2 boto3 aws-storage-gateway


【解决方案1】:

list_file_shares() API 调用返回:

{
    'Marker': 'string',
    'NextMarker': 'string',
    'FileShareInfoList': [
        {
            'FileShareType': 'NFS'|'SMB',
            'FileShareARN': 'string',
            'FileShareId': 'string',
            'FileShareStatus': 'string',
            'GatewayARN': 'string'
        },
    ]
}

因此,您的代码将类似于:

import boto3

sg_client = boto3.client('storagegateway', 'us-east-1')
response = sg_client.list_file_shares(GatewayARN = "arn:aws:storagegateway:us-east-1:.........")

for fileshare in response['FileShareInfoList']:
    print(
        "Id: {0}\nFileShareType: {1}\nFileShareARN: {2}\nFileShareId: {3}\nFileShareStatus".format(
        fileshare['FileShareType'], fileshare['FileShareARN'], fileshare['FileShareId'], fileshare['FileShareStatus']
        )
    )

【讨论】:

  • 谢谢。知道如何将其格式化为列而不是行吗?
  • ``` Id: NFS FileShareType: arn:aws:storagegateway:us-east-1:145429107744:share/share-6E229805 FileShareARN: share-6E229805 FileShareId: AVAILABLE FileShareStatus ```
  • 输出没有任何想法
  • “在列中格式化”是什么意思?只是在不同的行上?
猜你喜欢
  • 2019-02-18
  • 2014-11-14
  • 1970-01-01
  • 2016-10-29
  • 1970-01-01
  • 2018-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多