【问题标题】:Custom Image creation in IBM Cloud failing from COSIBM Cloud 中的自定义映像创建因 COS 失败
【发布时间】:2021-05-31 05:04:28
【问题描述】:

我正在使用 python 在 IBM Cloud 中创建自定义图像。我有一个非常简单的直接代码来创建图像,但它失败了。 根据我的说法,我正在传递所有参数的相关正确详细信息。

我仍然得到一个描述性不强的错误:

ERROR:root:Please check whether the resource you are requesting exists.
Traceback (most recent call last):
  File "/Users/deepali.mittal/GITHUB/dcoa/python/build/dmittal/virtual-env36/lib/python3.6/site-packages/ibm_cloud_sdk_core/base_service.py", line 246, in send
    response.status_code, http_response=response)
ibm_cloud_sdk_core.api_exception.ApiException: Error: Please check whether the resource you are requesting exists., Code: 400

Process finished with exit code 0

这与 COS 中的资源缺失无关。如果在 COS 中找不到图片,则会出现不同的错误。

代码:

from ibm_vpc import VpcV1 as vpc_client
from ibm_cloud_sdk_core import ApiException
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from boto3 import client as boto3_client
import logging

#logging.basicConfig(level=logging.DEBUG)

SOURCE_OBJECT_PATH = 'cos://us-south/de-images-dmittal/abc.qcow2'
RESOURCE_GROUP_ID = '1234'
OPERATING_SYSTEM = 'ubuntu-16-amd64'


def create_ssm_client():
    ssm_client = boto3_client("ssm", region_name="us-west-2")
    return ssm_client


def retrieve_ibm_config(ssm_client):
    params = ["/ibm/service-key"]
    response = ssm_client.get_parameters(Names=params, WithDecryption=True)
    try:
        api_key = response["Parameters"][0]["Value"]
    except (ValueError, IndexError):
        raise RuntimeError(
            f"Required SSM parameters not retrieved. "
            f'Required parameters are: {params}.'
        )
    return api_key


def create_authenticator(api_key):
    authenticator = IAMAuthenticator(api_key)
    return authenticator


def create_ibm_client(authenticator):
    ibm_client = vpc_client('2021-05-28', authenticator=authenticator)
    return ibm_client


def create_image_prototype():
    image_file_prototype_model = {'href': SOURCE_OBJECT_PATH}
    operating_system_identity_model = {'name': OPERATING_SYSTEM}
    resource_group_identity_model = {'id': RESOURCE_GROUP_ID}
    image_prototype_model = {
        'name': 'my-image',
        #'resource_group': resource_group_identity_model,
        'file': image_file_prototype_model,
        'operating_system': operating_system_identity_model
    }

    image_prototype = image_prototype_model
    return image_prototype


def create_image():
    ssm_client = create_ssm_client()
    api_key = retrieve_ibm_config(ssm_client)
    authenticator = create_authenticator(api_key)
    ibm_client = create_ibm_client(authenticator)
    image_prototype = create_image_prototype()
    try:
        #images = ibm_client.list_images()
        #print(vpc)
        #ibm_client.set_service_url('https://us-south.iaas.cloud.ibm.com/v1')
        response = ibm_client.create_image(image_prototype)
        print(response)
    except ApiException as e:
        print("Failed")


if __name__ == "__main__":
    create_image()

【问题讨论】:

  • list_images() 工作正常。

标签: python ibm-cloud


【解决方案1】:

问题在于 IAM 权限。修复它后,显示的错误无关紧要,所以需要时间来弄清楚

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-25
    • 1970-01-01
    • 1970-01-01
    • 2021-08-23
    • 2021-02-06
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多