~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/addmachine.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import (
7
7
        "fmt"
8
8
        "strconv"
9
 
        "time"
10
9
 
11
10
        "github.com/juju/errors"
12
11
        "github.com/juju/replicaset"
462
461
// into the database, based on the given template. Only the constraints are
463
462
// taken from the template.
464
463
func (st *State) insertNewMachineOps(mdoc *machineDoc, template MachineTemplate) (prereqOps []txn.Op, machineOp txn.Op, err error) {
 
464
        now := st.clock.Now()
465
465
        machineStatusDoc := statusDoc{
466
 
                Status:    status.StatusPending,
 
466
                Status:    status.Pending,
467
467
                ModelUUID: st.ModelUUID(),
468
 
                // TODO(fwereade): 2016-03-17 lp:1558657
469
 
                Updated: time.Now().UnixNano(),
 
468
                Updated:   now.UnixNano(),
470
469
        }
471
470
        instanceStatusDoc := statusDoc{
472
 
                Status:    status.StatusPending,
 
471
                Status:    status.Pending,
473
472
                ModelUUID: st.ModelUUID(),
474
 
                Updated:   time.Now().UnixNano(),
 
473
                Updated:   now.UnixNano(),
475
474
        }
476
475
 
477
476
        prereqOps, machineOp = st.baseNewMachineOps(
537
536
        filesystemAttachments map[names.FilesystemTag]FilesystemAttachmentParams
538
537
}
539
538
 
 
539
func combineMachineStorageParams(lhs, rhs *machineStorageParams) *machineStorageParams {
 
540
        out := &machineStorageParams{}
 
541
        out.volumes = append(lhs.volumes[:], rhs.volumes...)
 
542
        out.filesystems = append(lhs.filesystems[:], rhs.filesystems...)
 
543
        if lhs.volumeAttachments != nil || rhs.volumeAttachments != nil {
 
544
                out.volumeAttachments = make(map[names.VolumeTag]VolumeAttachmentParams)
 
545
                for k, v := range lhs.volumeAttachments {
 
546
                        out.volumeAttachments[k] = v
 
547
                }
 
548
                for k, v := range rhs.volumeAttachments {
 
549
                        out.volumeAttachments[k] = v
 
550
                }
 
551
        }
 
552
        if lhs.filesystemAttachments != nil || rhs.filesystemAttachments != nil {
 
553
                out.filesystemAttachments = make(map[names.FilesystemTag]FilesystemAttachmentParams)
 
554
                for k, v := range lhs.filesystemAttachments {
 
555
                        out.filesystemAttachments[k] = v
 
556
                }
 
557
                for k, v := range rhs.filesystemAttachments {
 
558
                        out.filesystemAttachments[k] = v
 
559
                }
 
560
        }
 
561
        return out
 
562
}
 
563
 
540
564
// machineStorageOps creates txn.Ops for creating volumes, filesystems,
541
565
// and attachments to the specified machine. The results are the txn.Ops,
542
566
// and the tags of volumes and filesystems newly attached to the machine.