From a8ed4ffcd10b07a4d237ee33c38cac34f00da951 Mon Sep 17 00:00:00 2001 From: Tom Bevan Date: Fri, 9 Dec 2016 16:20:43 +0000 Subject: [PATCH] ebs support --- c_ebs_volume.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 c_ebs_volume.go diff --git a/c_ebs_volume.go b/c_ebs_volume.go new file mode 100644 index 0000000..ad334c8 --- /dev/null +++ b/c_ebs_volume.go @@ -0,0 +1,49 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package main + +type EBSVolume struct { +} + +func (v *EBSVolume) Handle(subject string, components []interface{}, lines []Message) []Message { + switch subject { + case "ebs_volumes.create": + return append(lines, Message{Body: "Creating ebs volumes:", Level: "INFO"}) + case "ebs_volumes.create.done": + lines = v.getDetails(components) + return append(lines, Message{Body: "EBS volumes successfully created", Level: "INFO"}) + case "ebs_volumes.create.error": + lines = v.getDetails(components) + return append(lines, Message{Body: "EBS volumes creation failed", Level: "INFO"}) + case "ebs_volumes.delete": + return append(lines, Message{Body: "Deleting ebs volumes:", Level: "INFO"}) + case "ebs_volumes.delete.done": + lines = v.getDetails(components) + return append(lines, Message{Body: "EBS volumes deleted", Level: "INFO"}) + case "ebs_volumes.delete.error": + lines = v.getDetails(components) + return append(lines, Message{Body: "EBS volumes deletion failed", Level: "INFO"}) + } + return lines +} + +func (v *EBSVolume) getDetails(components []interface{}) (lines []Message) { + for _, v := range components { + r := v.(map[string]interface{}) + name, _ := r["name"].(string) + status, _ := r["status"].(string) + lines = append(lines, Message{Body: " - " + name, Level: ""}) + id, _ := r["volume_aws_id"].(string) + if id != "" { + lines = append(lines, Message{Body: " AWS ID : " + id, Level: ""}) + } + lines = append(lines, Message{Body: " Status : " + status, Level: ""}) + if status == "errored" { + err, _ := r["error"].(string) + lines = append(lines, Message{Body: " Error : " + err, Level: "ERROR"}) + } + } + return lines +}