文档首页> > 开发指南> 创建裸金属服务器

创建裸金属服务器

更新时间: 2018-10-29 18:13

场景描述

创建一台携带云硬盘的裸金属服务器。

约束限制

  • 不支持文件注入功能。
  • 本接口仅支持包周期创建裸金属服务器。

涉及接口

创建裸金属服务器时,需要进行规格查询、可用分区查询、云硬盘创建等操作,涉及的接口如下:

  • 查询可用分区列表
  • 查询裸金属服务器规格信息列表
  • 查询镜像列表
  • 创建云硬盘
  • 查询虚拟私有云列表
  • 查询安全组
  • 查询子网列表
  • 创建裸金属服务器

操作步骤

  1. 查询裸金属服务器可用分区。
    • 接口相关信息

      URI格式:GET /v2/{project_id}/os-availability-zone

      详情请参考《弹性云服务器API参考》的“查询可用分区列表”章节。

    • 请求样例

      GET /v2/9c53a566cb3443ab910cf0daebca90c4/os-availability-zone

    • 响应样例
      {
          "availabilityZoneInfo": [
              {
                  "zoneState": {
                      "available": true
                  },
                  "hosts": null,
                  "zoneName": "az1.dc1"
              },
              {
                  "zoneState": {
                      "available": true
                  },
                  "hosts": null,
                  "zoneName": "vmware.az1"
              }
          ]
      }
  2. 查询裸金属服务器规格。
    • 接口相关信息

      URI格式:GET /v2/{project_id}/flavors/detail

      详情请参考《裸金属服务器API参考》的“查询裸金属服务器规格信息列表(OpenStack原生)”章节。

      说明:

      裸金属服务器的规格以“physical.”作为前缀。

    • 请求样例

      GET /v2/384627f84f384e9eb4463492be39a950/flavors/detail

    • 响应样例
      {
          "flavors": [
               "name": "physical.d1.medium",
                  "links": [
                      {
                          "href": "https://bms.cn-north-1.myhuaweicloud.com/v2/c685484a8cc2416b97260938705deb65/flavors/physical.d1.medium",
                          "rel": "self"
                      },
                      {
                          "href": "https://bms.cn-north-1.myhuaweicloud.com/c685484a8cc2416b97260938705deb65/flavors/physical.d1.medium",
                          "rel": "bookmark"
                      }
                  ],
                  "ram": 321725,
                  "OS-FLV-DISABLED:disabled": false,
                  "vcpus": 56,
                  "swap": "",
                  "os-flavor-access:is_public": true,
                  "rxtx_factor": 1,
                  "OS-FLV-EXT-DATA:ephemeral": 0,
                  "disk": 3725,
                  "id": "physical.d1.medium"
          ]
      }
  3. 查询镜像列表。
    • 接口相关信息

      URI格式:GET /v2/images

      详情请参考《镜像服务API参考》的“查询镜像列表(OpenStack原生)”章节。

    • 请求样例

      GET /v2/images

    • 响应样例
      { 
          "images": [
              {
                  "status": "queued", 
                  "name": "test", 
                  "tags": [
                      "test",
                      "image"
                  ], 
                  "container_format": "bare", 
                  "created_at": "2014-12-16T01:22:05Z", 
                  "disk_format": "qcow2", 
                  "updated_at": "2014-12-16T01:22:05Z", 
                  "visibility": "private", 
                  "self": "/v2/images/4ca46bf1-5c61-48ff-b4f3-0ad4e5e3ba90", 
                  "min_disk": 1, 
                  "protected": false, 
                  "id": "4ca46bf1-5c61-48ff-b4f3-0ad4e5e3ba90", 
                  "file": "/v2/images/4ca46bf1-5c61-48ff-b4f3-0ad4e5e3ba90/file", 
                  "owner": "aed2c611711548a4a9c16fb8fe166af4", 
                  "min_ram": 1024, 
                  "schema": "/v2/schemas/image" 
              }, 
              { 
                  "status": "active", 
                  "name": "cirros", 
                  "tags": [
                      "new"
                  ], 
                  "container_format": "bare", 
                  "created_at": "2014-12-11T03:53:43Z", 
                  "size": 13147648, 
                  "disk_format": "qcow2", 
                  "updated_at": "2014-12-15T20:02:12Z", 
                  "visibility": "private", 
                  "self": "/v2/images/5155a22a-834e-4ffe-a95d-ed9665a8ed76", 
                  "min_disk": 0, 
                  "protected": false, 
                  "id": "5155a22a-834e-4ffe-a95d-ed9665a8ed76", 
                  "file": "/v2/images/5155a22a-834e-4ffe-a95d-ed9665a8ed76/file", 
                  "checksum": "d972013792949d0d3ba628fbe8685bce", 
                  "owner": "aed2c611711548a4a9c16fb8fe166af4", 
                  "min_ram": 0, 
                  "schema": "/v2/schemas/image" 
              } 
          ], 
          "schema": "/v2/schemas/images", 
          "first": "/v2/images" 
      }
  4. 创建云硬盘。
    • 接口相关信息

      URI格式:POST /v2/{project_id}/volumes

      详情请参考《云硬盘API参考》的“创建云硬盘”章节。

    • 请求样例

      POST /v2/9c53a566cb3443ab910cf0daebca90c4/volumes

      {
          "volume": {
              "name": "openapi_vol01", 
              "imageRef": "027cf713-45a6-45f0-ac1b-0ccc57ac12e2", 
              "availability_zone": "xxx", 
              "description": "create for api test", 
              "volume_type": "SATA", 
              "metadata": {
                  "volume_owner": "openapi"
              }, 
              "consistencygroup_id": null, 
              "OS-SCH-HNT:scheduler_hints": {
                  "dedicated_storage_id": "eddc1a3e-4145-45be-98d7-bf6f65af9767"
              }, 
              "source_volid": null, 
              "snapshot_id": null, 
              "shareable": "false", 
              "multiattach": false, 
              "source_replica": null, 
              "size": 40
          }
      }
    • 响应样例
      {
          "volume": {
              "attachments": [ ], 
              "availability_zone": "xxx", 
              "bootable": "false", 
              "consistencygroup_id": null, 
              "created_at": "2016-05-25T02:38:40.392463", 
              "description": "create for api test", 
              "encrypted": false, 
              "id": "8dd7c486-8e9f-49fe-bceb-26aa7e312b66", 
              "links": [
                  {
                      "href": "https://volume.localdomain.com:8776/v2/5dd0b0056f3d47b6ab4121667d35621a/volumes/8dd7c486-8e9f-49fe-bceb-26aa7e312b66",
                      "rel": "self"
                  }, 
                  {
                      "href": "https://volume.localdomain.com:8776/5dd0b0056f3d47b6ab4121667d35621a/volumes/8dd7c486-8e9f-49fe-bceb-26aa7e312b66",
                      "rel": "bookmark"
                  }
              ], 
              "metadata": {
                  "volume_owner": "openapi"
              }, 
              "name": "openapi_vol01",
              "replication_status": "disabled", 
              "shareable": false, 
              "multiattach": false, 
              "size": 40, 
              "snapshot_id": null, 
              "source_volid": null, 
              "status": "creating", 
              "updated_at": null, 
              "user_id": "39f6696ae23740708d0f358a253c2637", 
              "volume_type": "SATA"
          }
      }

      {
          "error": {
              "message": "XXXX", 
              "code": "XXX"
          }
      }

      其中error是泛指的错误,有badRequest、itemNotFound等,如报错为:

      {
          "badRequest": {
              "message": "XXXX", 
              "code": "XXX"
          }
      }
  5. 查询虚拟私有云列表。
    • 接口相关信息

      URI格式:GET /v1/{project_id}/vpcs

      详情请参考《虚拟私有云API参考》的“查询VPC列表”章节。

    • 请求样例

      GET /v1/000efdc5f9064584b718b181df137bd7/vpcs

    • 响应样例
      {    
          "vpcs": [
              {
                  "id": "13551d6b-755d-4757-b956-536f674975c0",
                  "name": "default",
                  "cidr": "172.16.0.0/16",
                  "status": "OK",
                  "routes": null
              },
              {
                  "id": "3ec3b33f-ac1c-4630-ad1c-7dba1ed79d85",
                  "name": "222",
                  "cidr": "192.168.0.0/16",
                  "status": "OK",
                  "routes": null
              },
              {
                  "id": "99d9d709-8478-4b46-9f3f-2206b1023fd3",
                  "name": "vpc",
                  "cidr": "192.168.0.0/16",
                  "status": "OK",
                  "routes": null
              }
          ]
      }
  6. 查询安全组。
    • 接口相关信息

      URI格式:GET /v2.0/security-groups

      详情请参考《虚拟私有云API参考》的“查询安全组”章节。

    • 请求样例

      GET /v2.0/security-groups

    • 响应样例
      {
          "security_groups": [
              {
                  "tenant_id": "84b25ac10ed642cca484aa55c098e3aa", 
                  "name": "default", 
                  "description": "Default security group", 
                  "security_group_rules": [
                      {
                          "remote_group_id": "1d8b19c7-7c56-48f7-a99b-4b40eb390967", 
                          "direction": "ingress", 
                          "remote_ip_prefix": null, 
                          "protocol": null, 
                          "ethertype": "IPv6", 
                          "tenant_id": "84b25ac10ed642cca484aa55c098e3aa", 
                          "port_range_max": null, 
                          "port_range_min": null, 
                          "id": "07adc044-3f21-4eeb-bd57-5e5eb6024b7f", 
                          "description": null, 
                          "security_group_id": "1d8b19c7-7c56-48f7-a99b-4b40eb390967"
                      }, 
                      {
                          "remote_group_id": null, 
                          "direction": "egress", 
                          "remote_ip_prefix": null, 
                          "protocol": null, 
                          "ethertype": "IPv6", 
                          "tenant_id": "84b25ac10ed642cca484aa55c098e3aa", 
                          "port_range_max": null, 
                          "port_range_min": null, 
                          "id": "47e05c14-1aa2-4355-aaf8-b57e18f98c9a", 
                          "description": null, 
                          "security_group_id": "1d8b19c7-7c56-48f7-a99b-4b40eb390967"
                      }, 
                      {
                          "remote_group_id": null, 
                          "direction": "egress", 
                          "remote_ip_prefix": null, 
                          "protocol": null, 
                          "ethertype": "IPv4", 
                          "tenant_id": "84b25ac10ed642cca484aa55c098e3aa", 
                          "port_range_max": null, 
                          "port_range_min": null, 
                          "id": "8a8a238b-fdb1-4321-b667-26205c7f37d1", 
                          "description": null, 
                          "security_group_id": "1d8b19c7-7c56-48f7-a99b-4b40eb390967"
                      }, 
                      {
                          "remote_group_id": "1d8b19c7-7c56-48f7-a99b-4b40eb390967", 
                          "direction": "ingress", 
                          "remote_ip_prefix": null, 
                          "protocol": null, 
                          "ethertype": "IPv4", 
                          "tenant_id": "84b25ac10ed642cca484aa55c098e3aa", 
                          "port_range_max": null, 
                          "port_range_min": null, 
                          "id": "b5874440-84a0-4382-8e37-3f012b90b71e", 
                          "description": null, 
                          "security_group_id": "1d8b19c7-7c56-48f7-a99b-4b40eb390967"
                      }
                  ], 
                  "id": "1d8b19c7-7c56-48f7-a99b-4b40eb390967"
              }
          ]
      }
  7. 查询子网列表。
    • 接口相关信息

      URI格式:GET /v1/{project_id}/subnets

      详情请参考《虚拟私有云API参考》的“查询子网列表”章节。

    • 请求样例

      GET /v1/000efdc5f9064584b718b181df137bd7/subnets

    • 响应样例
      {
          "subnets": [
              {
                  "id": "4779ab1c-7c1a-44b1-a02e-93dfc361b32d",
                  "name": "subnet",
                  "cidr": "192.168.20.0/24",
                  "dnsList": [
                      "114.114.114.114",
                      "114.114.115.115"
                  ],
                  "status": "ACTIVE",
                  "vpc_id": "3ec3b33f-ac1c-4630-ad1c-7dba1ed79d85",
                  "gateway_ip": "192.168.20.1",
                  "dhcp_enable": true,
                  "primary_dns": "114.114.114.114",
                  "secondary_dns": "114.114.115.115",
                  "availability_zone": "aa-bb-cc"  //假设可用分区名称为aa-bb-cc
                  "neutron_network_id": "4779ab1c-7c1a-44b1-a02e-93dfc361b32d",
                  "neutron_subnet_id": "213cb9d-3122-2ac1-1a29-91ffc1231a12"
              },
              {
                  "id": "531dec0f-3116-411b-a21b-e612e42349fd",
                  "name": "Subnet1",
                  "cidr": "192.168.1.0/24",
                  "dnsList": [
                      "114.114.114.114",
                      "114.114.115.115"
                  ],
                  "status": "ACTIVE",
                  "vpc_id": "3ec3b33f-ac1c-4630-ad1c-7dba1ed79d85",
                  "gateway_ip": "192.168.1.1",
                  "dhcp_enable": true,
                  "primary_dns": "114.114.114.114",
                  "secondary_dns": "114.114.115.115",
                  "availability_zone": "aa-bb-cc"  //假设可用分区名称为aa-bb-cc
                  "neutron_network_id": "531dec0f-3116-411b-a21b-e612e42349fd",
                  "neutron_subnet_id": "1aac193-a2ad-f153-d122-12d64c2c1d78"
              }
          ]
      }
  8. 创建裸金属服务器。
    • 前提条件

      必选参数:name、imageRef、flavorRef、networks、availability_zone

      非必选参数:root_volume、data_volumes、security_groups

    • 接口相关信息

      URI格式:POST /v1/{project_id}/baremetalservers

      详情请参考《裸金属服务器API参考》的“创建裸金属服务器”章节。

    • 请求样例

      POST /v1/000efdc5f9064584b718b181df137bd7/baremetalservers

      {
          "server": {
              "imageRef": "1a6635d8-afea-4f2b-abb6-27a202bad319",
              "flavorRef": "physical.d1.medium",
              "data_volumes": [
                  {
                      "volumetype": "SATA",
                      "size": 40,
                      "shareable": false,
                      "extendparam": {
                         "resourceSpecCode": "",
                         "resourceType": ""
                      }
                  }
              ],
              "name": "bms_name01",
              "availability_zone": "az01",
              "networks": [
                  {
                      "uuid": "8470310b-bfa2-4edf-8f64-d15196b2b2c9"
                  }
              ]
          }
      }
    • 响应样例
      {
          "server": {
              "security_groups": [
                  {
                      "name": "default"
                  }
              ],
              "OS-DCF:diskConfig": "MANUAL",
              "os-extended-volumes:volumes_attached": [
                  {
                      "id": "dc5b02ea-bece-4ec8-b194-f39db96406c8",
                      "delete_on_termination": false
                  }
              ],
              "links": [
                  {
                      "rel": "self",
                      "href": "https://ecs.cn-north-1.myhuaweicloud.com/v2/c685484a8cc2416b97260938705deb65/servers/9ab74d89-61e7-4259-8546-465fdebe4944"
                  },
                  {
                      "rel": "bookmark",
                      "href": "https://ecs.cn-north-1.myhuaweicloud.com/c685484a8cc2416b97260938705deb65/servers/9ab74d89-61e7-4259-8546-465fdebe4944"
                  }
              ],
              "id": "9ab74d89-61e7-4259-8546-465fdebe4944",
              "adminPass": "RjdD3h8U2DBe"
          }
      }

文档是否有解决您的问题?

提交成功!

非常感谢您的反馈,我们会继续努力做到更好!

反馈提交失败,请稍后再试!

在文档使用中是否遇到以下问题







请至少选择或填写一项反馈信息

字符长度不能超过100

反馈内容不能为空!

提交反馈 取消

如您有其它疑问,您也可以通过华为云社区问答频道来与我们联系探讨

跳转到云社区
点我,12·12惊喜等着你哦~