Skip to content

Commit

Permalink
ebs support
Browse files Browse the repository at this point in the history
  • Loading branch information
purehyperbole committed Dec 9, 2016
1 parent 274a95c commit a8ed4ff
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions c_ebs_volume.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a8ed4ff

Please sign in to comment.