You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by ma...@apache.org on 2013/04/26 17:46:58 UTC
[01/14] git commit: Network API rev 3 - NetworkInterface Collection
(routes)
Updated Branches:
refs/heads/master e8a2c85b6 -> 9c094964b
Network API rev 3 - NetworkInterface Collection (routes)
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/8c9ff36b
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/8c9ff36b
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/8c9ff36b
Branch: refs/heads/master
Commit: 8c9ff36beb937b6a656b10d29f18c19364d61606
Parents: e8a2c85
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 11:58:21 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:54 2013 +0300
----------------------------------------------------------------------
.../deltacloud/collections/network_interfaces.rb | 64 +++++++++++++++
1 files changed, 64 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/8c9ff36b/server/lib/deltacloud/collections/network_interfaces.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/network_interfaces.rb b/server/lib/deltacloud/collections/network_interfaces.rb
new file mode 100644
index 0000000..5a9c2a2
--- /dev/null
+++ b/server/lib/deltacloud/collections/network_interfaces.rb
@@ -0,0 +1,64 @@
+# 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.
+
+module Deltacloud::Collections
+ class NetworkInterfaces < Base
+
+ include Deltacloud::Features
+
+ set :capability, lambda { |m| driver.respond_to? m }
+ check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
+ new_route_for(:network_interfaces) do
+ @opts={}
+ @opts[:instances]=driver.instances(credentials)
+ @opts[:networks]= driver.respond_to?(:subnets) ? driver.subnets(credentials) : driver.networks(credentials)
+ end
+
+ collection :network_interfaces do
+
+ standard_show_operation({:check => :subnets})
+ standard_index_operation({:check => :subnets})
+
+ operation :create, :with_capability => :create_network_interface do
+ param :instance, :string, :required
+ param :network, :string, :required
+ param :name, :string, :optional
+ control do
+ params.delete("name") if params["name"] && params["name"].empty?
+ @network_interface = driver.create_network_interface(credentials, params)
+ respond_to do |format|
+ format.xml { haml :"network_interfaces/show", :locals => {:network_interface=>@network_interface, :subnets=>driver.respond_to?(:subnets)}}
+ format.html { haml :"network_interfaces/show", :locals => {:network_interface=>@network_interface, :subnets=>driver.respond_to?(:subnets)}}
+ format.json { xml_to_json("network_interfaces/show")}
+ end
+ end
+ end
+
+ operation :destroy, :with_capability => :destroy_network_interface do
+ control do
+ driver.destroy_network_interface(credentials, params[:id])
+ status 204
+ respond_to do |format|
+ format.xml
+ format.json
+ format.html { redirect(network_interfaces_url) }
+ end
+ end
+ end
+
+ end
+
+ end
+end
[10/14] git commit: Network API rev 3 - Updated Instance Views (haml)
Posted by ma...@apache.org.
Network API rev 3 - Updated Instance Views (haml)
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/1cef953d
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/1cef953d
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/1cef953d
Branch: refs/heads/master
Commit: 1cef953d697f20bf322df1700b5b1d61680142ee
Parents: a2d52f7
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:19:01 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
server/views/instances/show.html.haml | 5 +++++
server/views/instances/show.xml.haml | 5 ++++-
2 files changed, 9 insertions(+), 1 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1cef953d/server/views/instances/show.html.haml
----------------------------------------------------------------------
diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
index 58e912e..3fabc57 100644
--- a/server/views/instances/show.html.haml
+++ b/server/views/instances/show.html.haml
@@ -56,6 +56,11 @@
-instance.storage_volumes.each do |vol|
%li
%a{ :href => storage_volume_url("#{vol.keys.first}"), :'data-ajax' => 'false'}=["#{vol.keys.first}", "#{vol.values.first}"].compact.reject{ |e| e.empty? }.join(' <---> ')
+ - if instance.network_interfaces
+ %li{ :'data-role' => 'list-divider'} Network Interfaces
+ -instance.network_interfaces.each do |nic|
+ %li
+ %a{ :href => network_interface_url("#{nic}"), :'data-ajax' => 'false'}="#{nic}"
%li{ :'data-role' => 'list-divider'} Actions
%li
%div{ :'data-role' => 'controlgroup', :'data-type' => "horizontal" }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1cef953d/server/views/instances/show.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml
index 654037b..220a0a8 100644
--- a/server/views/instances/show.xml.haml
+++ b/server/views/instances/show.xml.haml
@@ -57,4 +57,7 @@
- if instance.keyname
%login
%keyname #{instance.keyname}
-
+ - if instance.network_interfaces
+ %network_interfaces<
+ - instance.network_interfaces.each do |nic|
+ %network_interface{:href => network_interface_url(nic), :id => nic}
[11/14] git commit: Network API rev 3 - Mock Driver fixtures (yaml)
Posted by ma...@apache.org.
Network API rev 3 - Mock Driver fixtures (yaml)
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/a7ad95f1
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/a7ad95f1
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/a7ad95f1
Branch: refs/heads/master
Commit: a7ad95f169c6a886c61c64f8e096ae08f1c77d60
Parents: 83dcee9
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:21:25 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
.../drivers/mock/data/instances/inst0.yml | 1 +
.../drivers/mock/data/instances/inst1.yml | 2 +
.../drivers/mock/data/instances/inst3.yml | 26 +++++++++++++++
.../drivers/mock/data/network_interfaces/nic1.yml | 6 +++
.../mock/data/network_interfaces/nicinst3.yml | 7 ++++
.../deltacloud/drivers/mock/data/networks/net1.yml | 9 +++++
.../deltacloud/drivers/mock/data/networks/net2.yml | 9 +++++
.../drivers/mock/data/subnets/subnet1.yml | 6 +++
.../drivers/mock/data/subnets/subnet2.yml | 6 +++
.../drivers/mock/data/subnets/subnet3.yml | 6 +++
.../drivers/mock/data/subnets/subnet4.yml | 6 +++
11 files changed, 84 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml b/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml
index 832329a..8ee7ad9 100644
--- a/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml
+++ b/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml
@@ -21,3 +21,4 @@
:id: inst0
:state: RUNNING
:storage_volumes: []
+:network_interfaces: []
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml b/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml
index b1ebb45..4d20bfa 100644
--- a/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml
+++ b/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml
@@ -20,3 +20,5 @@
- :reboot
- :stop
:storage_volumes: []
+:network_interfaces:
+ - nic1
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/instances/inst3.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/instances/inst3.yml b/server/lib/deltacloud/drivers/mock/data/instances/inst3.yml
new file mode 100644
index 0000000..0d8e36a
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/instances/inst3.yml
@@ -0,0 +1,26 @@
+---
+:id: inst3
+:name: ''
+:state: RUNNING
+:keyname: ''
+:image_id: img3
+:owner_id: !binary |-
+ bW9ja3VzZXI=
+:public_addresses:
+- !ruby/object:Deltacloud::InstanceAddress
+ address: img3.inst3.public.com
+ address_type: :hostname
+:private_addresses:
+- !ruby/object:Deltacloud::InstanceAddress
+ address: img3.inst3.private.com
+ address_type: :hostname
+:instance_profile: !ruby/object:Deltacloud::InstanceProfile
+ id: m1-small
+:realm_id: eu
+:create_image: true
+:actions:
+- :reboot
+- :stop
+:user_data:
+:network_interfaces:
+- nicinst3
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/network_interfaces/nic1.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/network_interfaces/nic1.yml b/server/lib/deltacloud/drivers/mock/data/network_interfaces/nic1.yml
new file mode 100644
index 0000000..5ca8b4b
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/network_interfaces/nic1.yml
@@ -0,0 +1,6 @@
+---
+:id: nic1
+:name: nic1
+:network: subnet1
+:instance: inst1
+:ip_address: 192.168.1.2
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/network_interfaces/nicinst3.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/network_interfaces/nicinst3.yml b/server/lib/deltacloud/drivers/mock/data/network_interfaces/nicinst3.yml
new file mode 100644
index 0000000..7a6f3e2
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/network_interfaces/nicinst3.yml
@@ -0,0 +1,7 @@
+---
+:id: nicinst3
+:name: nicinst3
+:instance: inst3
+:network: net1
+:subnet: subnet2
+:ip_address: 192.168.2.189
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/networks/net1.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/networks/net1.yml b/server/lib/deltacloud/drivers/mock/data/networks/net1.yml
new file mode 100644
index 0000000..b39f2fd
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/networks/net1.yml
@@ -0,0 +1,9 @@
+---
+:id: net1
+:name: network1
+:subnets:
+- subnet1
+- subnet2
+:address_blocks:
+- 192.168.0.0/16
+:state: UP
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/networks/net2.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/networks/net2.yml b/server/lib/deltacloud/drivers/mock/data/networks/net2.yml
new file mode 100644
index 0000000..535481b
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/networks/net2.yml
@@ -0,0 +1,9 @@
+---
+:id: net2
+:name: network2
+:subnets:
+- subnet3
+- subnet4
+:address_blocks:
+- 10.0.0.0/8
+:state: UP
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/subnets/subnet1.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/subnets/subnet1.yml b/server/lib/deltacloud/drivers/mock/data/subnets/subnet1.yml
new file mode 100644
index 0000000..11d5db9
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/subnets/subnet1.yml
@@ -0,0 +1,6 @@
+---
+:id: subnet1
+:name: subnet1
+:network: net1
+:address_block: 192.168.1.0/24
+:state: UP
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/subnets/subnet2.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/subnets/subnet2.yml b/server/lib/deltacloud/drivers/mock/data/subnets/subnet2.yml
new file mode 100644
index 0000000..d2ef7c2
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/subnets/subnet2.yml
@@ -0,0 +1,6 @@
+---
+:id: subnet2
+:name: subnet2
+:network: net1
+:address_block: 192.168.2.0/24
+:state: UP
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/subnets/subnet3.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/subnets/subnet3.yml b/server/lib/deltacloud/drivers/mock/data/subnets/subnet3.yml
new file mode 100644
index 0000000..7109179
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/subnets/subnet3.yml
@@ -0,0 +1,6 @@
+---
+:id: subnet3
+:name: subnet3
+:network: net2
+:address_block: 10.1.0.0/16
+:state: UP
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a7ad95f1/server/lib/deltacloud/drivers/mock/data/subnets/subnet4.yml
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/data/subnets/subnet4.yml b/server/lib/deltacloud/drivers/mock/data/subnets/subnet4.yml
new file mode 100644
index 0000000..937baaf
--- /dev/null
+++ b/server/lib/deltacloud/drivers/mock/data/subnets/subnet4.yml
@@ -0,0 +1,6 @@
+---
+:id: subnet4
+:name: subnet4
+:network: net2
+:address_block: 10.2.0.0/16
+:state: UP
[04/14] git commit: Network API rev 3 - Subnet Views (haml)
Posted by ma...@apache.org.
Network API rev 3 - Subnet Views (haml)
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/a2d52f7d
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/a2d52f7d
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/a2d52f7d
Branch: refs/heads/master
Commit: a2d52f7d9a1003203298ffc0d304b173241148ba
Parents: 765ee10
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:17:30 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
server/views/subnets/index.html.haml | 10 ++++++++++
server/views/subnets/index.xml.haml | 4 ++++
server/views/subnets/new.html.haml | 14 ++++++++++++++
server/views/subnets/show.html.haml | 24 ++++++++++++++++++++++++
server/views/subnets/show.xml.haml | 13 +++++++++++++
5 files changed, 65 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a2d52f7d/server/views/subnets/index.html.haml
----------------------------------------------------------------------
diff --git a/server/views/subnets/index.html.haml b/server/views/subnets/index.html.haml
new file mode 100644
index 0000000..5442c17
--- /dev/null
+++ b/server/views/subnets/index.html.haml
@@ -0,0 +1,10 @@
+=header "Subnets" do
+ %a{ :href => url_for('subnets/new'), :'data-icon' => :plus, :'data-role' => :button, :class => 'ui-btn-right'} Create new subnet
+
+%div{ :'data-role' => :content, :'data-theme' => 'c'}
+ %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' => 'a'}
+ - @elements.each do |subnet|
+ %li
+ %a{ :href => subnet_url(subnet.id), :'data-ajax' => 'false'}
+ %img{ :class => 'ui-link-thumb', :src => '/images/cloud.png'}
+ %h3=subnet.id
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a2d52f7d/server/views/subnets/index.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/subnets/index.xml.haml b/server/views/subnets/index.xml.haml
new file mode 100644
index 0000000..5079a8d
--- /dev/null
+++ b/server/views/subnets/index.xml.haml
@@ -0,0 +1,4 @@
+!!!XML
+%subnets
+ - @elements.each do |c|
+ = haml :'subnets/show', :locals => { :subnet => c, :partial => true }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a2d52f7d/server/views/subnets/new.html.haml
----------------------------------------------------------------------
diff --git a/server/views/subnets/new.html.haml b/server/views/subnets/new.html.haml
new file mode 100644
index 0000000..c542d8e
--- /dev/null
+++ b/server/views/subnets/new.html.haml
@@ -0,0 +1,14 @@
+=header "Create new subnet"
+
+%div{ :'data-role' => :content, :'data-theme' => 'c', :class => 'middle-dialog'}
+ %form{ :action => subnets_url, :method => :post}
+ %div{ 'data-role' => :fieldcontain }
+ %p
+ %label{ :for => :network_id} Network ID:
+ %p
+ %input{ :type => :text, :id => :network_id, :name => :network_id, :value => '' }
+ %p
+ %label{ :for => :address_block} CIDR Address block:
+ %p
+ %input{ :type => :text, :id => :address_block, :name => :address_block, :value => '' }
+ %button{ :type => :submit} Create subnet
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a2d52f7d/server/views/subnets/show.html.haml
----------------------------------------------------------------------
diff --git a/server/views/subnets/show.html.haml b/server/views/subnets/show.html.haml
new file mode 100644
index 0000000..dcb33c9
--- /dev/null
+++ b/server/views/subnets/show.html.haml
@@ -0,0 +1,24 @@
+=header "Subnet"
+=subheader @subnet.id
+
+%div{ :'data-role' => :content, :'data-theme' => 'c'}
+ %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' => 'd'}
+ %li{ :'data-role' => 'list-divider'} Identifier
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=@subnet.id
+ %li{ :'data-role' => 'list-divider'} Name
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=@subnet.name
+ %li{ :'data-role' => 'list-divider'} Network
+ %li
+ %a{ :href => network_url(@subnet.network.strip), :'data-ajax'=>'false' }=@subnet.network
+ %li{ :'data-role' => 'list-divider'} State
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=@subnet.state
+ %li{ :'data-role' => 'list-divider'} Address Block
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=(@subnet.address_block ? @subnet.address_block : nil)
+ %li{ :'data-role' => 'list-divider'} Actions
+ %li
+ %div{ :'data-role' => 'controlgroup', :'data-type' => "horizontal" }
+ =link_to_action "Destroy", destroy_subnet_url(@subnet.id), :delete
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/a2d52f7d/server/views/subnets/show.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/subnets/show.xml.haml b/server/views/subnets/show.xml.haml
new file mode 100644
index 0000000..75363af
--- /dev/null
+++ b/server/views/subnets/show.xml.haml
@@ -0,0 +1,13 @@
+- unless defined?(partial)
+ !!! XML
+%subnet{ :href => subnet_url(subnet.id), :id => subnet.id }
+ %name=subnet.name
+ %state<
+ =subnet.state
+ %address_block
+ =subnet.address_block
+ %network
+ =subnet.network
+ %actions
+ - if driver.respond_to?(:destroy_subnet)
+ %link{ :rel => "destroy", :method => "delete", :href => destroy_subnet_url(subnet.id)}
[02/14] git commit: Network API rev 3 - RHEV-M Driver implementation
Posted by ma...@apache.org.
Network API rev 3 - RHEV-M Driver implementation
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/c1c84bcb
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/c1c84bcb
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/c1c84bcb
Branch: refs/heads/master
Commit: c1c84bcb7bda87b137f990adc5db250c029d46d6
Parents: 3163f81
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:22:49 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
.../lib/deltacloud/drivers/rhevm/rhevm_driver.rb | 88 ++++++++++++++-
1 files changed, 86 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/c1c84bcb/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index ce34457..6b90b2d 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -208,6 +208,71 @@ class RhevmDriver < Deltacloud::BaseDriver
end
end
+ def networks(credentials, opts={})
+ client = new_client(credentials)
+ networks = []
+ safely do
+ client.networks(opts).each do |n|
+ next unless n.status == "operational" # making network operational is admin task
+ networks << convert_network(n)
+ end
+ end
+ filter_on(networks, :id, opts)
+ end
+
+ #def create_network(credentials, opts={})
+ # RHEV API supports creation of networks, but network creation is
+ # admin task, it's not expected to create networks on demand.
+ # If we want to have this action, it must also be implemented in
+ # rbovirt at first
+ #end
+
+ #def destroy_network(credentials, opts={})
+ # RHEV API supports deletion of networks, but network creation is
+ # admin task, it's not expected to delete networks on demand.
+ # If we want to have this action, it must also be implemented in
+ # rbovirt at first
+ #end
+
+ #def subnets(credentials, opts={})
+ # there is not any suitable entity in RHEV networking model
+ #end
+ def network_interfaces(credentials, opts={})
+ client = new_client(credentials)
+ nics = []
+ safely do
+ client.vms.each do |vm|
+ vm.interfaces.each do |vm_nic|
+ if opts[:id] && (vm_nic.id == opts[:id])
+ return [convert_nic(vm_nic)]
+ else
+ nics << convert_nic(vm_nic)
+ end
+ end
+ end
+ end
+ filter_on(nics, :id, opts)
+ end
+
+ #:network, :instance, :name
+ def create_network_interface(credentials, opts={})
+ client = new_client(credentials)
+ name = opts[:name] || "nic_#{Time.now.to_i}"
+ safely do
+ iface = client.add_interface(opts[:instance], {:name => name, :network => opts[:network]})
+ convert_nic(iface)
+ end
+ end
+
+ def destroy_network_interface(credentials, nic_id)
+ client = new_client(credentials)
+ safely do
+ #need to discover the instance for this nic first
+ nic = network_interface(credentials, {:id => nic_id})
+ client.destroy_interface(nic.instance, nic_id)
+ end
+ end
+
private
def new_client(credentials)
@@ -270,7 +335,8 @@ class RhevmDriver < Deltacloud::BaseDriver
else
actions = instance_actions_for(state)
end
-
+ #get network_interfaces:
+ nics = inst.interfaces.inject([]){|res, cur| res << cur.id ; res}
Instance.new(
:actions=>actions,
:id => inst.id,
@@ -284,7 +350,8 @@ class RhevmDriver < Deltacloud::BaseDriver
:hardware_profile_id => profile.id,
:public_addresses => public_addresses,
:private_addresses => [],
- :create_image => can_create_image
+ :create_image => can_create_image,
+ :network_interfaces => nics
)
end
@@ -344,6 +411,23 @@ class RhevmDriver < Deltacloud::BaseDriver
)
end
+ def convert_network(n)
+ Network.new(
+ :id => n.id,
+ :name => n.name,
+ :state => "UP" # only here if status is "operational"
+ )
+ end
+
+ def convert_nic(nic)
+ NetworkInterface.new({
+ :id => nic.id,
+ :name => nic.name,
+ :instance => nic.vm.id,
+ :network => nic.network || "n/a"
+ })
+ end
+
exceptions do
on /Unauthorized/ do
[03/14] git commit: Network API rev 3 - OpenStack Driver
implementation
Posted by ma...@apache.org.
Network API rev 3 - OpenStack Driver implementation
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/3163f817
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/3163f817
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/3163f817
Branch: refs/heads/master
Commit: 3163f817efd26bb51e3e9d4c96163d6832dcfdc3
Parents: a7ad95f
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:22:19 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
.../drivers/openstack/openstack_driver.rb | 192 ++++++++++++++-
1 files changed, 184 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3163f817/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
index 343934d..bfa4cb6 100644
--- a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
+++ b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
@@ -162,19 +162,24 @@ module Deltacloud
def instances(credentials, opts={})
os = new_client(credentials)
- insts = attachments = []
+ insts = attachments = nics = []
safely do
+ if have_quantum?(credentials)
+ nics = network_interfaces(credentials)
+ end
if opts[:id]
begin
server = os.get_server(opts[:id])
- insts << convert_from_server(server, os.connection.authuser, get_attachments(opts[:id], os))
+ inst_nics = nics.inject([]){|res, cur| res << cur.id if cur.instance == opts[:id] ;res}
+ insts << convert_from_server(server, os.connection.authuser, get_attachments(opts[:id], os), inst_nics)
rescue => e
raise e unless e.message =~ /The resource could not be found/
insts = []
end
else
insts = os.list_servers_detail.collect do |s|
- convert_from_server(s, os.connection.authuser,get_attachments(s[:id], os))
+ inst_nics = nics.inject([]){|res, cur| res << cur.id if cur.instance == s[:id] ;res}
+ convert_from_server(s, os.connection.authuser,get_attachments(s[:id], os), inst_nics)
end
end
end
@@ -182,6 +187,15 @@ module Deltacloud
insts
end
+ def have_quantum?(credentials)
+ begin
+ quantum = new_client(credentials, "network")
+ rescue => e
+ return nil
+ end
+ quantum
+ end
+
def create_instance(credentials, image_id, opts)
os = new_client( credentials, "compute")
result = nil
@@ -473,6 +487,124 @@ module Deltacloud
end
end
+ def networks(credentials, opts={})
+ os = new_client(credentials, "network")
+ networks = []
+ safely do
+ subnets = os.subnets
+ if opts[:id]
+ begin
+ net = os.network(opts[:id])
+ addr_blocks = get_address_blocks_for(net.id, subnets)
+ networks << convert_network(net, addr_blocks)
+ rescue => e
+ raise e unless e.message =~ /Network not found/
+ networks = []
+ end
+ else
+ os.networks.each do |net|
+ addr_blocks = get_address_blocks_for(net.id, subnets)
+ networks << convert_network(net, addr_blocks)
+ end
+ end
+ end
+ networks = filter_on(networks, :id, opts)
+ end
+
+ #require params for openstack: {:name}
+ def create_network(credentials, opts={})
+ os = new_client(credentials, "network")
+ safely do
+ net = os.create_network(opts[:name] || "net_#{Time.now.to_i}")
+ convert_network(net)
+ end
+ end
+
+ def destroy_network(credentials, id)
+ os = new_client(credentials, "network")
+ safely do
+ os.delete_network(id)
+ end
+ end
+
+ def subnets(credentials, opts={})
+ os = new_client(credentials, "network")
+ subnets = []
+ safely do
+ if opts[:id]
+ begin
+ snet = os.subnet opts[:id]
+ subnets << convert_subnet(snet)
+ rescue => e
+ raise e unless e.message =~ /Subnet not found/
+ subnets = []
+ end
+ else
+ os.subnets.each do |subnet|
+ subnets << convert_subnet(subnet)
+ end
+ end
+ end
+ subnets = filter_on(subnets, :id, opts)
+ end
+
+ #required params: :network_id, cidr_block
+ #optional params: :ip_version, :gateway_ip, :allocation_pools
+ def create_subnet(credentials, opts={})
+ os = new_client(credentials, "network")
+ safely do
+ convert_subnet(os.create_subnet(opts[:network_id], opts[:address_block]))
+ end
+ end
+
+ def destroy_subnet(credentials, subnet_id)
+ os = new_client(credentials, "network")
+ safely do
+ os.delete_subnet(subnet_id)
+ end
+ end
+
+ def network_interfaces(credentials, opts={})
+ os = new_client(credentials, "network")
+ nics = []
+ safely do
+ if opts[:id]
+ begin
+ nic = os.port(opts[:id])
+ nics << convert_nic(nic)
+ rescue => e
+ raise e unless e.message =~ /Port not found/
+ nics = []
+ end
+ else
+ os.ports.each do |port|
+ nics << convert_nic(port)
+ end
+ end
+ end
+ nics = filter_on(nics, :id, opts)
+ end
+
+ def create_network_interface(credentials, opts={})
+ quantum = new_client(credentials, "network")
+ safely do
+ #first discover the network for the supplied subnet
+ #i.e. opts[:network] is actually a subnet
+ snet = quantum.subnet(opts[:network])
+ network = snet.network_id
+ name = opts[:name] || "nic_#{Time.now.to_i}"
+ port = quantum.create_port(network, {"fixed_ips"=>[{"subnet_id"=>opts[:network]}], "device_id"=>opts[:instance], "name"=>name})
+ convert_nic(port)
+ end
+ end
+
+ def destroy_network_interface(credentials, nic_id)
+ os = new_client(credentials, "network")
+ safely do
+ os.delete_port(nic_id)
+ end
+ end
+
private
#for v2 authentication credentials.name == "username+tenant_name"
def new_client(credentials, type="compute", ignore_provider=false)
@@ -495,7 +627,7 @@ private
connection_params.merge!({:region => region}) if region && !ignore_provider # hack needed for 'def providers'
safely do
raise ValidationFailure.new(Exception.new("Error: tried to initialise Openstack connection using" +
- " an unknown service_type: #{type}")) unless ["volume", "compute", "object-store"].include? type
+ " an unknown service_type: #{type}")) unless ["volume", "compute", "object-store", "network"].include? type
OpenStack::Connection.create(connection_params)
end
end
@@ -529,16 +661,16 @@ private
})
end
- def convert_from_server(server, owner, attachments=[])
+ def convert_from_server(server, owner, attachments=[], nics=[])
op = (server.class == Hash)? :fetch : :send
image = server.send(op, :image)
flavor = server.send(op, :flavor)
- begin
+ begin
password = server.send(op, :adminPass) || ""
rescue IndexError
password = ""
end
- inst = Instance.new(
+ inst_params = {
:id => server.send(op, :id).to_s,
:realm_id => "default",
:owner_id => owner,
@@ -555,7 +687,11 @@ private
:keyname => server.send(op, :key_name),
:launch_time => server.send(op, :created),
:storage_volumes => attachments.inject([]){|res, cur| res << {cur[:volumeId] => cur[:device]} ;res}
- )
+ }
+ unless nics.empty?
+ inst_params.merge!(:network_interfaces=>nics)
+ end
+ inst = Instance.new(inst_params)
inst.actions = instance_actions_for(inst.state)
inst.create_image = 'RUNNING'.eql?(inst.state)
inst
@@ -656,6 +792,46 @@ private
)
end
+ def get_address_blocks_for(network_id, subnets)
+ return [] if subnets.empty?
+ addr_blocks = []
+ subnets.each do |sn|
+ if sn.network_id == network_id
+ addr_blocks << sn.cidr
+ end
+ end
+ addr_blocks
+ end
+
+ def convert_network(net, addr_blocks)
+ Network.new({ :id => net.id,
+ :name => net.name,
+ :subnets => net.subnets,
+ :state => (net.admin_state_up ? "UP" : "DOWN"),
+ :address_blocks => addr_blocks
+ })
+ end
+
+ def convert_subnet(subnet)
+ Subnet.new({ :id => subnet.id,
+ :name => subnet.name,
+ :network => subnet.network_id,
+ :address_block => subnet.cidr,
+ :state => "UP"
+ })
+ end
+
+ def convert_nic(port)
+ NetworkInterface.new({ :id => port.id,
+ :name => port.name,
+ :instance => port.device_id,
+ :network => port.fixed_ips.first["subnet_id"], #subnet, not network for OS
+ :state => (port.admin_state_up ? "UP" : "DOWN" ), # true/false
+ :ip_address =>port.fixed_ips.first["ip_address"]
+ # this is a structure; [{"subnet_id": ID, "ip_address": addr}] - COULD BE >1 address here...
+ })
+ end
+
#IN: path1='server_path1'. content1='contents1', path2='server_path2', content2='contents2' etc
#OUT:{local_path=>server_path, local_path1=>server_path2 etc}
def extract_personality(opts)
[07/14] git commit: Network API rev 3 - Collection helpers (passing
context to views - check for presence of resource)
Posted by ma...@apache.org.
Network API rev 3 - Collection helpers (passing context to views - check for presence of resource)
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/483be9a4
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/483be9a4
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/483be9a4
Branch: refs/heads/master
Commit: 483be9a49ea1d14371f292a17363cfdb1a7a7c29
Parents: 895a9c6
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:11:04 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
server/lib/deltacloud/helpers/deltacloud_helper.rb | 15 +++++++++------
server/lib/deltacloud/helpers/rabbit_helper.rb | 8 ++++----
2 files changed, 13 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/483be9a4/server/lib/deltacloud/helpers/deltacloud_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/deltacloud_helper.rb b/server/lib/deltacloud/helpers/deltacloud_helper.rb
index e069312..242effc 100644
--- a/server/lib/deltacloud/helpers/deltacloud_helper.rb
+++ b/server/lib/deltacloud/helpers/deltacloud_helper.rb
@@ -65,18 +65,19 @@ module Deltacloud::Helpers
http_method || Deltacloud::Rabbit::BaseCollection.http_method_for(action)
end
- def filter_all(model)
+ def filter_all(model, opts={})
begin
@benchmark = Benchmark.measure { @elements = driver.send(model.to_sym, credentials, params) }
rescue => e
@exception = e
end
+ locals = opts[:check] ? {:elements => @elements, opts[:check]=>driver.respond_to?(opts[:check])} : {:elements => @elements}
if @elements
headers['X-Backend-Runtime'] = @benchmark.real.to_s
instance_variable_set(:"@#{model}", @elements)
respond_to do |format|
- format.html { haml :"#{model}/index", :locals => { :elements => @elements } }
- format.xml { haml :"#{model}/index", :locals => { :elements => @elements } }
+ format.html { haml :"#{model}/index", :locals => locals}
+ format.xml { haml :"#{model}/index", :locals => locals}
format.json { JSON::dump({ model => @elements.map { |el| el.to_hash(self) }}) }
end
else
@@ -84,16 +85,18 @@ module Deltacloud::Helpers
end
end
- def show(model)
+ def show(model, opts={})
@benchmark = Benchmark.measure do
@element = driver.send(model, credentials, { :id => params[:id]} )
end
headers['X-Backend-Runtime'] = @benchmark.real.to_s
instance_variable_set("@#{model}", @element)
+ #checks for methods in opts:
+ locals = opts[:check] ? {model => @element, opts[:check]=>driver.respond_to?(opts[:check])} : {model => @element}
if @element
respond_to do |format|
- format.html { haml :"#{model.to_s.pluralize}/show", :locals=>{model=>@element}}
- format.xml { haml :"#{model.to_s.pluralize}/show" , :locals=>{model=>@element}}
+ format.html { haml :"#{model.to_s.pluralize}/show", :locals=>locals}
+ format.xml { haml :"#{model.to_s.pluralize}/show" , :locals=>locals}
format.json { JSON::dump(model => @element.to_hash(self)) }
end
else
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/483be9a4/server/lib/deltacloud/helpers/rabbit_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/rabbit_helper.rb b/server/lib/deltacloud/helpers/rabbit_helper.rb
index cdd0ae1..3c4d43f 100644
--- a/server/lib/deltacloud/helpers/rabbit_helper.rb
+++ b/server/lib/deltacloud/helpers/rabbit_helper.rb
@@ -18,15 +18,15 @@ Sinatra::Rabbit::Collection.class_eval do
def self.standard_index_operation(opts={})
collection_name = @collection_name
- operation :index, :with_capability => opts[:capability] || collection_name do
- control { filter_all collection_name }
+ operation :index, :with_capability => opts.delete(:capability) || collection_name do
+ control { filter_all collection_name, opts }
end
end
def self.standard_show_operation(opts={})
collection_name = @collection_name
- operation :show, :with_capability => opts[:capability] || collection_name do
- control { show collection_name.to_s.singularize.intern }
+ operation :show, :with_capability => opts.delete(:capability) || collection_name do
+ control { show collection_name.to_s.singularize.intern, opts}
end
end
[08/14] git commit: Network API rev 3 - Models (Network, Subnet,
NetworkInterface, Instance)
Posted by ma...@apache.org.
Network API rev 3 - Models (Network, Subnet, NetworkInterface, Instance)
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/3aefaacf
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/3aefaacf
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/3aefaacf
Branch: refs/heads/master
Commit: 3aefaacf8175353e62e5af9f3dbabd48013d5498
Parents: 483be9a
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:14:17 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
server/lib/deltacloud/models.rb | 3 ++
server/lib/deltacloud/models/instance.rb | 1 +
server/lib/deltacloud/models/network.rb | 30 ++++++++++++++++
server/lib/deltacloud/models/network_interface.rb | 24 ++++++++++++
server/lib/deltacloud/models/subnet.rb | 27 ++++++++++++++
5 files changed, 85 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3aefaacf/server/lib/deltacloud/models.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models.rb b/server/lib/deltacloud/models.rb
index e6020e6..2edbf4a 100644
--- a/server/lib/deltacloud/models.rb
+++ b/server/lib/deltacloud/models.rb
@@ -32,3 +32,6 @@ require_relative 'models/realm'
require_relative 'models/state_machine'
require_relative 'models/storage_snapshot'
require_relative 'models/storage_volume'
+require_relative 'models/network'
+require_relative 'models/subnet'
+require_relative 'models/network_interface'
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3aefaacf/server/lib/deltacloud/models/instance.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb
index 6c6b018..b435387 100644
--- a/server/lib/deltacloud/models/instance.rb
+++ b/server/lib/deltacloud/models/instance.rb
@@ -34,6 +34,7 @@ module Deltacloud
attr_accessor :create_image
attr_accessor :firewalls
attr_accessor :storage_volumes
+ attr_accessor :network_interfaces
def to_hash(context)
r = {
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3aefaacf/server/lib/deltacloud/models/network.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/network.rb b/server/lib/deltacloud/models/network.rb
new file mode 100644
index 0000000..d46ac27
--- /dev/null
+++ b/server/lib/deltacloud/models/network.rb
@@ -0,0 +1,30 @@
+#
+# 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.
+module Deltacloud
+class Network < BaseModel
+
+ attr_accessor :name
+ attr_accessor :subnets
+ attr_accessor :address_blocks
+ attr_accessor :state
+
+ def initialize(init=nil)
+ super(init)
+ self.subnets = [] unless self.subnets
+ end
+
+end
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3aefaacf/server/lib/deltacloud/models/network_interface.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/network_interface.rb b/server/lib/deltacloud/models/network_interface.rb
new file mode 100644
index 0000000..41d9816
--- /dev/null
+++ b/server/lib/deltacloud/models/network_interface.rb
@@ -0,0 +1,24 @@
+# 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.
+module Deltacloud
+class NetworkInterface < BaseModel
+
+ attr_accessor :name
+ attr_accessor :instance
+ attr_accessor :network
+ attr_accessor :ip_address
+
+end
+end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/3aefaacf/server/lib/deltacloud/models/subnet.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/subnet.rb b/server/lib/deltacloud/models/subnet.rb
new file mode 100644
index 0000000..d91a7a9
--- /dev/null
+++ b/server/lib/deltacloud/models/subnet.rb
@@ -0,0 +1,27 @@
+#
+# 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.
+
+module Deltacloud
+class Subnet < BaseModel
+
+ attr_accessor :name
+ attr_accessor :network
+ attr_accessor :address_block
+ attr_accessor :state
+ attr_accessor :type
+
+end
+end
[06/14] git commit: Network API rev 3 - Subnet Collection (routes)
Posted by ma...@apache.org.
Network API rev 3 - Subnet Collection (routes)
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/895a9c63
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/895a9c63
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/895a9c63
Branch: refs/heads/master
Commit: 895a9c63af9dc0f9969bf9b5fafa047d5b4ded09
Parents: 34a66ca
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:04:53 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
server/lib/deltacloud/collections/subnets.rb | 65 +++++++++++++++++++++
1 files changed, 65 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/895a9c63/server/lib/deltacloud/collections/subnets.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/subnets.rb b/server/lib/deltacloud/collections/subnets.rb
new file mode 100644
index 0000000..9d5fd74
--- /dev/null
+++ b/server/lib/deltacloud/collections/subnets.rb
@@ -0,0 +1,65 @@
+
+# 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.
+
+module Deltacloud::Collections
+ class Subnets < Base
+
+ include Deltacloud::Features
+
+ set :capability, lambda { |m| driver.respond_to? m }
+ check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
+
+ get '/subnets/new' do
+ respond_to do |format|
+ format.html { haml :"subnets/new" }
+ end
+ end
+
+
+ collection :subnets do
+
+ standard_show_operation
+ standard_index_operation
+
+ operation :create, :with_capability => :create_subnet do
+ param :network_id, :string, :required
+ param :address_block, :string, :required
+ control do
+ @subnet = driver.create_subnet(credentials, { :network_id => params[:network_id], :address_block => params[:address_block]})
+ respond_to do |format|
+ format.xml { haml :"subnets/show"}
+ format.html { haml :"subnets/show" }
+ format.json { xml_to_json("subnets/show")}
+ end
+ end
+ end
+
+ operation :destroy, :with_capability => :destroy_subnet do
+ control do
+ driver.destroy_subnet(credentials, params[:id])
+ status 204
+ respond_to do |format|
+ format.xml
+ format.json
+ format.html { redirect(subnets_url) }
+ end
+ end
+ end
+
+ end
+
+ end
+end
[13/14] git commit: Network API rev 3 - Mock Driver implementation
Posted by ma...@apache.org.
Network API rev 3 - Mock Driver implementation
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/83dcee9d
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/83dcee9d
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/83dcee9d
Branch: refs/heads/master
Commit: 83dcee9d39e92bb7dc59053ee88e44001e7f10e1
Parents: 1cef953
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:20:29 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
server/lib/deltacloud/drivers/base_driver.rb | 11 ++
server/lib/deltacloud/drivers/mock/mock_driver.rb | 102 +++++++++++++++-
2 files changed, 111 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/83dcee9d/server/lib/deltacloud/drivers/base_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index 85a2148..8e1c6df 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -259,6 +259,17 @@ module Deltacloud
addresses(credentials, opts).first if has_capability?(:addresses)
end
+ def network(credentials, opts={})
+ networks(credentials, opts).first if has_capability?(:networks)
+ end
+
+ def subnet(credentials, opts={})
+ subnets(credentials, opts).first if has_capability?(:subnets)
+ end
+
+ def network_interface(credentials, opts={})
+ network_interfaces(credentials, opts).first if has_capability?(:network_interfaces)
+ end
MEMBER_SHOW_METHODS = [ :realm, :image, :instance, :storage_volume, :bucket, :blob,
:key, :firewall ] unless defined?(MEMBER_SHOW_METHODS)
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/83dcee9d/server/lib/deltacloud/drivers/mock/mock_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 51a568c..feb3a01 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -227,7 +227,6 @@ module Deltacloud::Drivers::Mock
:actions => instance_actions_for((initial_state == "STARTED" ? "RUNNING" : initial_state)),
:user_data => opts[:user_data] ? Base64::decode64(opts[:user_data]) : nil
}
-
@client.store(:instances, instance)
Instance.new( instance )
end
@@ -254,6 +253,11 @@ module Deltacloud::Drivers::Mock
def destroy_instance(credentials, id)
check_credentials( credentials )
+ #also destroy the instance network_interface(s) if any:
+ inst = @client.load_collection(:instances, id)
+ inst[:network_interfaces].each do |network_interface|
+ destroy_network_interface(credentials, network_interface)
+ end
@client.destroy(:instances, id)
end
@@ -561,6 +565,100 @@ module Deltacloud::Drivers::Mock
metric
end
+ def networks(credentials, opts={})
+ check_credentials(credentials)
+ networks = @client.build_all(Network)
+ filter_on(networks, opts, :id)
+ end
+
+ def create_network(credentials, opts={})
+ check_credentials(credentials)
+ id = opts[:name] || "net_#{Time.now.to_i}"
+ net_hash = { :id => id,
+ :name => id,
+ :address_blocks => [opts[:address_block]],
+ :state => "UP"}
+ @client.store(:networks, net_hash)
+ Network.new(net_hash)
+ end
+
+ def destroy_network(credentials, network_id)
+ check_credentials(credentials)
+ net = network(credentials, {:id => network_id})
+ #also destroy subnets:
+ net.subnets.each do |sn|
+ destroy_subnet(credentials, sn)
+ end
+ @client.destroy(:networks, network_id)
+ end
+
+ def subnets(credentials, opts={})
+ check_credentials(credentials)
+ subnets = @client.build_all(Subnet)
+ filter_on(subnets, opts, :id)
+ end
+
+ def create_subnet(credentials, opts={})
+ check_credentials(credentials)
+ id = opts[:name] || "subnet_#{Time.now.to_i}"
+ snet_hash = { :id => id,
+ :name => id,
+ :address_block => opts[:address_block],
+ :network => opts[:network_id],
+ :state => "UP"}
+ @client.store(:subnets, snet_hash)
+ #also update network:
+ net = @client.load_collection(:networks, opts[:network_id])
+ net[:subnets] ||=[]
+ net[:subnets] << snet_hash[:id]
+ @client.store(:networks, net)
+ Subnet.new(snet_hash)
+ end
+
+ def destroy_subnet(credentials, subnet_id)
+ check_credentials(credentials)
+ snet = subnet(credentials, {:id => subnet_id})
+ #also update network:
+ net = @client.load_collection(:networks, snet.network)
+ net[:subnets].delete(subnet_id)
+ @client.store(:networks, net)
+ @client.destroy(:subnets, subnet_id)
+ end
+
+ def network_interfaces(credentials, opts={})
+ check_credentials(credentials)
+ network_interfaces = @client.build_all(NetworkInterface)
+ filter_on(network_interfaces, opts, :id)
+ end
+
+ def create_network_interface(credentials, opts={})
+ check_credentials(credentials)
+ id = opts[:name] || "nic_#{Time.now.to_i}"
+ nic_hash = {:id => id, :name => id, :instance => opts[:instance],
+ :network => opts[:network]}
+ #need an IP address from the subnet cidr range:
+ snet = @client.load_collection(:subnets, opts[:subnet])
+ cidr = IPAddr.new(snet[:address_block])
+ nic_hash[:ip_address] = cidr.to_range.to_a.sample.to_s #sloppy, choose random address - hey it's mock!
+ #need to update instance nics:
+ inst = @client.load_collection(:instances, opts[:instance])
+ inst[:network_interfaces] ||= []
+ inst[:network_interfaces] << id
+ @client.store(:instances, inst)
+ @client.store(:network_interfaces, nic_hash)
+ NetworkInterface.new(nic_hash)
+ end
+
+ def destroy_network_interface(credentials, nic_id)
+ check_credentials(credentials)
+ #need to update the instance too
+ nic = @client.load_collection(:network_interfaces, nic_id)
+ inst = @client.load_collection(:instances, nic[:instance])
+ inst[:network_interfaces].delete(nic_id)
+ @client.store(:instances, inst)
+ @client.destroy(:network_interfaces, nic_id)
+ end
+
private
def check_credentials(credentials)
@@ -647,7 +745,7 @@ module Deltacloud::Drivers::Mock
status 403
end
- on /BucketNotExist/ do
+ on /(BucketNotExist || NotFound)/ do
status 404
end
[12/14] git commit: Network API rev 3 - Network Views (haml)
Posted by ma...@apache.org.
Network API rev 3 - Network Views (haml)
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/765ee10a
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/765ee10a
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/765ee10a
Branch: refs/heads/master
Commit: 765ee10afe0594a1ccdaec95805f52e73a116a62
Parents: da7f912
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:17:06 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
server/views/networks/index.html.haml | 10 ++++++++++
server/views/networks/index.xml.haml | 4 ++++
server/views/networks/new.html.haml | 10 ++++++++++
server/views/networks/show.html.haml | 25 +++++++++++++++++++++++++
server/views/networks/show.xml.haml | 15 +++++++++++++++
5 files changed, 64 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/765ee10a/server/views/networks/index.html.haml
----------------------------------------------------------------------
diff --git a/server/views/networks/index.html.haml b/server/views/networks/index.html.haml
new file mode 100644
index 0000000..5eba1d5
--- /dev/null
+++ b/server/views/networks/index.html.haml
@@ -0,0 +1,10 @@
+=header "Networks" do
+ %a{ :href => url_for('networks/new'), :'data-icon' => :plus, :'data-role' => :button, :class => 'ui-btn-right'} Create new network
+
+%div{ :'data-role' => :content, :'data-theme' => 'c'}
+ %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' => 'a'}
+ - elements.each do |net|
+ %li
+ %a{ :href => network_url(net.id), :'data-ajax' => 'false'}
+ %img{ :class => 'ui-link-thumb', :src => '/images/cloud.png'}
+ %h3=net.id
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/765ee10a/server/views/networks/index.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/networks/index.xml.haml b/server/views/networks/index.xml.haml
new file mode 100644
index 0000000..59fa939
--- /dev/null
+++ b/server/views/networks/index.xml.haml
@@ -0,0 +1,4 @@
+!!!XML
+%networks
+ - @elements.each do |c|
+ = haml :'networks/show', :locals => { :network => c, :partial => true }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/765ee10a/server/views/networks/new.html.haml
----------------------------------------------------------------------
diff --git a/server/views/networks/new.html.haml b/server/views/networks/new.html.haml
new file mode 100644
index 0000000..0087259
--- /dev/null
+++ b/server/views/networks/new.html.haml
@@ -0,0 +1,10 @@
+=header "Create new network"
+
+%div{ :'data-role' => :content, :'data-theme' => 'c', :class => 'middle-dialog'}
+ %form{ :action => networks_url, :method => :post}
+ %div{ 'data-role' => :fieldcontain }
+ %p
+ %label{ :for => :address_block} CIDR Address block (optional):
+ %p
+ %input{ :type => :text, :id => :address_block, :name => :address_block, :value => '' }
+ %button{ :type => :submit} Create network
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/765ee10a/server/views/networks/show.html.haml
----------------------------------------------------------------------
diff --git a/server/views/networks/show.html.haml b/server/views/networks/show.html.haml
new file mode 100644
index 0000000..89a636e
--- /dev/null
+++ b/server/views/networks/show.html.haml
@@ -0,0 +1,25 @@
+=header "Network"
+=subheader @network.id
+
+%div{ :'data-role' => :content, :'data-theme' => 'c'}
+ %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' => 'd'}
+ %li{ :'data-role' => 'list-divider'} Identifier
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=@network.id
+ %li{ :'data-role' => 'list-divider'} Name
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=@network.name
+ %li{ :'data-role' => 'list-divider'} State
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=@network.state
+ %li{ :'data-role' => 'list-divider'} Address Blocks
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=(@network.address_blocks ? @network.address_blocks.join(",") : nil)
+ %li{ :'data-role' => 'list-divider'} Subnets
+ -@network.subnets.each do |sn|
+ %li
+ %a{ :href => subnet_url(sn.strip), :'data-ajax'=>'false' }=sn
+ %li{ :'data-role' => 'list-divider'} Actions
+ %li
+ %div{ :'data-role' => 'controlgroup', :'data-type' => "horizontal" }
+ =link_to_action "Destroy", destroy_network_url(@network.id), :delete
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/765ee10a/server/views/networks/show.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/networks/show.xml.haml b/server/views/networks/show.xml.haml
new file mode 100644
index 0000000..16f9e41
--- /dev/null
+++ b/server/views/networks/show.xml.haml
@@ -0,0 +1,15 @@
+- unless defined?(partial)
+ !!! XML
+%network{ :href => network_url(network.id), :id => network.id }
+ %name=network.name
+ %state<
+ =network.state
+ %address_blocks
+ - network.address_blocks.each do |addr_block|
+ %address_block=addr_block
+ %subnets
+ - (network.subnets || []).each do |subnet|
+ %subnet{:href => subnet_url(subnet), :id=>subnet}
+ %actions
+ - if driver.respond_to?(:destroy_network)
+ %link{ :rel => "destroy", :method => "delete", :href => destroy_network_url(network.id)}
[05/14] git commit: Network API rev 3 - Network Collection (routes)
Posted by ma...@apache.org.
Network API rev 3 - Network Collection (routes)
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/34a66ca1
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/34a66ca1
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/34a66ca1
Branch: refs/heads/master
Commit: 34a66ca1b305d2f341cfe48f396e7aac64aa2ffc
Parents: 8c9ff36
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:00:21 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
server/lib/deltacloud/collections/networks.rb | 63 ++++++++++++++++++++
1 files changed, 63 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/34a66ca1/server/lib/deltacloud/collections/networks.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/networks.rb b/server/lib/deltacloud/collections/networks.rb
new file mode 100644
index 0000000..34c7fad
--- /dev/null
+++ b/server/lib/deltacloud/collections/networks.rb
@@ -0,0 +1,63 @@
+# 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.
+
+module Deltacloud::Collections
+ class Networks < Base
+
+ include Deltacloud::Features
+
+ set :capability, lambda { |m| driver.respond_to? m }
+ check_features :for => lambda { |c, f| driver.class.has_feature?(c, f) }
+
+ get '/networks/new' do
+ respond_to do |format|
+ format.html { haml :"networks/new" }
+ end
+ end
+
+ collection :networks do
+
+ standard_show_operation
+ standard_index_operation
+
+ operation :create, :with_capability => :create_network do
+ param :address_block, :string, :optional
+ param :name, :string, :optional
+ control do
+ @network = driver.create_network(credentials, { :address_block => params[:address_block]})
+ respond_to do |format|
+ format.xml { haml :"networks/show" }
+ format.html { haml :"networks/show" }
+ format.json { xml_to_json("networks/show")}
+ end
+ end
+ end
+
+ operation :destroy, :with_capability => :destroy_network do
+ control do
+ driver.destroy_network(credentials, params[:id])
+ status 204
+ respond_to do |format|
+ format.xml
+ format.json
+ format.html { redirect(networks_url) }
+ end
+ end
+ end
+
+ end
+
+ end
+end
[14/14] git commit: Network API rev 3 - EC2 Driver implementation
Posted by ma...@apache.org.
Network API rev 3 - EC2 Driver implementation
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/9c094964
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/9c094964
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/9c094964
Branch: refs/heads/master
Commit: 9c094964b0cc285d98496f6a797bc4f649badece
Parents: c1c84bc
Author: marios <ma...@redhat.com>
Authored: Fri Apr 26 18:28:33 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:28:33 2013 +0300
----------------------------------------------------------------------
server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 130 ++++++++++++++++--
1 files changed, 119 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/9c094964/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 62c72cc..f258dfb 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -268,14 +268,8 @@ module Deltacloud
if opts[:metrics] and !opts[:metrics].empty?
instance_options[:monitoring_enabled] = true
end
- if opts[:realm_id]
- az, sn = opts[:realm_id].split(":")
- if sn
- instance_options[:subnet_id] = sn
- else
- instance_options[:availability_zone] = az
- end
- end
+ instance_options[:availability_zone] = opts[:realm_id] if opts[:realm_id]
+ instance_options[:subnet_id] = opts[:subnet_id] if opts[:subnet_id] #FIXME should we fail if no :network_id ? don't need it but need consistency in API...
instance_options[:key_name] = opts[:keyname] if opts[:keyname]
instance_options[:instance_type] = opts[:hwp_id] if opts[:hwp_id] && opts[:hwp_id].length > 0
firewalls = opts.inject([]){|res, (k,v)| res << v if k =~ /firewalls\d+$/; res}
@@ -835,6 +829,91 @@ module Deltacloud
end
end
+ #Deltacloud Networks == Amazon VPC
+ def networks(credentials, opts={})
+ ec2 = new_client(credentials)
+ networks = []
+ safely do
+ subnets = subnets(credentials) #get all subnets once
+ (opts[:id] ? ec2.describe_vpcs(opts[:id]) : ec2.describe_subnets).each do |vpc|
+ vpc_subnets = subnets.inject([]){|res,cur| res<<cur if cur.network==vpc[:vpc_id] ;res} #collect subnets for this.network
+ networks << convert_vpc(vpc, vpc_subnets)
+ end
+ end
+ networks = filter_on(networks, :id, opts)
+ end
+
+ def create_network(credentials, opts={})
+ ec2 = new_client(credentials)
+ safely do
+ network = ec2.create_vpc(opts[:address_block]).first
+ convert_vpc(network)
+ end
+ end
+
+ def destroy_network(credentials, network_id)
+ ec2 = new_client(credentials)
+ safely do
+ ec2.delete_vpc(network_id)
+ end
+ end
+
+ def subnets(credentials, opts={})
+ ec2 = new_client(credentials)
+ subnets = []
+ safely do
+ (opts[:id] ? ec2.describe_subnets(opts[:id]) : ec2.describe_subnets).each do |sn|
+ subnets << convert_subnet(sn)
+ end
+ end
+ subnets = filter_on(subnets, :id, opts)
+ end
+
+ def create_subnet(credentials, opts={})
+ ec2 = new_client(credentials)
+ safely do
+ subnet = ec2.create_subnet(opts[:network_id], opts[:address_block]).first
+ convert_subnet(subnet)
+ end
+ end
+
+ def destroy_subnet(credentials, subnet_id)
+ ec2 = new_client(credentials)
+ safely do
+ ec2.delete_subnet(subnet_id)
+ end
+ end
+
+ def network_interfaces(credentials, opts={})
+ ec2 = new_client(credentials)
+ nics = []
+ safely do
+ (opts[:id] ? ec2.describe_network_interfaces(opts[:id]) : ec2.describe_network_interfaces).each do |nic|
+ nics << convert_nic(nic)
+ end
+ end
+ filter_on(nics, :id, opts)
+ end
+
+ def create_network_interface(credentials, opts={})
+ ec2 = new_client(credentials)
+ safely do
+ #create a nic:
+ nic = ec2.create_network_interface(opts[:network])
+ #retrieve the instance to determine appropriate device_index?
+ #attach it:
+ ec2.attach_network_interface(nic[:network_interface_id], opts[:instance], 0)
+ convert_nic(nic)
+ end
+ end
+
+ def destroy_network_interface(credentials, nic_id)
+ client = new_client(credentials)
+ safely do
+ client.delete_network_interface(nic_id)
+ end
+ end
+
def providers(credentials, opts={})
ec2 = new_client(credentials)
@providers ||= ec2.describe_regions.map{|r| Provider.new( {:id=>r, :name=>r,
@@ -966,7 +1045,7 @@ module Deltacloud
unless instance[:subnet_id].empty?
realm_id = "#{realm_id}:#{instance[:subnet_id]}"
end
- Instance.new(
+ inst_params = {
:id => instance[:aws_instance_id],
:name => instance[:aws_image_id],
:state => convert_state(instance[:aws_state]),
@@ -981,8 +1060,11 @@ module Deltacloud
:private_addresses => [InstanceAddress.new(instance[:private_dns_name], :type => :hostname)],
:firewalls => instance[:aws_groups],
:storage_volumes => instance[:block_device_mappings].map{|vol| {vol.values.first=>vol.keys.first } },
- :create_image => can_create_image
- )
+ :create_image => can_create_image }
+# if instance[:vpc_id]
+# inst_params.merge!(:network_bindings => [{:network=>instance[:vpc_id], :subnet=>instance[:subnet_id], :ip_address=> instance[:aws_private_ip_address]}])
+# end
+ Instance.new(inst_params)
end
def convert_key(key)
@@ -1159,6 +1241,32 @@ module Deltacloud
end
end
+ def convert_vpc(vpc, subnets=[])
+ addr_blocks = subnets.inject([]){|res,cur| res << cur.address_block ; res}
+ Network.new({ :id => vpc[:vpc_id],
+ :name => vpc[:vpc_id],
+ :state=> (vpc[:state] == "available" ? "UP" : "DOWN"),
+ :subnets => subnets.inject([]){|res,cur| res << cur.id ;res},
+ :address_blocks=> (addr_blocks.empty? ? [vpc[:cidr_block]] : addr_blocks) })
+ end
+
+ def convert_subnet(subnet)
+ Subnet.new({ :id => subnet[:subnet_id],
+ :name => subnet[:subnet_id],
+ :network =>subnet[:vpc_id],
+ :address_block => subnet[:cidr_block],
+ :state => (subnet[:state] == "available" ? "UP" : "DOWN" )})
+ end
+
+ def convert_nic(nic, instance_id=nil)
+ instance = instance_id || (nic[:attachment] ? nic[:attachment][:instance_id] : nil)
+ NetworkInterface.new({ :id => nic[:network_interface_id],
+ :name => nic[:network_interface_id],
+ :instance => instance,
+ :ip_address => nic[:private_ip_address]
+ })
+ end
+
exceptions do
on /root device is not supported for the instance/ do
[09/14] git commit: Network API rev 3 - NetworkInterface Views (haml)
Posted by ma...@apache.org.
Network API rev 3 - NetworkInterface Views (haml)
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/da7f912d
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/da7f912d
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/da7f912d
Branch: refs/heads/master
Commit: da7f912d846381f58e7877f4694cbcc4fa022d67
Parents: 3aefaac
Author: marios <ma...@redhat.com>
Authored: Fri Apr 12 12:15:47 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Apr 26 18:01:55 2013 +0300
----------------------------------------------------------------------
server/views/network_interfaces/index.html.haml | 10 ++++++
server/views/network_interfaces/index.xml.haml | 4 ++
server/views/network_interfaces/new.html.haml | 20 ++++++++++++
server/views/network_interfaces/show.html.haml | 29 ++++++++++++++++++
server/views/network_interfaces/show.xml.haml | 13 ++++++++
5 files changed, 76 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/da7f912d/server/views/network_interfaces/index.html.haml
----------------------------------------------------------------------
diff --git a/server/views/network_interfaces/index.html.haml b/server/views/network_interfaces/index.html.haml
new file mode 100644
index 0000000..d0bfed7
--- /dev/null
+++ b/server/views/network_interfaces/index.html.haml
@@ -0,0 +1,10 @@
+=header "Network Interfaces" do
+ %a{ :href => url_for('network_interfaces/new'), :'data-icon' => :plus, :'data-role' => :button, :class => 'ui-btn-right'} Create new Network Interface
+
+%div{ :'data-role' => :content, :'data-theme' => 'c'}
+ %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' => 'a'}
+ - @elements.each do |nic|
+ %li
+ %a{ :href => network_interface_url(nic.id), :'data-ajax' => 'false'}
+ %img{ :class => 'ui-link-thumb', :src => '/images/cloud.png'}
+ %h3=nic.id
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/da7f912d/server/views/network_interfaces/index.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/network_interfaces/index.xml.haml b/server/views/network_interfaces/index.xml.haml
new file mode 100644
index 0000000..2f012d3
--- /dev/null
+++ b/server/views/network_interfaces/index.xml.haml
@@ -0,0 +1,4 @@
+!!!XML
+%network_interfaces
+ - @elements.each do |c|
+ = haml :'network_interfaces/show', :locals => { :network_interface => c, :subnets => subnets, :partial => true }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/da7f912d/server/views/network_interfaces/new.html.haml
----------------------------------------------------------------------
diff --git a/server/views/network_interfaces/new.html.haml b/server/views/network_interfaces/new.html.haml
new file mode 100644
index 0000000..608b820
--- /dev/null
+++ b/server/views/network_interfaces/new.html.haml
@@ -0,0 +1,20 @@
+=header "Create new Network Interface"
+
+%div{ :'data-role' => :content, :'data-theme' => 'c', :class => 'middle-dialog'}
+ %form{ :action => network_interfaces_url, :method => :post}
+ %div{ 'data-role' => :fieldcontain }
+ %p
+ %label{ :for => :name} Name (optional):
+ %p
+ %input{ :type => :text, :id => :name, :name => :name, :value => '' }
+ %div{ 'data-role' => :fieldcontain }
+ %label{ :for => :instance, :class => 'ui-input-text'} Instance for attachment:
+ %select{:name => 'instance', :'data-native-menu' => "true" }
+ - instances.each do |inst|
+ %option{ :value => inst.id } #{inst.id}
+ %div{ 'data-role' => :fieldcontain }
+ %label{ :for => :network, :class => 'ui-input-text'} Network to attach to:
+ %select{:name => 'network', :'data-native-menu' => "true" }
+ - networks.each do |net|
+ %option{ :value => net.id } #{net.id}
+ %button{ :type => :submit} Create Network Interface
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/da7f912d/server/views/network_interfaces/show.html.haml
----------------------------------------------------------------------
diff --git a/server/views/network_interfaces/show.html.haml b/server/views/network_interfaces/show.html.haml
new file mode 100644
index 0000000..877dd0f
--- /dev/null
+++ b/server/views/network_interfaces/show.html.haml
@@ -0,0 +1,29 @@
+=header "Network Interface"
+=subheader network_interface.id
+
+%div{ :'data-role' => :content, :'data-theme' => 'c'}
+ %ul{ :'data-role' => :listview , :'data-inset' => :true, :'data-divider-theme' => 'd'}
+ %li{ :'data-role' => 'list-divider'} Identifier
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=network_interface.id
+ %li{ :'data-role' => 'list-divider'} Name
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=network_interface.name
+ %li{ :'data-role' => 'list-divider'} IP Address
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=network_interface.ip_address
+ -if subnets
+ %li{ :'data-role' => 'list-divider'} Network (subnet)
+ %li
+ %a{ :href => subnet_url(network_interface.network), :'data-ajax'=>'false' }=network_interface.network
+ -else
+ %li{ :'data-role' => 'list-divider'} Network
+ %li
+ %a{ :href => network_url(network_interface.network), :'data-ajax'=>'false' }=network_interface.network
+ %li{ :'data-role' => 'list-divider'} Instance
+ %li
+ %a{ :href => instance_url(network_interface.instance), :'data-ajax'=>'false' }=network_interface.instance
+ %li{ :'data-role' => 'list-divider'} Actions
+ %li
+ %div{ :'data-role' => 'controlgroup', :'data-type' => "horizontal" }
+ =link_to_action "Destroy", destroy_network_interface_url(network_interface.id), :delete
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/da7f912d/server/views/network_interfaces/show.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/network_interfaces/show.xml.haml b/server/views/network_interfaces/show.xml.haml
new file mode 100644
index 0000000..995cb7b
--- /dev/null
+++ b/server/views/network_interfaces/show.xml.haml
@@ -0,0 +1,13 @@
+- unless defined?(partial)
+ !!! XML
+%network_interface{ :href => network_interface_url(network_interface.id), :id => network_interface.id }
+ %name=network_interface.name
+ %ip_address=network_interface.ip_address
+ -if subnets
+ %network{:href => subnet_url(network_interface.network), :rel => "subnet", :id => network_interface.network} #{network_interface.network}
+ -else
+ %network{:href => network_url(network_interface.network), :rel => "network", :id => network_interface.network} #{network_interface.network}
+ %instance{:href => instance_url(network_interface.instance), :id=>network_interface.instance} #{network_interface.instance}
+ %actions
+ - if driver.respond_to?(:destroy_network_interface)
+ %link{ :rel => "destroy", :method => "delete", :href => destroy_network_interface_url(network_interface.id)}