Skip to content
Browse files

Integrate appliances more closely with LCs

  • Loading branch information...
1 parent 76a7b2f commit 203c505ef212f958e947ba8564e6e7c96e23a6d7 @oldpatricka oldpatricka committed Oct 11, 2013
View
9 phantomweb/api/dev.py
@@ -564,6 +564,7 @@ def launchconfigurations(request):
user_data = content.get('user_data')
chef_runlist = content.get('chef_runlist')
chef_attributes = content.get('chef_attributes')
+ appliance = content.get('appliance')
if (contextualization_method is 'none' and
(user_data, chef_runlist, chef_attributes) is not (None, None, None)):
@@ -584,15 +585,16 @@ def launchconfigurations(request):
'contextualization_method': contextualization_method,
'user_data': user_data,
'chef_runlist': chef_runlist,
- 'chef_attributes': chef_attributes
+ 'chef_attributes': chef_attributes,
}
- lc = create_launch_configuration(username, name, cloud_params, context_params)
+ lc = create_launch_configuration(username, name, cloud_params, context_params, appliance)
response_dict = {
"id": lc.id,
"name": name,
"owner": username,
+ 'appliance': appliance,
'contextualization_method': contextualization_method,
"cloud_params": cloud_params,
"uri": "/api/%s/launchconfigurations/%s" % (API_VERSION, lc.id),
@@ -651,6 +653,7 @@ def launchconfiguration_resource(request, id):
user_data = content.get('user_data')
chef_runlist = content.get('chef_runlist')
chef_attributes = content.get('chef_attributes')
+ appliance = content.get('appliance')
if (contextualization_method is 'none' and
(user_data, chef_runlist, chef_attributes) is not (None, None, None)):
@@ -674,7 +677,7 @@ def launchconfiguration_resource(request, id):
'chef_attributes': content.get('chef_attributes')
}
- response_dict = update_launch_configuration(lc.id, cloud_params, context_params)
+ response_dict = update_launch_configuration(lc.id, cloud_params, context_params, appliance)
response_dict['uri'] = "/api/%s/launchconfigurations/%s" % (API_VERSION, lc.id)
response_dict['contextualization_method'] = contextualization_method
View
128 phantomweb/static/js/phantom_lc.js
@@ -1,3 +1,4 @@
+var g_appliances = {};
var g_cloud_map = {};
var g_arranged_cloud_values = {};
var g_lc_info = {};
@@ -16,6 +17,19 @@ $(document).ready(function() {
return false;
});
+ $("a[rel='popover']").on('click', function(e) {e.preventDefault(); return true;});
+
+ $("#phantom_lc_appliance").change(function() {
+ var appliance_name = $(this).val();
+ if (appliance_name) {
+ load_appliance(appliance_name);
+ phantom_lc_change_lc_internal(g_selected_lc);
+ }
+ else {
+ unload_appliance();
+ }
+ });
+
$("#cloud_table_body").on('click', 'tr', function(event){
$(this).parent().children().removeClass("info");
var cloud_name = $(this).children().first().text();
@@ -155,6 +169,29 @@ function select_contextualization_method(context_type) {
}
+function load_appliance(appliance_name) {
+ $phantom_lc_appliance_choice = $("#phantom_lc_appliance_choice");
+ $phantom_lc_appliance_choice.text(appliance_name);
+ $phantom_lc_appliance_choice.parent().show();
+ $("#phantom_lc_common_image_input").parent().hide();
+ $("#phantom_lc_user_images_choices").parent().hide();
+ g_selected_appliance = appliance_name;
+
+ var appliance = g_appliances[appliance_name];
+ g_lc_info[g_selected_lc]['cloud_params'] = appliance['cloud_params'];
+ g_lc_info[g_selected_lc]['appliance'] = appliance_name;
+}
+
+function unload_appliance() {
+ $("#phantom_lc_appliance_choice").parent().hide();
+ $("#phantom_lc_common_image_input").parent().show();
+ $("#phantom_lc_user_images_choices").parent().show();
+ g_selected_appliance = null;
+ if ('appliance' in g_lc_info[g_selected_lc]) {
+ delete g_lc_info[g_selected_lc]['appliance'];
+ }
+}
+
function phantom_lc_buttons(enabled) {
if (enabled) {
@@ -334,7 +371,16 @@ function phantom_lc_change_lc_internal(lc_name) {
if (g_arranged_cloud_values === undefined) {
g_arranged_cloud_values = {};
}
-
+
+ if ('appliance' in lc) {
+ $("#phantom_lc_appliance").val(lc['appliance']);
+ load_appliance(lc['appliance']);
+ }
+ else {
+ $("#phantom_lc_appliance").val('');
+ unload_appliance();
+ }
+
if (! ('contextualization_method' in lc)) {
$("#phantom_lc_userdata").val(lc['user_data']);
@@ -486,6 +532,66 @@ function phantom_lc_load_internal() {
}
}
+ var load_appliances_success = function(appliances) {
+ try {
+ g_appliances = {};
+ $("#phantom_lc_appliance").empty()
+ .append("<option></option>");
+
+ for(var i=0; i<appliances.length; i++) {
+ var appliance = appliances[i];
+ g_appliances[appliance.name] = appliance;
+ $("#phantom_lc_appliance")
+ .append("<option>" + appliance.name + "</option>");
+ }
+
+
+ /*$("#phantom_lc_name_select").empty();
+ $("#phantom_lc_cloud").empty();
+ g_lc_info = {};
+ for(var i=0; i<launchconfigs.length; i++) {
+ var launchconfig = launchconfigs[i];
+ g_lc_info[launchconfig.name] = launchconfig;
+ }
+
+ phantom_lc_load_lc_names();
+ phantom_lc_load_cloud_names();
+ var cloud_name = g_selected_cloud;
+ phantom_lc_select_new_cloud_internal(cloud_name);
+ phantom_lc_change_image_type();
+
+ var lc_name_from_saved = $("#phantom_lc_name_input").val();
+ if (lc_name_from_saved) {
+ // if it was a saved name load up its value
+ $("#phantom_lc_name_select").val(lc_name_from_saved);
+ }
+
+ if (g_selected_lc === null) {
+ var url_lc = get_hash_lc();
+ var first_lc = $("a.launch_config").first().text();
+
+ if (g_lc_info.hasOwnProperty(url_lc)) {
+ g_selected_lc = url_lc;
+ phantom_lc_load_lc_names();
+ }
+ else if (first_lc) {
+ g_selected_lc = first_lc;
+ phantom_lc_load_lc_names();
+ }
+ else {
+ $("#phantom_lc_info_area").hide();
+ $("#phantom_lc_order_area").hide();
+ }
+ }
+
+ phantom_lc_buttons(true);*/
+ }
+ catch (err) {
+ phantom_alert("There was a problem loading the page. Please try again later. ".concat(err.message));
+ $('#loading').hide();
+ }
+ }
+
var credentials_url = make_url('credentials/sites')
var cred_request = phantomGET(credentials_url);
@@ -495,14 +601,18 @@ function phantom_lc_load_internal() {
var lc_url = make_url('launchconfigurations')
var lc_request = phantomGET(lc_url);
+ var appliances_url = make_url('launchconfigurations?public=true')
+ var appliances_request = phantomGET(appliances_url);
+
phantom_lc_buttons(false);
phantom_info("Loading Launch Configurations");
- $.when(cred_request, sites_request, lc_request)
- .done(function(credentials, sites, lcs) {
+ $.when(cred_request, sites_request, lc_request, appliances_request)
+ .done(function(credentials, sites, lcs, appliances) {
load_sites_success(sites[0]);
load_credentials_success(credentials[0]);
load_lc_success(lcs[0]);
+ load_appliances_success(appliances[0]);
})
.fail(function(err) {
phantom_alert("There was a problem loading your launch configs. Please try again later. ".concat(err.message));
@@ -531,6 +641,11 @@ function save_lc_values() {
var chef_runlist = $("#phantom_lc_chef_runlist").val();
var chef_attributes = $("#phantom_lc_chef_attributes").val();
var user_data = $("#phantom_lc_userdata").val();
+ var appliance_name = $("#phantom_lc_appliance").val();
+
+ if (appliance_name) {
+ lc['appliance'] = appliance_name;
+ }
if (contextualization_method == 'chef') {
@@ -621,7 +736,7 @@ function save_lc_values() {
else {
$("#phantom_lc_user_images_choices").parent().addClass("error");
}
- phantom_warning("You must select an image.");
+ phantom_warning("You must select an image, or an appliance.");
return false;
}
if (!instance_type) {
@@ -683,6 +798,10 @@ function phantom_lc_save_click_internal() {
'cloud_params': {},
};
+ if ('appliance' in lc) {
+ data['appliance'] = lc['appliance'];
+ }
+
if (! ('contextualization_method' in lc)) {
data['contextualization_method'] = 'user_data';
data['user_data'] = lc['user_data'];
@@ -737,6 +856,7 @@ function phantom_lc_save_click_internal() {
phantom_lc_buttons(true);
}
+ console.log(data);
if (g_unsaved_lcs.indexOf(lc_name) > -1) {
var url = make_url("launchconfigurations");
phantomPOST(url, data, success_func, error_func);
View
6 phantomweb/templates/launchconfig.html
@@ -49,6 +49,12 @@ <h5 class="phantom_area_header magic-underline" id="launch_config_options_head">
<form class="form-horizontal">
<div class="control-group">
+ <label for="phantom_lc_appliance" class="phantom_lc_info_label">Appliance:</label>
+ <select id="phantom_lc_appliance" class="span6 pull-right">
+ </select>
+ </div>
+
+ <div class="control-group">
<label for="phantom_lc_contextualization" class="phantom_lc_info_label">Contextualization Type:</label>
<select id="phantom_lc_contextualization" class="span6 pull-right">
<option value="none" selected>None</option>
View
8 phantomweb/util.py
@@ -370,7 +370,7 @@ def get_all_groups(self):
domains.append(domain_description)
return domains
- def create_dt(self, dt_name, cloud_params, context_params):
+ def create_dt(self, dt_name, cloud_params, context_params, appliance=None):
dt = self.get_dt(dt_name)
if dt is None:
dt = {}
@@ -429,6 +429,12 @@ def create_dt(self, dt_name, cloud_params, context_params):
contextualization = dt['contextualization'] = {}
contextualization['method'] = None
+ if appliance is not None:
+ dt['appliance'] = appliance
+ else:
+ if 'appliance' in dt:
+ del dt['appliance']
+
if create:
return self.dtrs.add_dt(self.access_key, dt_name, dt)
else:
View
12 phantomweb/workload.py
@@ -132,26 +132,26 @@ def upload_key(cloud, name, key):
cloud.upload_key(name, key)
-def create_launch_configuration(username, name, cloud_params, context_params):
+def create_launch_configuration(username, name, cloud_params, context_params, appliance=None):
lc = LaunchConfiguration.objects.create(name=name, username=username)
user_obj = get_user_object(username)
- user_obj.create_dt(name, cloud_params, context_params)
+ user_obj.create_dt(name, cloud_params, context_params, appliance)
lc.save()
return lc
-def update_launch_configuration(id, cloud_params, context_params):
+def update_launch_configuration(id, cloud_params, context_params, appliance=None):
lc = get_launch_configuration(id)
if lc is None:
raise PhantomWebException("Trying to update lc %s that doesn't exist?" % id)
username = lc.get('owner')
name = lc.get('name')
user_obj = get_user_object(username)
- user_obj.create_dt(name, cloud_params, context_params)
+ user_obj.create_dt(name, cloud_params, context_params, appliance)
return lc
@@ -213,6 +213,10 @@ def get_launch_configuration(id):
elif method is None:
lc_dict["contextualization_method"] = 'none'
+ appliance = dt.get('appliance')
+ if appliance:
+ lc_dict['appliance'] = appliance
+
for cloud, mapping in dt.get('mappings', {}).iteritems():
lc_dict["cloud_params"][cloud] = {

0 comments on commit 203c505

Please sign in to comment.
Something went wrong with that request. Please try again.