How to provision OpenStack instance via API?


#1

Hello.

My name is naleeJang.

Nowadays, I develop application using manageIQ REST API. and I am testing to provision OpenStack instance via manageIQ rest api. but I can’t find REST API document about provisioning OpenStack instance api example.

My REST API is below.

curl --user admin:smartvm -X POST -H “accept:application/json” -d
’{“version” : 1.1,
“template_fields” : {“guid” : “2ecd91d8-2414-11e7-b41e-525400d8de67”},
“vm_fields” : {
“number_of_vms” : 1,
“vm_description” : “rest api test vm”,
“vm_name” : “rest_test_vm1”,
“vm_description” : “Rest API TEST”,
“placement_auto” : 0,
“cloud_tenant” : 99000000000003,
“placement_availability_zone” : 99000000000001,
“cloud_network” : 99000000000003,
“security_groups” : 99000000000004,
“instance_type” : 99000000000001,
“addr_mode” : “dhcp”,
“customization_template_id” : 99000000000007,
“customization_template_script” : “#cloud-config chpasswd: list: | root:<%= MiqPassword.decrypt(evm[:root_password]) %> expire: False”,
“schedule_type” : “immediately”,
“retirement” : 0
},
“requester” : {
“user_name” : “nalee”,
“owner_first_name” : “nalee”,
“owner_last_name” : “Jang”,
“owner_email” : "nalee999@redhat.com",
“auto_approve” : true
},
“tags” : {“network_location” : “Internal”},
“additional_values” : { },
“ems_custom_attributes” : { },
“miq_custom_attributes” : { }
}’ https://localhost:9000/api/provision_requests

I can see the following error message.
{
“error”:{
“kind”: “not_found”,
“message”: “ActiveRecord::RecordNotFound”,
“klass”: “ActiveRecord::RecordNotFound”
}
}

so I modified below api parameter.
{“version” : 1.1,
“template_fields” : {“guid” : “2ecd91d8-2414-11e7-b41e-525400d8de67”},
“vm_fields” : {
“number_of_vms” : 1,
“vm_description” : “rest api test vm”,
“vm_name” : “rest_test_vm1”,
“vm_description” : “Rest API TEST”,
“placement_auto” : 0,
“cloud_tenant” : 99000000000003,
“placement_availability_zone” : 99000000000001,
“cloud_network” : 99000000000003,
“security_groups” : 99000000000004,
“instance_type” : 99000000000001,
“addr_mode” : “dhcp”,
“customization_template_id” : 99000000000007,
“customization_template_script” : “#cloud-config chpasswd: list: | root:<%= MiqPassword.decrypt(evm[:root_password]) %> expire: False”,
“schedule_type” : “immediately”,
“retirement” : 0
},
“request” : {
“user_name” : “nalee”,
“owner_first_name” : “nalee”,
“owner_last_name” : “Jang”,
“owner_email” : "nalee999@redhat.com",
“auto_approve” : true
},
“tags” : {“network_location” : “Internal”},
“additional_values” : { },
“ems_custom_attributes” : { },
“miq_custom_attributes” : { }
}

in this case, I saw below error message.
{
“error”:{
“kind”: “internal_server_error”,
“message”: “Provision failed for the following reasons:\n’Request/First Name’ is required\n’Request/Last Name’ is required\n’Request/E-Mail’ is required”,
“klass”: “RuntimeError”
}
}

What parameters do I use for provisioning OpenStack instance?


#2

Hi @Nalee_Jang . For single an abstract openstack instance it seams to easier to use openstack API instead of MIQ. But if you want to work with MIQ features (like automation and so on) you can create service for openstack instance provisioning and then call REST API of ManageIQ for provisioning a searvice instead of Lifecycle->Provisioning. Service can be parameterized by custom dialog and this dialog can by invoked by REST query like you queries. In json body you can specify these configured for dialog parameters for provisioning like this:

{
  "name": "cloud",
  "description": "Provisioning Cloud",
  "data_type": "string",
  "display": "edit",
  "display_method_options": {},
  "required": true,
  "required_method_options": {},
  "default_value": "3",
  "values": [
    [
      3,
      "cloud.example.com"
    ]
  ],
  "values_method_options": {},
  "options": {
    "force_multi_value": false,
    "sort_by": "value"
  },
  "label": "Provisioning Cloud",
  "position": 0,
  "dynamic": true,
  "read_only": false,
  "auto_refresh": false,
  "trigger_auto_refresh": true,
  "visible": false,
  "type": "DialogFieldDropDownList",
  "resource_action": {
    "resource_type": "DialogField",
    "ae_namespace": "Cloud/VM/Operations",
    "ae_class": "Methods",
    "ae_instance": "get_openstack_clouds",
    "ae_attributes": {}
  }
},
{
  "name": "instance_type",
  "data_type": "string",
  "display": "edit",
  "display_method_options": {},
  "required": true,
  "required_method_options": {},
  "default_value": "19",
  "values": [
    [
      19,
      "t1.tiny"
    ],
    [
      13,
      "t1.small"
    ],
    [
      14,
      "t1.medium"
    ],
    [
      12,
      "t1.2medium"
    ],
    [
      27,
      "t1.large"
    ],
    [
      26,
      "t1.2large"
    ]
  ],
  "values_method_options": {},
  "options": {
    "force_multi_value": false,
    "sort_by": "none"
  },
  "label": "Select Flavor",
  "position": 2,
  "reconfigurable": true,
  "dynamic": true,
  "show_refresh_button": false,
  "load_values_on_init": true,
  "read_only": false,
  "auto_refresh": true,
  "visible": true,
  "type": "DialogFieldDropDownList",
  "resource_action": {
    "resource_type": "DialogField",
    "ae_namespace": "Cloud/VM/Operations",
    "ae_class": "Methods",
    "ae_instance": "os_instances_flavor",
    "ae_attributes": {}
  }
}

There is methods for services call:
http://manageiq.org/docs/reference/latest/api/examples/order_service