deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "marios@redhat.com" <mandr...@redhat.com>
Subject Re: [PATCH core] EC2: Added initial support for CloudWatch via new Metric collection
Date Wed, 18 Jan 2012 14:05:32 GMT
ack
(minor typo needs fixing before push - server wouldn't start):

On 18/01/12 15:27, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mfojtik@redhat.com>

<snip>

> 
> Signed-off-by: Michal fojtik <mfojtik@redhat.com>
> ---
>  server/config/drivers/ec2.yaml                  |    8 ++++
>  server/lib/deltacloud/drivers/ec2/ec2_driver.rb |   51 ++++++++++++++++++++++-
> +        def convert_metric(metric)
> +          Metric.new(
> +            :id => metric[:value],
> +            :entity => metric[:name] || :unknown,
> +          ).add_property(metric[:measure_name])
> +        end

the extra ',' after :unkown (ruby 1.8.7).


> +
>          def convert_state(ec2_state)
>            case ec2_state
>              when "terminated"
> diff --git a/server/lib/deltacloud/models.rb b/server/lib/deltacloud/models.rb
> index a794192..af02520 100644
> --- a/server/lib/deltacloud/models.rb
> +++ b/server/lib/deltacloud/models.rb
> @@ -30,3 +30,4 @@ require 'deltacloud/models/load_balancer'
>  require 'deltacloud/models/firewall'
>  require 'deltacloud/models/firewall_rule'
>  require 'deltacloud/models/provider'
> +require 'deltacloud/models/metric'
> diff --git a/server/lib/deltacloud/models/metric.rb b/server/lib/deltacloud/models/metric.rb
> new file mode 100644
> index 0000000..42edaaf
> --- /dev/null
> +++ b/server/lib/deltacloud/models/metric.rb
> @@ -0,0 +1,40 @@
> +# Licensed to the Apache Software Foundation (ASF) under one or more
> +# contributor license agreements.  See the NOTICE file distributed with
> +# this work for additional information regarding copyright ownership.  The
> +# ASF licenses this file to you under the Apache License, Version 2.0 (the
> +# "License"); you may not use this file except in compliance with the
> +# License.  You may obtain a copy of the License at
> +#
> +#       http://www.apache.org/licenses/LICENSE-2.0
> +#
> +# Unless required by applicable law or agreed to in writing, software
> +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
> +# License for the specific language governing permissions and limitations
> +# under the License.
> +
> +class Metric < BaseModel
> +
> +  attr_accessor :entity
> +  attr_accessor :properties
> +
> +  def unknown?
> +    true if self.entity == :unknown
> +  end
> +
> +  def add_property(name, values=nil)
> +    self.properties ||= []
> +    return self if self.properties.any? { |p| p.name == name }
> +    self.properties << Property.new(name, values)
> +    self
> +  end
> +
> +  class Property
> +    attr_accessor :name, :values
> +
> +    def initialize(name, values=nil)
> +      @name, @values = name, values
> +    end
> +  end
> +
> +end
> diff --git a/server/lib/deltacloud/server.rb b/server/lib/deltacloud/server.rb
> index db742d6..e1badaa 100644
> --- a/server/lib/deltacloud/server.rb
> +++ b/server/lib/deltacloud/server.rb
> @@ -538,6 +538,21 @@ END
>    end
>  end
>  
> +collection :metrics do
> +
> +  operation :index do
> +    with_capability :metrics
> +    control { filter_all(:metrics) }
> +  end
> +
> +  operation :show do
> +    with_capability :metrics
> +    param :id,  :string,  :required
> +    control { show :metric }
> +  end
> +
> +end
> +
>  collection :hardware_profiles do
>    description <<END
>   A hardware profile represents a configuration of resources upon which a
> diff --git a/server/views/metrics/index.xml.haml b/server/views/metrics/index.xml.haml
> new file mode 100644
> index 0000000..a3b3d0d
> --- /dev/null
> +++ b/server/views/metrics/index.xml.haml
> @@ -0,0 +1,4 @@
> +!!!XML
> +%metrics
> +  - @elements.each do |c|
> +    = haml :'metrics/show', :locals => { :@metric => c, :partial => true }
> diff --git a/server/views/metrics/show.xml.haml b/server/views/metrics/show.xml.haml
> new file mode 100644
> index 0000000..55b96d2
> --- /dev/null
> +++ b/server/views/metrics/show.xml.haml
> @@ -0,0 +1,13 @@
> +- unless defined?(partial)
> +  !!! XML
> +%metric{ :href => metric_url(@metric.id), :id => @metric.id }
> +  %properties
> +    - @metric.properties.each do |p|
> +      %property
> +        %name=p.name
> +        - if p.values
> +          - p.values.each do |value|
> +            %value{ :timestamp => value[:timestamp], :unit => value[:unit]}
> +              %minimum=value[:minimum]
> +              %maximum=value[:maximum]
> +              %average=value[:average]


Mime
View raw message