You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/12/07 16:26:47 UTC
[PATCH core 3/8] CIMI: Added MachineAdmin to UI (create and destroy operations included)
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
clients/cimi/app.rb | 1 +
clients/cimi/lib/entities.rb | 1 +
clients/cimi/lib/entities/machine_admin.rb | 68 ++++++++++++++++++++++++++
clients/cimi/views/machine_admins/index.haml | 44 +++++++++++++++++
clients/cimi/views/machine_admins/new.haml | 54 ++++++++++++++++++++
clients/cimi/views/machine_admins/show.haml | 42 ++++++++++++++++
6 files changed, 210 insertions(+), 0 deletions(-)
create mode 100644 clients/cimi/lib/entities/machine_admin.rb
create mode 100644 clients/cimi/views/machine_admins/index.haml
create mode 100644 clients/cimi/views/machine_admins/new.haml
create mode 100644 clients/cimi/views/machine_admins/show.haml
diff --git a/clients/cimi/app.rb b/clients/cimi/app.rb
index 0dcad34..a8c3459 100644
--- a/clients/cimi/app.rb
+++ b/clients/cimi/app.rb
@@ -23,6 +23,7 @@ module CIMI::Frontend
use CIMI::Frontend::MachineConfiguration
use CIMI::Frontend::MachineImage
use CIMI::Frontend::Machine
+ use CIMI::Frontend::MachineAdmin
use CIMI::Frontend::MachineTemplate
use CIMI::Frontend::VolumeConfiguration
use CIMI::Frontend::VolumeImage
diff --git a/clients/cimi/lib/entities.rb b/clients/cimi/lib/entities.rb
index d351488..ddb8f91 100644
--- a/clients/cimi/lib/entities.rb
+++ b/clients/cimi/lib/entities.rb
@@ -21,6 +21,7 @@ end
require 'entities/base_entity'
require 'entities/cloud_entry_point'
require 'entities/machine_configuration'
+require 'entities/machine_admin'
require 'entities/machine_image'
require 'entities/machine'
require 'entities/machine_template'
diff --git a/clients/cimi/lib/entities/machine_admin.rb b/clients/cimi/lib/entities/machine_admin.rb
new file mode 100644
index 0000000..bfa49ad
--- /dev/null
+++ b/clients/cimi/lib/entities/machine_admin.rb
@@ -0,0 +1,68 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership. The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+class CIMI::Frontend::MachineAdmin < CIMI::Frontend::Entity
+
+ get '/cimi/machine_admins/new' do
+ haml :'machine_admins/new'
+ end
+
+ get '/cimi/machine_admins/:id' do
+ machine_admins_xml = get_entity('machine_admins', params[:id], credentials)
+ @machine_admin = CIMI::Model::MachineAdmin.from_xml(machine_admins_xml)
+ haml :'machine_admins/show'
+ end
+
+ delete '/cimi/machine_admins/:id/delete' do
+ result = destroy_entity('machine_admins', params[:id], credentials)
+ if result.code == 200
+ flash[:success] = "MachineAdmin '#{params[:id]}' was successfully destroyed."
+ redirect '/cimi/machine_admins'
+ else
+ flash[:error] = "Unable to destroy Machine Admin #{params[:id]}"
+ end
+ end
+
+ get '/cimi/machine_admins' do
+ machine_admin_xml = get_entity_collection('machine_admins', credentials)
+ puts machine_admin_xml
+ @machine_admins = CIMI::Model::MachineAdminCollection.from_xml(machine_admin_xml)
+ puts @machine_admins.inspect
+ haml :'machine_admins/index'
+ end
+
+ post '/cimi/machine_admin' do
+ machine_admin_xml = Nokogiri::XML::Builder.new do |xml|
+ xml.MachineAdmin(:xmlns => CIMI::Frontend::CMWG_NAMESPACE) {
+ xml.name params[:machine_admin][:name]
+ xml.description params[:machine_admin][:description]
+ xml.username params[:machine_admin][:username]
+ xml.password params[:machine_admin][:password]
+ xml.key params[:machine_admin][:key]
+ }
+ end.to_xml
+ begin
+ result = create_entity('machine_admins', machine_admin_xml, credentials)
+ machine_admin = CIMI::Model::MachineAdminCollection.from_xml(result)
+ flash[:success] = "MachineAdmin was successfully created."
+ redirect "/cimi/machine_admins/#{machine_admin.name}", 302
+ rescue => e
+ flash[:error] = "Machine Admin could not be created: #{e.message}"
+ redirect :back
+ end
+ end
+
+
+end
diff --git a/clients/cimi/views/machine_admins/index.haml b/clients/cimi/views/machine_admins/index.haml
new file mode 100644
index 0000000..cb04af6
--- /dev/null
+++ b/clients/cimi/views/machine_admins/index.haml
@@ -0,0 +1,44 @@
+- @title=@machine_admins.name
+
+- content_for :breadcrumb do
+ %ul.breadcrumb
+ %li
+ %a{ :href => "/cimi/cloudEntryPoint"} CloudEntryPoint
+ %span.divider="/"
+ %li.active
+ MachineAdminCollection
+
+- content_for :actions do
+ %p
+ %a{ :href => "#{@machine_admins.uri}?format=xml", :class => 'label warning' } XML
+ %a{ :href => "#{@machine_admins.uri}?format=json", :class => 'label warning' } JSON
+ %p
+ %a{ :href => '/cimi/machine_admins/new', :class => 'btn info'} New Machine Admin
+
+%blockquote
+ %p
+ A Machine Admin Collection entity represents the collection of Machine Admin
+ entities within a Provider. This entity can be used to locate and create
+ MachineAdmins.
+
+%ul
+ - @machine_admins.machine_admins.each do |conf|
+ %li
+ %a{ :href => "/cimi/machine_admins/#{conf.href.split('/').last}"}=conf.href.split('/').last
+
+- if @machine_admins.machine_admins.empty?
+ .alert-message.block-message.warning
+ %p
+ There are no MachineAdmin entities defined for this collection.
+ .alert_actions
+ %a{ :href => '/cimi/machine_admins/new', :class => 'btn'} Create new
+
+%h3 Collection details
+
+%dl
+ %dt URI
+ %dd=@machine_admins.uri
+ %dt Description
+ %dd=@machine_admins.description
+ %dt Created
+ %dd=@machine_admins.created
diff --git a/clients/cimi/views/machine_admins/new.haml b/clients/cimi/views/machine_admins/new.haml
new file mode 100644
index 0000000..b969740
--- /dev/null
+++ b/clients/cimi/views/machine_admins/new.haml
@@ -0,0 +1,54 @@
+- @title="New MachineAdmin"
+
+- content_for :breadcrumb do
+ %ul.breadcrumb
+ %li
+ %a{ :href => "/cimi/cloudEntryPoint"} CloudEntryPoint
+ %span.divider="/"
+ %li
+ %a{ :href => "/cimi/machine_admins"} MachineAdminCollection
+ %span.divider="/"
+ %li.active New MachineAdmin
+
+
+%form{ :action => "/cimi/machine_admin", :method => :post }
+ %fieldset
+ %legend Create new MachineAdmin
+ %div.clearfix
+ %label{ :for => 'machine_admin[name]' }
+ Name
+ %div.input
+ %input{ :type => :text, :name => 'machine_admin[name]' }
+ %div.clearfix
+ %label{ :for => 'machine_admin[description]' }
+ Description
+ %div.input
+ %input{ :type => :text, :name => 'machine_admin[description]' }
+ %div.clearfix
+ %label{ :for => 'machine_admin[username]' }
+ Username
+ %div.input
+ %input{ :type => :text, :name => 'machine_admin[username]', :value => "root" }
+ %span.help-block
+ %span.label.info NOTE
+ Property could not be supported by cloud provider
+ %div.clearfix
+ %label{ :for => 'machine_admin[password]' }
+ Password
+ %div.input
+ %input{ :type => :text, :name => 'machine_admin[password]' }
+ %span.help-block
+ %span.label.info NOTE
+ Property could not be supported by cloud provider
+ %div.clearfix
+ %label{ :for => 'machine_admin[key]' }
+ Key
+ %div.input
+ %textarea.xlarge{ :name => 'machine_admin[key]', :rows => 3 }
+ %span.help-block
+ %span.label.info NOTE
+ Property could not be supported by cloud provider
+ %div.actions
+ %input{ :type => :submit, :class => 'btn primary', :value => "Create MachineAdmin" }
+ %button{ :type => :reset, :class => 'btn' } Reset
+
diff --git a/clients/cimi/views/machine_admins/show.haml b/clients/cimi/views/machine_admins/show.haml
new file mode 100644
index 0000000..07602f3
--- /dev/null
+++ b/clients/cimi/views/machine_admins/show.haml
@@ -0,0 +1,42 @@
+- @title="#{@machine_admin.name}"
+
+- content_for :breadcrumb do
+ %ul.breadcrumb
+ %li
+ %a{ :href => "/cimi/cloudEntryPoint"} CloudEntryPoint
+ %span.divider="/"
+ %li
+ %a{ :href => "/cimi/machine_admins"} MachineAdminCollection
+ %span.divider="/"
+ %li.active
+ = @machine_admin.name
+
+- content_for :actions do
+ %p
+ %a{ :href => "#{@machine_admin.uri}?format=xml", :class => 'label warning' } XML
+ %a{ :href => "#{@machine_admin.uri}?format=json", :class => 'label warning' } JSON
+ %p
+ %form{ :action => "/cimi/machine_admins/#{@machine_admin.name}/delete", :method => :post, :style => 'display:inline'}
+ %input{ :type => :hidden, :name => '_method', :value => 'delete'}
+ %button{ :class => 'btn danger'} Destroy
+
+%blockquote
+ %p
+ A Machine Admin entity contains the information required to create the
+ initial administrative super- user of a newly created Machine
+
+%dl
+ %dt URI
+ %dd
+ %a{ :href => @machine_admin.uri }=@machine_admin.uri
+ %dt Description
+ %dd=@machine_admin.description
+ %dt Created
+ %dd=@machine_admin.created
+ %dt Username
+ %dd=boolean_span_for @machine_admin.username
+ %dt Password
+ %dd=boolean_span_for @machine_admin.password
+ %dt Key
+ %dd
+ %pre=boolean_span_for @machine_admin.key
--
1.7.4.4