Move net function in class method and fix instance id
The instance id copied is not the UUID, so it's useless because it does not help to associate network with instances. Also, move make_vnic_counter function into a class method since it's not used anywhere else. This fixes bug #1063693 Change-Id: I31366d0edaf1f2768a9b7fe349faae2cc5c99e3e Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
ef10895ffa
commit
51550f2fdf
@ -60,23 +60,6 @@ def make_counter_from_instance(instance, name, type, volume):
|
||||
)
|
||||
|
||||
|
||||
def make_vnic_counter(instance, name, type, volume, vnic_data):
|
||||
resource_metadata = copy.copy(vnic_data)
|
||||
resource_metadata['instance_id'] = instance.id
|
||||
|
||||
return counter.Counter(
|
||||
source='?',
|
||||
name=name,
|
||||
type=type,
|
||||
volume=volume,
|
||||
user_id=instance.user_id,
|
||||
project_id=instance.project_id,
|
||||
resource_id=vnic_data['fref'],
|
||||
timestamp=timeutils.isotime(),
|
||||
resource_metadata=resource_metadata
|
||||
)
|
||||
|
||||
|
||||
class InstancePollster(plugin.ComputePollster):
|
||||
|
||||
def get_counters(self, manager, instance):
|
||||
@ -186,6 +169,23 @@ class NetPollster(plugin.ComputePollster):
|
||||
vnics.append(vnic)
|
||||
return vnics
|
||||
|
||||
@staticmethod
|
||||
def make_vnic_counter(instance, name, type, volume, vnic_data):
|
||||
resource_metadata = copy.copy(vnic_data)
|
||||
resource_metadata['instance_id'] = instance.uuid
|
||||
|
||||
return counter.Counter(
|
||||
source='?',
|
||||
name=name,
|
||||
type=type,
|
||||
volume=volume,
|
||||
user_id=instance.user_id,
|
||||
project_id=instance.project_id,
|
||||
resource_id=vnic_data['fref'],
|
||||
timestamp=timeutils.isotime(),
|
||||
resource_metadata=resource_metadata
|
||||
)
|
||||
|
||||
def get_counters(self, manager, instance):
|
||||
conn = get_libvirt_connection()
|
||||
self.LOG.info('checking instance %s', instance.uuid)
|
||||
@ -203,27 +203,27 @@ class NetPollster(plugin.ComputePollster):
|
||||
domain.interfaceStats(vnic['name'])
|
||||
self.LOG.info(self.NET_USAGE_MESSAGE, instance.name,
|
||||
vnic['name'], rx_bytes, tx_bytes)
|
||||
yield make_vnic_counter(instance,
|
||||
name='network.incoming.bytes',
|
||||
type=counter.TYPE_CUMULATIVE,
|
||||
volume=rx_bytes,
|
||||
vnic_data=vnic
|
||||
)
|
||||
yield make_vnic_counter(instance,
|
||||
name='network.outgoing.bytes',
|
||||
type=counter.TYPE_CUMULATIVE,
|
||||
volume=tx_bytes,
|
||||
vnic_data=vnic
|
||||
)
|
||||
yield make_vnic_counter(instance,
|
||||
name='network.incoming.packets',
|
||||
type=counter.TYPE_CUMULATIVE,
|
||||
volume=rx_packets,
|
||||
vnic_data=vnic
|
||||
)
|
||||
yield make_vnic_counter(instance,
|
||||
name='network.outgoing.packets',
|
||||
type=counter.TYPE_CUMULATIVE,
|
||||
volume=tx_packets,
|
||||
vnic_data=vnic
|
||||
)
|
||||
yield self.make_vnic_counter(instance,
|
||||
name='network.incoming.bytes',
|
||||
type=counter.TYPE_CUMULATIVE,
|
||||
volume=rx_bytes,
|
||||
vnic_data=vnic,
|
||||
)
|
||||
yield self.make_vnic_counter(instance,
|
||||
name='network.outgoing.bytes',
|
||||
type=counter.TYPE_CUMULATIVE,
|
||||
volume=tx_bytes,
|
||||
vnic_data=vnic,
|
||||
)
|
||||
yield self.make_vnic_counter(instance,
|
||||
name='network.incoming.packets',
|
||||
type=counter.TYPE_CUMULATIVE,
|
||||
volume=rx_packets,
|
||||
vnic_data=vnic,
|
||||
)
|
||||
yield self.make_vnic_counter(instance,
|
||||
name='network.outgoing.packets',
|
||||
type=counter.TYPE_CUMULATIVE,
|
||||
volume=tx_packets,
|
||||
vnic_data=vnic,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user