From f42b9d807cb0739e72060f9da30e64949a8aaf95 Mon Sep 17 00:00:00 2001 From: Colin Gagnaire Date: Fri, 18 Jan 2019 18:19:54 +0100 Subject: [PATCH] enh azure plugins, add tags on list modes --- .../virtualmachine/mode/listresources.pm | 18 +++++++++++++++-- .../management/resource/mode/listgroups.pm | 18 ++++++++++++++--- .../management/resource/mode/listresources.pm | 20 ++++++++++++++++--- .../networkinterface/mode/listresources.pm | 20 ++++++++++++++++--- .../storageaccount/mode/listresources.pm | 20 ++++++++++++++++--- 5 files changed, 82 insertions(+), 14 deletions(-) diff --git a/cloud/azure/compute/virtualmachine/mode/listresources.pm b/cloud/azure/compute/virtualmachine/mode/listresources.pm index 4f785a388..f2036eb20 100644 --- a/cloud/azure/compute/virtualmachine/mode/listresources.pm +++ b/cloud/azure/compute/virtualmachine/mode/listresources.pm @@ -67,8 +67,14 @@ sub run { my $resource_group = '-'; $resource_group = $vm->{resourceGroup} if (defined($vm->{resourceGroup})); $resource_group = $1 if (defined($vm->{id}) && $vm->{id} =~ /resourceGroups\/(.*)\/providers/); + + my @tags; + foreach my $tag (keys %{$vm->{tags}}) { + push @tags, $tag . ':' . $vm->{tags}->{$tag}; + } + $self->{output}->output_add(long_msg => sprintf("[name = %s][computername = %s][resourcegroup = %s]" . - "[location = %s][vmid = %s][vmsize = %s][os = %s][state = %s]", + "[location = %s][vmid = %s][vmsize = %s][os = %s][state = %s][tags = %s]", $vm->{name}, $computer_name, $resource_group, @@ -77,6 +83,7 @@ sub run { (defined($vm->{properties}->{hardwareProfile}->{vmSize})) ? $vm->{properties}->{hardwareProfile}->{vmSize} : $vm->{hardwareProfile}->{vmSize}, (defined($vm->{properties}->{storageProfile}->{osDisk}->{osType})) ? $vm->{properties}->{storageProfile}->{osDisk}->{osType} : $vm->{storageProfile}->{osDisk}->{osType}, (defined($vm->{powerState})) ? $vm->{powerState} : "-", + join(',', @tags), )); } @@ -89,7 +96,7 @@ sub run { sub disco_format { my ($self, %options) = @_; - $self->{output}->add_disco_format(elements => ['name', 'computername', 'resourcegroup', 'location', 'vmid', 'vmsize', 'os', 'state']); + $self->{output}->add_disco_format(elements => ['name', 'computername', 'resourcegroup', 'location', 'vmid', 'vmsize', 'os', 'state', 'tags']); } sub disco_show { @@ -103,6 +110,12 @@ sub disco_show { my $resource_group = '-'; $resource_group = $vm->{resourceGroup} if (defined($vm->{resourceGroup})); $resource_group = $1 if (defined($vm->{id}) && $vm->{id} =~ /resourceGroups\/(.*)\/providers/); + + my @tags; + foreach my $tag (keys %{$vm->{tags}}) { + push @tags, $tag . ':' . $vm->{tags}->{$tag}; + } + $self->{output}->add_disco_entry( name => $vm->{name}, computername => $computer_name, @@ -112,6 +125,7 @@ sub disco_show { vmsize => (defined($vm->{properties}->{hardwareProfile}->{vmSize})) ? $vm->{properties}->{hardwareProfile}->{vmSize} : $vm->{hardwareProfile}->{vmSize}, os => (defined($vm->{properties}->{storageProfile}->{osDisk}->{osType})) ? $vm->{properties}->{storageProfile}->{osDisk}->{osType} : $vm->{storageProfile}->{osDisk}->{osType}, state => (defined($vm->{powerState})) ? $vm->{powerState} : "-", + tags => join(',', @tags), ); } } diff --git a/cloud/azure/management/resource/mode/listgroups.pm b/cloud/azure/management/resource/mode/listgroups.pm index 0b404e65b..dd7d26309 100644 --- a/cloud/azure/management/resource/mode/listgroups.pm +++ b/cloud/azure/management/resource/mode/listgroups.pm @@ -60,8 +60,14 @@ sub run { && $group->{name} !~ /$self->{option_results}->{filter_name}/); next if (defined($self->{option_results}->{location}) && $self->{option_results}->{location} ne '' && $group->{location} !~ /$self->{option_results}->{location}/); - $self->{output}->output_add(long_msg => sprintf("[name = %s][location = %s][id = %s]", - $group->{name}, $group->{location}, $group->{id})); + + my @tags; + foreach my $tag (keys %{$group->{tags}}) { + push @tags, $tag . ':' . $group->{tags}->{$tag}; + } + + $self->{output}->output_add(long_msg => sprintf("[name = %s][location = %s][id = %s][tags = %s]", + $group->{name}, $group->{location}, $group->{id}, join(',', @tags))); } $self->{output}->output_add(severity => 'OK', @@ -73,7 +79,7 @@ sub run { sub disco_format { my ($self, %options) = @_; - $self->{output}->add_disco_format(elements => ['name', 'location', 'id']); + $self->{output}->add_disco_format(elements => ['name', 'location', 'id', 'tags']); } sub disco_show { @@ -81,10 +87,16 @@ sub disco_show { $self->manage_selection(%options); foreach my $group (@{$self->{groups}}) { + my @tags; + foreach my $tag (keys %{$group->{tags}}) { + push @tags, $tag . ':' . $group->{tags}->{$tag}; + } + $self->{output}->add_disco_entry( name => $group->{name}, location => $group->{location}, id => $group->{id}, + tags => join(',', @tags), ); } } diff --git a/cloud/azure/management/resource/mode/listresources.pm b/cloud/azure/management/resource/mode/listresources.pm index 6a413d257..6be51a002 100644 --- a/cloud/azure/management/resource/mode/listresources.pm +++ b/cloud/azure/management/resource/mode/listresources.pm @@ -70,12 +70,19 @@ sub run { my $resource_group = '-'; $resource_group = $resource->{resourceGroup} if (defined($resource->{resourceGroup})); $resource_group = $1 if (defined($resource->{id}) && $resource->{id} =~ /resourceGroups\/(.*)\/providers/); - $self->{output}->output_add(long_msg => sprintf("[name = %s][resourcegroup = %s][location = %s][id = %s][type = %s]", + + my @tags; + foreach my $tag (keys %{$resource->{tags}}) { + push @tags, $tag . ':' . $resource->{tags}->{$tag}; + } + + $self->{output}->output_add(long_msg => sprintf("[name = %s][resourcegroup = %s][location = %s][id = %s][type = %s][tags = %s]", $resource->{name}, $resource_group, $resource->{location}, $resource->{id}, - $resource->{type} + $resource->{type}, + join(',', @tags), )); } @@ -88,7 +95,7 @@ sub run { sub disco_format { my ($self, %options) = @_; - $self->{output}->add_disco_format(elements => ['name', 'resourcegroup', 'location', 'id', 'type']); + $self->{output}->add_disco_format(elements => ['name', 'resourcegroup', 'location', 'id', 'type', 'tags']); } sub disco_show { @@ -99,12 +106,19 @@ sub disco_show { my $resource_group = '-'; $resource_group = $resource->{resourceGroup} if (defined($resource->{resourceGroup})); $resource_group = $1 if (defined($resource->{id}) && $resource->{id} =~ /resourceGroups\/(.*)\/providers/); + + my @tags; + foreach my $tag (keys %{$resource->{tags}}) { + push @tags, $tag . ':' . $resource->{tags}->{$tag}; + } + $self->{output}->add_disco_entry( name => $resource->{name}, resourcegroup => $resource_group, location => $resource->{location}, id => $resource->{id}, type => $resource->{type}, + tags => join(',', @tags), ); } } diff --git a/cloud/azure/network/networkinterface/mode/listresources.pm b/cloud/azure/network/networkinterface/mode/listresources.pm index 01594b930..7862bfe4b 100644 --- a/cloud/azure/network/networkinterface/mode/listresources.pm +++ b/cloud/azure/network/networkinterface/mode/listresources.pm @@ -67,11 +67,18 @@ sub run { my $resource_group = '-'; $resource_group = $resource->{resourceGroup} if (defined($resource->{resourceGroup})); $resource_group = $1 if (defined($resource->{id}) && $resource->{id} =~ /resourceGroups\/(.*)\/providers/); - $self->{output}->output_add(long_msg => sprintf("[name = %s][resourcegroup = %s][location = %s][id = %s]", + + my @tags; + foreach my $tag (keys %{$resource->{tags}}) { + push @tags, $tag . ':' . $resource->{tags}->{$tag}; + } + + $self->{output}->output_add(long_msg => sprintf("[name = %s][resourcegroup = %s][location = %s][id = %s][tags = %s]", $resource->{name}, $resource_group, $resource->{location}, - $resource->{id} + $resource->{id}, + join(',', @tags), )); } @@ -84,7 +91,7 @@ sub run { sub disco_format { my ($self, %options) = @_; - $self->{output}->add_disco_format(elements => ['name', 'resourcegroup', 'location', 'id']); + $self->{output}->add_disco_format(elements => ['name', 'resourcegroup', 'location', 'id', 'tags']); } sub disco_show { @@ -95,11 +102,18 @@ sub disco_show { my $resource_group = '-'; $resource_group = $resource->{resourceGroup} if (defined($resource->{resourceGroup})); $resource_group = $1 if (defined($resource->{id}) && $resource->{id} =~ /resourceGroups\/(.*)\/providers/); + + my @tags; + foreach my $tag (keys %{$resource->{tags}}) { + push @tags, $tag . ':' . $resource->{tags}->{$tag}; + } + $self->{output}->add_disco_entry( name => $resource->{name}, resourcegroup => $resource_group, location => $resource->{location}, id => $resource->{id}, + tags => join(',', @tags), ); } } diff --git a/cloud/azure/storage/storageaccount/mode/listresources.pm b/cloud/azure/storage/storageaccount/mode/listresources.pm index 7004734f6..36ea3ebbb 100644 --- a/cloud/azure/storage/storageaccount/mode/listresources.pm +++ b/cloud/azure/storage/storageaccount/mode/listresources.pm @@ -67,11 +67,18 @@ sub run { my $resource_group = '-'; $resource_group = $resource->{resourceGroup} if (defined($resource->{resourceGroup})); $resource_group = $1 if (defined($resource->{id}) && $resource->{id} =~ /resourceGroups\/(.*)\/providers/); - $self->{output}->output_add(long_msg => sprintf("[name = %s][resourcegroup = %s][location = %s][id = %s]", + + my @tags; + foreach my $tag (keys %{$resource->{tags}}) { + push @tags, $tag . ':' . $resource->{tags}->{$tag}; + } + + $self->{output}->output_add(long_msg => sprintf("[name = %s][resourcegroup = %s][location = %s][id = %s][tags = %s]", $resource->{name}, $resource_group, $resource->{location}, - $resource->{id} + $resource->{id}, + join(',', @tags), )); } @@ -84,7 +91,7 @@ sub run { sub disco_format { my ($self, %options) = @_; - $self->{output}->add_disco_format(elements => ['name', 'resourcegroup', 'location', 'id']); + $self->{output}->add_disco_format(elements => ['name', 'resourcegroup', 'location', 'id', 'tags']); } sub disco_show { @@ -95,11 +102,18 @@ sub disco_show { my $resource_group = '-'; $resource_group = $resource->{resourceGroup} if (defined($resource->{resourceGroup})); $resource_group = $1 if (defined($resource->{id}) && $resource->{id} =~ /resourceGroups\/(.*)\/providers/); + + my @tags; + foreach my $tag (keys %{$resource->{tags}}) { + push @tags, $tag . ':' . $resource->{tags}->{$tag}; + } + $self->{output}->add_disco_entry( name => $resource->{name}, resourcegroup => $resource_group, location => $resource->{location}, id => $resource->{id}, + tags => join(',', @tags), ); } }