Add "host" parameter for image pull

Also, this patch marks "repo" and "host" as "required".

This patch implements pull-down input for specifying host.
To compose the pull-down, this patch imlements
REST API and Angular service for retrieving host list.

Change-Id: Iba8f440f6d8339e1353bb64c26c25a493c874f63
Implements: blueprint image-host
This commit is contained in:
Shu Muto 2018-06-13 11:15:59 +09:00
parent 513af9dbc3
commit a2480da5d3
4 changed files with 67 additions and 6 deletions

View File

@ -267,11 +267,18 @@ def availability_zone_list(request):
def image_list(request, limit=None, marker=None, sort_key=None,
sort_dir=None, detail=True):
sort_dir=None, detail=False):
# FIXME(shu-mutou): change "detail" param to True, if it enabled.
return zunclient(request).images.list(limit, marker, sort_key,
sort_dir, False)
sort_dir, detail)
def image_create(request, **kwargs):
args, run = _cleanup_params(IMAGE_PULL_ATTRS, True, **kwargs)
return zunclient(request).images.create(**args)
def host_list(request, limit=None, marker=None, sort_key=None,
sort_dir=None, detail=False):
return zunclient(request).hosts.list(limit, marker, sort_key,
sort_dir, detail)

View File

@ -188,3 +188,19 @@ class Images(generic.View):
return rest_utils.CreatedResponse(
'/api/zun/image/%s' % new_image.uuid,
new_image.to_dict())
@urls.register
class Hosts(generic.View):
"""API for Zun Hosts"""
url_regex = r'zun/hosts/$'
@rest_utils.ajax()
def get(self, request):
"""Get a list of the Hosts for admin users.
The returned result is an object with property 'items' and each
item under this is a HOst.
"""
result = client.host_list(request)
return {'items': [change_to_id(i.to_dict()) for i in result]}

View File

@ -26,16 +26,21 @@
.factory('horizon.dashboard.container.images.actions.workflow', workflow);
workflow.$inject = [
'horizon.app.core.openstack-service-api.zun',
'horizon.framework.util.i18n.gettext'
];
function workflow(gettext) {
function workflow(zun, gettext) {
var workflow = {
init: init
};
function init(actionType, title, submitText) {
var push = Array.prototype.push;
var schema, form, model;
var hosts = [
{value: "", name: gettext("Select host that stores the image.")}
];
// schema
schema = {
@ -44,6 +49,10 @@
repo: {
title: gettext('Image'),
type: 'string'
},
host: {
title: gettext('Host'),
type: 'string'
}
}
};
@ -60,7 +69,14 @@
items: [
{
key: 'repo',
placeholder: gettext('Name of the image.')
placeholder: gettext('Name of the image.'),
required: true
},
{
key: 'host',
type: "select",
titleMap: hosts,
required: true
}
]
}
@ -69,9 +85,20 @@
]; // form
model = {
repo: ''
repo: '',
host: ''
};
// get hosts for zun
zun.getHosts().then(onGetZunHosts);
function onGetZunHosts(response) {
var hs = [];
response.data.items.forEach(function (host) {
hs.push({value: host.id, name: host.hostname});
});
push.apply(hosts, hs);
}
var config = {
title: title,
submitText: submitText,

View File

@ -28,6 +28,7 @@
var containersPath = '/api/zun/containers/';
var zunAvailabilityZonesPath = '/api/zun/availability_zones/';
var imagesPath = '/api/zun/images/';
var hostsPath = '/api/zun/hosts/';
var service = {
createContainer: createContainer,
updateContainer: updateContainer,
@ -52,7 +53,8 @@
updatePortSecurityGroup: updatePortSecurityGroup,
getZunAvailabilityZones: getZunAvailabilityZones,
pullImage: pullImage,
getImages: getImages
getImages: getImages,
getHosts: getHosts
};
return service;
@ -208,6 +210,15 @@
return apiService.get(imagesPath).error(error(msg));
}
///////////
// Hosts //
///////////
function getHosts() {
var msg = gettext('Unable to retrieve the Hosts.');
return apiService.get(hostsPath).error(error(msg));
}
function error(message) {
return function() {
toastService.add('error', message);