resources: aws: ec2: Change event messages to iota consts
This commit is contained in:
@@ -58,6 +58,18 @@ const (
|
|||||||
waitTimeout = 400
|
waitTimeout = 400
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:generate stringer -type=awsEc2Event -output=awsec2event_stringer.go
|
||||||
|
|
||||||
|
// awsEc2Event represents the contents of event messages sent via awsChan.
|
||||||
|
type awsEc2Event uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
awsEc2EventServerReady awsEc2Event = iota
|
||||||
|
awsEc2EventInstanceStopped
|
||||||
|
awsEc2EventInstanceRunning
|
||||||
|
awsEc2EventInstanceExists
|
||||||
|
)
|
||||||
|
|
||||||
// AwsRegions is a list of all AWS regions generated using ec2.DescribeRegions.
|
// AwsRegions is a list of all AWS regions generated using ec2.DescribeRegions.
|
||||||
// cn-north-1 and us-gov-west-1 are not returned, probably due to security.
|
// cn-north-1 and us-gov-west-1 are not returned, probably due to security.
|
||||||
// List available at http://docs.aws.amazon.com/general/latest/gr/rande.html
|
// List available at http://docs.aws.amazon.com/general/latest/gr/rande.html
|
||||||
@@ -110,8 +122,8 @@ type AwsEc2Res struct {
|
|||||||
|
|
||||||
// chanStruct defines the type for a channel used to pass events and errors to watch.
|
// chanStruct defines the type for a channel used to pass events and errors to watch.
|
||||||
type chanStruct struct {
|
type chanStruct struct {
|
||||||
str string
|
event awsEc2Event
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default returns some sensible defaults for this resource.
|
// Default returns some sensible defaults for this resource.
|
||||||
@@ -340,7 +352,7 @@ func (obj *AwsEc2Res) longpollWatch() error {
|
|||||||
if len(stateOutput.Reservations) == 0 || (len(stateOutput.Reservations) == 1 && stateName != "running") {
|
if len(stateOutput.Reservations) == 0 || (len(stateOutput.Reservations) == 1 && stateName != "running") {
|
||||||
select {
|
select {
|
||||||
case obj.awsChan <- &chanStruct{
|
case obj.awsChan <- &chanStruct{
|
||||||
str: "stopped",
|
event: awsEc2EventInstanceStopped,
|
||||||
}:
|
}:
|
||||||
case <-obj.closeChan:
|
case <-obj.closeChan:
|
||||||
return
|
return
|
||||||
@@ -415,7 +427,7 @@ func (obj *AwsEc2Res) longpollWatch() error {
|
|||||||
if len(stateOutput.Reservations) == 0 || (len(stateOutput.Reservations) == 1 && stateName != "stopped") {
|
if len(stateOutput.Reservations) == 0 || (len(stateOutput.Reservations) == 1 && stateName != "stopped") {
|
||||||
select {
|
select {
|
||||||
case obj.awsChan <- &chanStruct{
|
case obj.awsChan <- &chanStruct{
|
||||||
str: "running",
|
event: awsEc2EventInstanceRunning,
|
||||||
}:
|
}:
|
||||||
case <-obj.closeChan:
|
case <-obj.closeChan:
|
||||||
return
|
return
|
||||||
@@ -452,7 +464,7 @@ func (obj *AwsEc2Res) longpollWatch() error {
|
|||||||
{
|
{
|
||||||
select {
|
select {
|
||||||
case obj.awsChan <- &chanStruct{
|
case obj.awsChan <- &chanStruct{
|
||||||
str: "exists",
|
event: awsEc2EventInstanceExists,
|
||||||
}:
|
}:
|
||||||
case <-obj.closeChan:
|
case <-obj.closeChan:
|
||||||
return
|
return
|
||||||
@@ -480,7 +492,7 @@ func (obj *AwsEc2Res) longpollWatch() error {
|
|||||||
if err := msg.err; err != nil {
|
if err := msg.err; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Printf("%s: State: %s", obj, msg.str)
|
log.Printf("%s: State: %v", obj, msg.event)
|
||||||
obj.StateOK(false)
|
obj.StateOK(false)
|
||||||
send = true
|
send = true
|
||||||
}
|
}
|
||||||
@@ -547,7 +559,7 @@ func (obj *AwsEc2Res) snsWatch() error {
|
|||||||
if err := msg.err; err != nil {
|
if err := msg.err; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Printf("%s: State: %s", obj, msg.str)
|
log.Printf("%s: State: %v", obj, msg.event)
|
||||||
obj.StateOK(false)
|
obj.StateOK(false)
|
||||||
send = true
|
send = true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user