登录
首页 >  Golang >  Go问答

在Azure中使用API或SDK上传模板

来源:stackoverflow

时间:2024-03-02 20:21:23 206浏览 收藏

积累知识,胜过积蓄金银!毕竟在Golang开发的过程中,会遇到各种各样的问题,往往都是一些细节知识点还没有掌握好而导致的,因此基础知识点的积累是很重要的。下面本文《在Azure中使用API或SDK上传模板》,就带大家讲解一下知识点,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~

问题内容

我希望使用 Go SDK 或 Rest API 以编程方式在 Azure 中上传 VM 部署模板。我无法找到相同的正确文档。

此外,我不想启动虚拟机部署。仅限将部署模板上传到Azure。


解决方案


下面是将空模板放入门户的示例 api 请求:

{
    "name": "test",
    "type": "microsoft.gallery/myareas/galleryitems",
    "properties": {
        "publishername": "username_goes_here",
        "publisherdisplayname": "username_goes_here",
        "displayname": "test",
        "description": "test",
        "artifacts": {
            "default": {
                "name": "template",
                "type": "template",
                "uri": "https://gallery.azure.com/artifact/20161101/microsoft.mygallery.0.0.9-preview/deploymenttemplates/emptytemplate.json"
            }
        },
        "images": [
            {
                "context": "ibiza",
                "items": [
                    {
                        "name": "large",
                        "type": "icon",
                        "uri": "https://gallery.azure.com/galleryrp/content/galleryitemdefaultlargeicon.png"
                    }
                ]
            }
        ],
        "version": "1.0.0",
        "uidefinitionuri": "",
        "publishingstate": "stable",
        "categoryids": [],
        "links": []
    }
}

输入:https://management.azure.com/providers/Microsoft.Gallery/myareas/df010a79-26a3-401a-8697-a5736c82895a/galleryItems/test?api-version=2016-03-01-preview

不确定从哪里获取 guid,可能必须手动创建第一个 guid,或者对 myareas 的获取请求可能会显示可能区域的列表

不幸的是,我没有在任何地方的 api 中看到此记录。

编辑:我能够找到提供者的操作列表:

{
    "namespace": "Microsoft.Gallery",
    "resourceTypes": [
        {
            "resourceType": "myareas",
            "locations": "",
            "apiVersions": "2016-03-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "myareas/areas",
            "locations": "",
            "apiVersions": "2016-03-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "myareas/areas/areas",
            "locations": "",
            "apiVersions": "2016-03-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "myareas/galleryitems",
            "locations": "",
            "apiVersions": "2016-03-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "myareas/areas/galleryitems",
            "locations": "",
            "apiVersions": "2016-03-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "myareas/areas/areas/galleryitems",
            "locations": "",
            "apiVersions": "2016-03-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "enroll",
            "locations": "",
            "apiVersions": "2016-03-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "register",
            "locations": "",
            "apiVersions": "2016-03-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "galleryitems",
            "locations": "",
            "apiVersions": "2016-03-01-preview 2014-04-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "resources",
            "locations": "",
            "apiVersions": "2016-03-01-preview 2014-04-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "retrieveresourcesbyid",
            "locations": "",
            "apiVersions": "2016-03-01-preview 2014-04-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "generateartifactaccessuri",
            "locations": "",
            "apiVersions": "2016-03-01-preview",
            "capabilities": "None"
        },
        {
            "resourceType": "checknameavailability",
            "locations": "",
            "apiVersions": "2016-03-01-preview",
            "capabilities": "None"
        }
    ]
}

所以我不认为它是 ui 代理。它似乎是一个真正的提供商,但它似乎位于租户级别或其他什么?请注意 url:https://management.azure.com/providers

编辑:是的,我可以通过此调用获取我的区域列表:https://management.azure.com/providers/microsoft.gallery/myareas/?api-version=2020-01-01

它将返回我迄今为止唯一的区域:df010a79-26a3-401a-8697-a5736c82895a

今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>