1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Add network publishing functionality to OCCI

This commit is contained in:
Daniel Molina 2010-12-02 19:21:59 +01:00
parent 1cd061babc
commit 40f282cd8a
5 changed files with 87 additions and 4 deletions

View File

@ -36,18 +36,22 @@ Usage:
Commands:
create <occi xml file>
* create <occi xml file>
creates a new virtual network described by the provided
<occi xml file>
list
* list
lists available virtual networks
show <network id>
* show <network id>
retrieves the OCCI XML representation of the virtual network
identified by <network id>
delete <network id>
* update <occi xml file>
updates the representation of the network resource represented by the
provided <occi xml file>
* delete <network id>
deletes the virtual network idenfitied by <network id>
@ -164,6 +168,16 @@ case ARGV[0].downcase
rc = occi_client.get_network(network_id)
when 'update'
network_xml = ARGV[1]
if !network_xml || !File.exists?(network_xml)
puts "#{cmd_name} update: missing OCCI-XML or file not found"
exit -1
end
rc = occi_client.put_network(network_xml)
when 'delete'
network_id = ARGV[1]

View File

@ -352,6 +352,38 @@ module OCCIClient
end
end
######################################################################
# Puts a new Network representation in order to change its state
# :xmlfile Network OCCI xml representation
######################################################################
def put_network(xmlfile)
xml = File.read(xmlfile)
vnet_info = REXML::Document.new(xml).root
if vnet_info.elements['ID'] == nil
return CloudClient::Error.new("Can not find NETWORK_ID")
end
vnet_id = vnet_info.elements['ID'].text
url = URI.parse(@endpoint+'/network/' + vnet_id)
req = Net::HTTP::Put.new(url.path)
req.body = xml
req.basic_auth @occiauth[0], @occiauth[1]
res = CloudClient::http_start(url, @timeout) do |http|
http.request(req)
end
if CloudClient::is_error?(res)
return res
else
return res.body
end
end
######################################################################
# :id VM identifier
######################################################################

View File

@ -293,6 +293,34 @@ class OCCIServer < CloudServer
return "", 204
end
# Updates a NETWORK resource
# request:: _Hash_ hash containing the data of the request
# [return] _String_,_Integer_ Update confirmation msg or error,
# status code
def put_network(request, params)
xmldoc = XMLElement.build_xml(request.body, 'NETWORK')
vnet_info = XMLElement.new(xmldoc) if xmldoc != nil
vnet = VirtualNetworkOCCI.new(
VirtualNetwork.build_xml(params[:id]),
get_client(request.env))
rc = vnet.info
return rc, 400 if OpenNebula.is_error?(rc)
if vnet_info['PUBLIC'] == 'YES'
rc = vnet.publish
return rc, 400 if OpenNebula.is_error?(rc)
elsif vnet_info['PUBLIC'] == 'NO'
rc = vnet.unpublish
return rc, 400 if OpenNebula.is_error?(rc)
end
# --- Prepare XML Response ---
vnet.info
return to_occi_xml(vnet, 202)
end
############################################################################
# STORAGE Methods

View File

@ -30,6 +30,7 @@ class VirtualNetworkOCCI < VirtualNetwork
<% if self['TEMPLATE/NETWORK_SIZE'] %>
<SIZE><%= self['TEMPLATE/NETWORK_SIZE'] %></SIZE>
<% end %>
<PUBLIC><%= self['PUBLIC'] == "0" ? "NO" : "YES"%></PUBLIC>
</NETWORK>
}
@ -39,6 +40,9 @@ class VirtualNetworkOCCI < VirtualNetwork
<% if @vnet_info['DESCRIPTION'] != nil %>
DESCRIPTION = "<%= @vnet_info['DESCRIPTION'] %>"
<% end %>
<% if @vnet_info['PUBLIC'] != nil %>
PUBLIC = "<%= @vnet_info['PUBLIC'] %>"
<% end %>
<% if @bridge %>
BRIDGE = <%= @bridge %>
<% end %>

View File

@ -151,6 +151,11 @@ delete '/network/:id' do
treat_response(result,rc)
end
put '/network/:id' do
result,rc = $occi_server.put_network(request, params)
treat_response(result,rc)
end
get '/storage/:id' do
result,rc = $occi_server.get_storage(request, params)
treat_response(result,rc)