diff --git a/operation_attach.go b/operation_attach.go index cb552ea..a7dcb7e 100644 --- a/operation_attach.go +++ b/operation_attach.go @@ -42,7 +42,7 @@ func (nodes *Nodes) Attach(targets []string) { for _, target := range nodes.GetTargets(targets) { if target.node.Do("start") { for _, instance := range target.instances { - if instance.isActive() { + if instance.HasContainer(true) { instance.Attach() } } @@ -61,7 +61,7 @@ func (node *Node) Attach(filters []string) { instances = node.FilterInstances(filters) } for _, instance := range instances { - if instance.isActive() { + if instance.HasContainer(true) { instance.Attach() } } diff --git a/operation_info.go b/operation_info.go index 7ee0aab..62e29fa 100644 --- a/operation_info.go +++ b/operation_info.go @@ -117,6 +117,7 @@ func (node *Node) Info_Instances() bool { "Container", "Default", "Active", + "Running", "Status", "ID", "Created", @@ -142,6 +143,11 @@ func (node *Node) Info_Instances() bool { } else { row = append(row, "no") } + if instance.HasContainer(true) { + row = append(row, "yes") + } else { + row = append(row, "no") + } container, found := instance.GetContainer(false) if found { diff --git a/operation_scale.go b/operation_scale.go index e54b61b..d2bdcc7 100644 --- a/operation_scale.go +++ b/operation_scale.go @@ -10,9 +10,14 @@ type Operation_Scale struct { nodes Nodes targets []string + + scale int } func (operation *Operation_Scale) Flags(flags []string) { + //@TODO GET SCALE FROM FLAG + operation.scale = 1 + } func (operation *Operation_Scale) Help(topics []string) { @@ -34,36 +39,103 @@ func (operation *Operation_Scale) Run() { operation.log.Message("running scale operation") operation.log.DebugObject(LOG_SEVERITY_DEBUG_LOTS, "Targets:", operation.targets) + if operation.scale==0 { + operation.log.Warning("scale operation was told to scale to 0") + return + } + TargetScaleReturn: for _, target := range operation.nodes.GetTargets(operation.targets) { - InstanceScaleReturn: - for i := 0; i < len(target.node.InstanceMap); i++ { - if instance, ok := target.node.InstanceMap[strconv.FormatInt(int64(i+1), 10)]; ok { - - container, hasContainer := instance.GetContainer(false) + if target.node.InstanceType!="scaled" { + operation.log.Warning("Tried to scale non-scaleable node :"+target.node.Name) + continue TargetScaleReturn + } - if hasContainer { - if strings.Contains(container.Status, "Up") { - operation.log.Debug(LOG_SEVERITY_DEBUG_LOTS, "Node instance already has a running container :"+container.ID) - continue InstanceScaleReturn - } - } else { - // create a new container for this instance - instance.Create([]string{}, false) - } + if operation.scale>0 { + count := target.node.ScaleUpNumber(operation.scale) + + if count==0 { + target.node.log.Warning("Scale operation could not scale up any new instances of node :"+target.node.Name) + } else if count= number { + return count + } + } +// operation.log.DebugObject(LOG_SEVERITY_DEBUG_LOTS, "SCALE NODE TEST INSTANCE:", *target.node.InstanceMap[strconv.FormatInt(int64(i+1), 10)]) + } + + return count +} +func (node *Node) ScaleDOwnNumber(number int) int { + + count := 0 + + InstanceScaleReturn: + for i := len(node.InstanceMap); i>=0; i-- { + if instance, ok := node.InstanceMap[strconv.FormatInt(int64(i+1), 10)]; ok { + + _, hasContainer := instance.GetContainer(true) + + if !hasContainer { + continue InstanceScaleReturn + } + + node.log.Message("Node Scaling down. Starting instance :"+instance.Name) + instance.Stop(false,10) + + count++ + if count >= number { + return count + } + } +// operation.log.DebugObject(LOG_SEVERITY_DEBUG_LOTS, "SCALE NODE TEST INSTANCE:", *target.node.InstanceMap[strconv.FormatInt(int64(i+1), 10)]) + } + + return count +} \ No newline at end of file