1
# -*- encoding: utf-8 -*-
3
# Copyright © 2013 ZHAW SoE
4
# Copyright © 2014 Intel Corp.
6
# Authors: Lucas Graf <graflu0@students.zhaw.ch>
7
# Toni Zehnder <zehndton@students.zhaw.ch>
8
# Lianhao Lu <lianhao.lu@intel.com>
10
# Licensed under the Apache License, Version 2.0 (the "License"); you may
11
# not use this file except in compliance with the License. You may obtain
12
# a copy of the License at
14
# http://www.apache.org/licenses/LICENSE-2.0
16
# Unless required by applicable law or agreed to in writing, software
17
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
19
# License for the specific language governing permissions and limitations
25
from ceilometer.openstack.common import timeutils
26
from ceilometer import sample
29
def get_metadata_from_host(host_url):
30
return {'resource_url': urlparse.urlunsplit(host_url)}
33
def make_sample_from_host(host_url, name, type, unit, volume,
34
project_id=None, user_id=None, res_metadata=None):
35
resource_metadata = dict()
36
if res_metadata is not None:
37
metadata = copy.copy(res_metadata)
38
resource_metadata = dict(zip(metadata._fields, metadata))
39
resource_metadata.update(get_metadata_from_host(host_url))
48
resource_id=host_url.hostname,
49
timestamp=timeutils.isotime(),
50
resource_metadata=resource_metadata,