Skip to content

Commit

Permalink
Merge branch 'master' of ssh://git.opennebula.org/ogf-occi
Browse files Browse the repository at this point in the history
Conflicts:
	.idea/misc.xml
  • Loading branch information
pkasprzak committed Feb 21, 2012
2 parents e9b680f + c209d05 commit 79a106b
Show file tree
Hide file tree
Showing 14 changed files with 444 additions and 353 deletions.
317 changes: 201 additions & 116 deletions .idea/workspace.xml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion config.ru
@@ -1,6 +1,7 @@
$: << 'lib'

require 'rubygems'
require 'sinatra'
require 'occi/occi-server.rb'

run Sinatra::Application
run OCCIServer.new
18 changes: 10 additions & 8 deletions etc/occi-server.conf
@@ -1,25 +1,27 @@
BACKEND=dummy
#BACKEND=dummy
BACKEND=opennebula

LOG_LEVEL=debug

# important, server needs to end with a /
SERVER=http://localhost/
PORT=3000

ONE_XMLRPC=http://localhost:2633/RPC2
ONE_XMLRPC=http://134.76.9.66:2633/RPC2

TEMPLATE_LOCATION=etc/occi_one_templates/

ONE_USER=oneadmin
ONE_PASSWORD=oneadmin
ONE_USER=occi
ONE_PASSWORD=r8YAeyYdeG

ONE_IMAGE_TMP_DIR=/tmp

VNC_PROXY_BASE_PORT=0
NOVNC_PATH=public/novnc
#VNC_PROXY_BASE_PORT=0
#NOVNC_PATH=public/novnc

# set webinterface to enabled/disabled
WEBINTERFACE=enabled

#USERNAME=occi
#PASSWORD=56DPmCAJzeIICptW
# Enable NFS storage support
NFS_SUPPORT=true

5 changes: 3 additions & 2 deletions lib/occi/StateMachine.rb
Expand Up @@ -95,7 +95,8 @@ def set_state(state)
# Return backend method symbol to handle transition or nil if not defined
def transition(action)
raise "Transition for action [#{action}] not supported in current state: #{@current_state}" if !check_transition(action)
@current_state = @current_state.get_target_state(action)
# TODO: state changes should only be triggered by the backend!
#@current_state = @current_state.get_target_state(action)
# Invoke event callback if defined
return @options[:on_transition] if @options.has_key?(:on_transition)
return nil
Expand All @@ -116,4 +117,4 @@ def to_s()
$log.debug("Current state: " + @current_state)
end
end
end
end
2 changes: 1 addition & 1 deletion lib/occi/backend/Manager.rb
Expand Up @@ -126,7 +126,7 @@ def self.delegate_action(backend, action, parameters, resource)
signal_resource(backend, operation, resource, parameters)

state_machine.transition(action)
signal_resource(backend, OCCI::Backend::RESOURCE_UPDATE_STATE)
signal_resource(backend, OCCI::Backend::RESOURCE_UPDATE_STATE,resource)

rescue OCCI::BackendError
$log.error("Action invocation failed!")
Expand Down
73 changes: 36 additions & 37 deletions lib/occi/backend/opennebula/Compute.rb
Expand Up @@ -31,12 +31,16 @@ module Compute
TEMPLATECOMPUTERAWFILE = 'occi_one_template_compute.erb'

# ---------------------------------------------------------------------------------------------------------------------
private
# private
# ---------------------------------------------------------------------------------------------------------------------

# ---------------------------------------------------------------------------------------------------------------------
# PARSE OPENNEBULA COMPUTE OBJECT
def self.compute_parse_backend_object(backend_object)
def compute_parse_backend_object(backend_object)

backend_object.info
# $log.debug("*** compute object: " + backend_object.to_xml)

if backend_object['TEMPLATE/OCCI_ID'].nil?
raise "no backend ID found" if backend_object.id.nil?
occi_id = self.generate_occi_id(OCCI::Infrastructure::Compute::KIND, backend_object.id.to_s)
Expand Down Expand Up @@ -73,27 +77,22 @@ def self.compute_parse_backend_object(backend_object)
else

# ALI start
id= backend_object.id
$log.debug("--- Monitoring start backend id : #{id}")
watch_client = OneWatchClient::VmWatchClient.new
monitoring_resources = [ :cpu_usage,
:mem_usage,
:net_rx,
:net_tx
]
vm_monitoring = watch_client.resource_monitoring(id.to_i,monitoring_resources)
occi_object.mixins.each do |mixin|
# attributes['cpu'] = vm_monitoring[:monitoring][:cpu_usage][4][1] if mixin.term == "rxtot"
# attributes['memory'] = vm_monitoring[:monitoring][:mem_usage][4][1] if mixin.term == "memory"
# attributes['net_rx'] = vm_monitoring[:monitoring][:net_rx][4][1] if mixin.term == "net_rx"
# attributes['net_tx'] = vm_monitoring[:monitoring][:net_tx][4][1] if mixin.term == "net_tx"
# attributes['net_tx'] = vm_monitoring[:monitoring][:net_tx][4][1] if mixin.term == "net_tx"
attributes['cpu'] = vm_monitoring[:monitoring][:cpu_usage].join(',') if mixin.term == "rxtot"
attributes['memory'] = vm_monitoring[:monitoring][:mem_usage].join(',') if mixin.term == "memory"
attributes['net_rx'] = vm_monitoring[:monitoring][:net_rx].join(',') if mixin.term == "net_rx"
attributes['net_tx'] = vm_monitoring[:monitoring][:net_tx].join(',') if mixin.term == "net_tx"
attributes['net_tx'] = (vm_monitoring[:monitoring][:net_tx]).join(',') if mixin.term == "net_tx"
end
# id= backend_object.id
# $log.debug("--- Monitoring start backend id : #{id}")
# watch_client = OneWatchClient::VmWatchClient.new
# monitoring_resources = [ :cpu_usage,
# :mem_usage,
# :net_rx,
# :net_tx
# ]
# vm_monitoring = watch_client.resource_monitoring(id.to_i,monitoring_resources)
# occi_object.mixins.each do |mixin|
# attributes['cpu'] = vm_monitoring[:monitoring][:cpu_usage].join(',') if mixin.term == "rxtot"
# attributes['memory'] = vm_monitoring[:monitoring][:mem_usage].join(',') if mixin.term == "memory"
# attributes['net_rx'] = vm_monitoring[:monitoring][:net_rx].join(',') if mixin.term == "net_rx"
# attributes['net_tx'] = vm_monitoring[:monitoring][:net_tx].join(',') if mixin.term == "net_tx"
# attributes['net_tx'] = (vm_monitoring[:monitoring][:net_tx]).join(',') if mixin.term == "net_tx"
# end
# ALI end

occi_object.attributes.merge!(attributes)
Expand Down Expand Up @@ -149,7 +148,7 @@ def self.compute_parse_backend_object(backend_object)

# ---------------------------------------------------------------------------------------------------------------------
# PARSE OPENNEBULA DEPENDENCIES TO E.G. STORAGE AND NETWORK LINKS
def self.compute_parse_links(occi_object, backend_object)
def compute_parse_links(occi_object, backend_object)
# create links for all storage instances
backend_object['TEMPLATE/DISK/IMAGE_ID'].each do |image_id|
attributes = {}
Expand Down Expand Up @@ -221,16 +220,16 @@ def self.compute_parse_links(occi_object, backend_object)

# ---------------------------------------------------------------------------------------------------------------------
# ALI: Monitoring
def monitor(parameter)
backend_object = VirtualMachine.new(VirtualMachine.build_xml(@backend[:id]), $backend.one_client)
backend_object.info
occi_object = OCCI::Backend::OpenNebula::Compute.parse_backend_object(backend_object)
monitoring_resources = [ :cpu] if parameter == "cpu"
monitoring_resources = [ :memory] if parameter == "memory"
monitoring_resources = [ :net_rx] if parameter == "net_rx"
monitoring_resources = [:net_tx] if parameter == "net_tx"
occi_object.attributes["compute.cpu.value"]= watch_client.resource_monitoring(occi_object.backend[:id],monitoring_resources)
end
# def monitor(parameter)
# backend_object = VirtualMachine.new(VirtualMachine.build_xml(@backend[:id]), $backend.one_client)
# backend_object.info
# occi_object = parse_backend_object(backend_object)
# monitoring_resources = [ :cpu] if parameter == "cpu"
# monitoring_resources = [ :memory] if parameter == "memory"
# monitoring_resources = [ :net_rx] if parameter == "net_rx"
# monitoring_resources = [:net_tx] if parameter == "net_tx"
# occi_object.attributes["compute.cpu.value"]= watch_client.resource_monitoring(occi_object.backend[:id],monitoring_resources)
# end

# ---------------------------------------------------------------------------------------------------------------------
public
Expand Down Expand Up @@ -324,7 +323,7 @@ def compute_refresh(compute)

# backend_object.info

occi_object = OCCI::Backend::OpenNebula.compute_parse_backend_object(backend_object)
occi_object = compute_parse_backend_object(backend_object)
if occi_object.nil?
$log.debug("Problems refreshing backend object")
else
Expand Down Expand Up @@ -369,7 +368,7 @@ def compute_delete(compute)
def compute_register_all_instances
backend_object_pool = VirtualMachinePool.new(@one_client)
# backend_object_pool.info
backend_object_pool.info(INFO_ACL, -1, -1, OpenNebula::VirtualMachinePool::INFO_ALL_VM)
backend_object_pool.info(OCCI::Backend::OpenNebula::OpenNebula::INFO_ACL, -1, -1, OpenNebula::VirtualMachinePool::INFO_NOT_DONE)
compute_register_all_objects(backend_object_pool)
end

Expand All @@ -387,7 +386,7 @@ def compute_register_all_objects(backend_object_pool, template = false)
occi_objects = []
backend_object_pool.each do |backend_object|
$log.debug("ONE compute object: #{backend_object}")
occi_object = OCCI::Backend::OpenNebula.compute_parse_backend_object(backend_object)
occi_object = compute_parse_backend_object(backend_object)
if occi_object.nil?
$log.debug("Error creating occi resource from backend")
else
Expand Down
16 changes: 9 additions & 7 deletions lib/occi/backend/opennebula/Network.rb
Expand Up @@ -31,11 +31,11 @@ module Network
TEMPLATENETWORKRAWFILE = 'occi_one_template_network.erb'

# ---------------------------------------------------------------------------------------------------------------------
private
# private
# ---------------------------------------------------------------------------------------------------------------------

# ---------------------------------------------------------------------------------------------------------------------
def self.network_parse_backend_object(backend_object)
def network_parse_backend_object(backend_object)
if backend_object['TEMPLATE/OCCI_ID'].nil?
raise "no backend ID found" if backend_object.id.nil?
occi_id = self.generate_occi_id(OCCI::Infrastructure::Network::KIND, backend_object.id.to_s)
Expand All @@ -53,7 +53,7 @@ def self.network_parse_backend_object(backend_object)
attributes['occi.core.summary'] = backend_object['TEMPLATE/DESCRIPTION']
# attributes['opennebula.network.bridge'] = vnet['TEMPLATE/BRIDGE']
# attributes['opennebula.network.public'] = vnet['TEMPLATE/PUBLIC']
$log.debug("*** object: " + backend_object.to_xml)
# $log.debug("*** object: " + backend_object.to_xml)
if backend_object['TEMPLATE/TYPE'].downcase == 'fixed'
mixins << OCCI::Backend::ONE::Network::MIXIN
# attributes['opennebula.network.leases'] = backend_object['TEMPLATE/LEASES']
Expand Down Expand Up @@ -110,9 +110,9 @@ def network_deploy(network)
def network_refresh(network)
backend_object = VirtualNetwork.new(VirtualNetwork.build_xml(network.backend[:id]), @one_client)

# backend_object.info
backend_object.info

occi_object = OCCI::Backend::OpenNebula.network_parse_backend_object(backend_object)
occi_object = network_parse_backend_object(backend_object)

if occi_object.nil? then
$log.warn("Problem refreshing network with backend id #{network.backend[:id]}")
Expand Down Expand Up @@ -144,10 +144,12 @@ def network_delete(network)
# ---------------------------------------------------------------------------------------------------------------------
def network_register_all_instances
occi_objects = []
backend_object_pool=VirtualNetworkPool.new(@one_client, INFO_ACL)
backend_object_pool=VirtualNetworkPool.new(@one_client, OCCI::Backend::OpenNebula::OpenNebula::INFO_ACL)
backend_object_pool.info
backend_object_pool.each do |backend_object|
occi_object = OCCI::Backend::OpenNebula.network_parse_backend_object(backend_object)
# $log.debug("*** network_register_all_instances: backend_object: " + backend_object.to_xml)
backend_object.info
occi_object = network_parse_backend_object(backend_object)
if occi_object.nil?
$log.debug("Error creating network from backend")
else
Expand Down
17 changes: 9 additions & 8 deletions lib/occi/backend/opennebula/OpenNebula.rb
Expand Up @@ -46,17 +46,18 @@ module OpenNebula

# ---------------------------------------------------------------------------------------------------------------------
class OpenNebula

include Compute
include Network
include Storage


# The ACL level to be used when querying resource in OpenNebula:
# - INFO_ALL returns all resources and works only when running under the oneadmin account
# - INFO_GROUP returns the resources of the account + his group (= default)
# - INFO_MINE returns only the resources of the account
INFO_ACL = OpenNebula::Pool::INFO_GROUP


include Compute
include Network
include Storage


# Operation mappings

OPERATIONS = {}
Expand Down Expand Up @@ -124,7 +125,7 @@ class OpenNebula
end

# ---------------------------------------------------------------------------------------------------------------------
private
# private
# ---------------------------------------------------------------------------------------------------------------------

# ---------------------------------------------------------------------------------------------------------------------
Expand All @@ -137,7 +138,7 @@ def check_rc(rc)

# ---------------------------------------------------------------------------------------------------------------------
# Generate a new occi id for resources created directly in OpenNebula using a seed id and the kind identifier
def self.generate_occi_id(kind, seed_id)
def generate_occi_id(kind, seed_id)
# Use strings as kind ids
kind = kind.type_identifier if kind.kind_of?(OCCI::Core::Kind)
return UUIDTools::UUID.sha1_create(UUIDTools::UUID_DNS_NAMESPACE, "#{kind}:#{seed_id}").to_s
Expand Down
10 changes: 5 additions & 5 deletions lib/occi/backend/opennebula/Storage.rb
Expand Up @@ -31,11 +31,11 @@ module Storage
TEMPLATESTORAGERAWFILE = 'occi_one_template_storage.erb'

# ---------------------------------------------------------------------------------------------------------------------
private
# private
# ---------------------------------------------------------------------------------------------------------------------

# ---------------------------------------------------------------------------------------------------------------------
def self.storage_parse_backend_object(backend_object)
def storage_parse_backend_object(backend_object)

if backend_object['TEMPLATE/OCCI_ID'].nil?
raise "no backend ID found" if backend_object.id.nil?
Expand Down Expand Up @@ -140,7 +140,7 @@ def storage_refresh(storage)

# backend_object.info

occi_object = OCCI::Backend::OpenNebula.storage_parse_backend_object(backend_object)
occi_object = storage_parse_backend_object(backend_object)

if occi_object.nil? then
$log.warn("Problem refreshing storage with backend id #{storage.backend[:id]}")
Expand All @@ -158,10 +158,10 @@ def storage_refresh(storage)
# ---------------------------------------------------------------------------------------------------------------------
def storage_register_all_instances
occi_objects = []
backend_object_pool=ImagePool.new(@one_client, INFO_ACL)
backend_object_pool=ImagePool.new(@one_client, OCCI::Backend::OpenNebula::OpenNebula::INFO_ACL)
backend_object_pool.info
backend_object_pool.each do |backend_object|
occi_object = OCCI::Backend::OpenNebula.storage_parse_backend_object(backend_object)
occi_object = storage_parse_backend_object(backend_object)
if occi_object.nil?
$log.debug("Error creating storage from backend")
else
Expand Down
32 changes: 32 additions & 0 deletions lib/occi/helpers/OCCIRequestHelper.rb
@@ -0,0 +1,32 @@
##############################################################################
# Copyright 2011 Service Computing group, TU Dortmund
#
# Licensed 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.
##############################################################################

##############################################################################
# Description: OCCI Request Helper
# Author(s): Hayati Bice, Florian Feldhaus, Piotr Kasprzak
##############################################################################

require 'sinatra/base'

module Sinatra
module OCCIRequestHelper
def testhelper

end
end

helpers OCCIRequestHelper
end

0 comments on commit 79a106b

Please sign in to comment.