Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(492)

Side by Side Diff: environs/local/environ.go

Issue 11561044: Make agent/tools and remove state.Tools
Patch Set: Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 Canonical Ltd. 1 // Copyright 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package local 4 package local
5 5
6 import ( 6 import (
7 "fmt" 7 "fmt"
8 "io/ioutil" 8 "io/ioutil"
9 "net" 9 "net"
10 "net/url" 10 "net/url"
11 "os" 11 "os"
12 "path/filepath" 12 "path/filepath"
13 "sync" 13 "sync"
14 "time" 14 "time"
15 15
16 "launchpad.net/juju-core/agent" 16 "launchpad.net/juju-core/agent"
17 "launchpad.net/juju-core/agent/tools"
17 "launchpad.net/juju-core/constraints" 18 "launchpad.net/juju-core/constraints"
18 "launchpad.net/juju-core/container/lxc" 19 "launchpad.net/juju-core/container/lxc"
19 "launchpad.net/juju-core/environs" 20 "launchpad.net/juju-core/environs"
20 "launchpad.net/juju-core/environs/config" 21 "launchpad.net/juju-core/environs/config"
21 "launchpad.net/juju-core/environs/localstorage" 22 "launchpad.net/juju-core/environs/localstorage"
22 "launchpad.net/juju-core/instance" 23 "launchpad.net/juju-core/instance"
23 "launchpad.net/juju-core/state" 24 "launchpad.net/juju-core/state"
24 "launchpad.net/juju-core/state/api" 25 "launchpad.net/juju-core/state/api"
25 "launchpad.net/juju-core/upstart" 26 "launchpad.net/juju-core/upstart"
26 "launchpad.net/juju-core/utils" 27 "launchpad.net/juju-core/utils"
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 dataDir := env.config.rootDir() 448 dataDir := env.config.rootDir()
448 toolList, err := environs.FindBootstrapTools(env, cons) 449 toolList, err := environs.FindBootstrapTools(env, cons)
449 if err != nil { 450 if err != nil {
450 return err 451 return err
451 } 452 }
452 // ensure we have at least one valid tools 453 // ensure we have at least one valid tools
453 if len(toolList) == 0 { 454 if len(toolList) == 0 {
454 return fmt.Errorf("No bootstrap tools found") 455 return fmt.Errorf("No bootstrap tools found")
455 } 456 }
456 // unpack the first tools into the agent dir. 457 // unpack the first tools into the agent dir.
457 » tools := toolList[0] 458 » agentTools := toolList[0]
458 » logger.Debugf("tools: %#v", tools) 459 » logger.Debugf("tools: %#v", agentTools)
459 // brutally abuse our knowledge of storage to directly open the file 460 // brutally abuse our knowledge of storage to directly open the file
460 » toolsUrl, err := url.Parse(tools.URL) 461 » toolsUrl, err := url.Parse(agentTools.URL)
461 toolsLocation := filepath.Join(env.config.storageDir(), toolsUrl.Path) 462 toolsLocation := filepath.Join(env.config.storageDir(), toolsUrl.Path)
462 logger.Infof("tools location: %v", toolsLocation) 463 logger.Infof("tools location: %v", toolsLocation)
463 toolsFile, err := os.Open(toolsLocation) 464 toolsFile, err := os.Open(toolsLocation)
464 defer toolsFile.Close() 465 defer toolsFile.Close()
465 // Again, brutally abuse our knowledge here. 466 // Again, brutally abuse our knowledge here.
466 467
467 // The tools that FindBootstrapTools has returned us are based on the 468 // The tools that FindBootstrapTools has returned us are based on the
468 // default series in the config. However we are running potentially on a 469 // default series in the config. However we are running potentially on a
469 // different series. When the machine agent is started, it will be 470 // different series. When the machine agent is started, it will be
470 // looking based on the current series, so we need to override the serie s 471 // looking based on the current series, so we need to override the serie s
471 // returned in the tools to be the current series. 472 // returned in the tools to be the current series.
472 » tools.Binary.Series = version.CurrentSeries() 473 » agentTools.Binary.Series = version.CurrentSeries()
473 » err = agent.UnpackTools(dataDir, tools, toolsFile) 474 » err = tools.UnpackTools(dataDir, agentTools, toolsFile)
474 475
475 machineId := "0" // Always machine 0 476 machineId := "0" // Always machine 0
476 tag := state.MachineTag(machineId) 477 tag := state.MachineTag(machineId)
477 » toolsDir := agent.SharedToolsDir(dataDir, tools.Binary) 478 » toolsDir := tools.SharedToolsDir(dataDir, agentTools.Binary)
478 logDir := env.config.logDir() 479 logDir := env.config.logDir()
479 logConfig := "--debug" // TODO(thumper): specify loggo config 480 logConfig := "--debug" // TODO(thumper): specify loggo config
480 agent := upstart.MachineAgentUpstartService( 481 agent := upstart.MachineAgentUpstartService(
481 env.machineAgentServiceName(), 482 env.machineAgentServiceName(),
482 toolsDir, dataDir, logDir, tag, machineId, logConfig, env.config .Type()) 483 toolsDir, dataDir, logDir, tag, machineId, logConfig, env.config .Type())
483 agent.Env["USER"] = env.config.user 484 agent.Env["USER"] = env.config.user
484 agent.Env["HOME"] = os.Getenv("HOME") 485 agent.Env["HOME"] = os.Getenv("HOME")
485 agent.Env["JUJU_STORAGE_DIR"] = env.config.storageDir() 486 agent.Env["JUJU_STORAGE_DIR"] = env.config.storageDir()
486 agent.Env["JUJU_STORAGE_ADDR"] = env.config.storageAddr() 487 agent.Env["JUJU_STORAGE_ADDR"] = env.config.storageAddr()
487 agent.Env["JUJU_SHARED_STORAGE_DIR"] = env.config.sharedStorageDir() 488 agent.Env["JUJU_SHARED_STORAGE_DIR"] = env.config.sharedStorageDir()
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 558
558 if err := environs.ConfigureBootstrapMachine( 559 if err := environs.ConfigureBootstrapMachine(
559 st, cons, env.config.rootDir(), jobs, instance.Id(boostrapInstan ceId), instance.HardwareCharacteristics{}); err != nil { 560 st, cons, env.config.rootDir(), jobs, instance.Id(boostrapInstan ceId), instance.HardwareCharacteristics{}); err != nil {
560 st.Close() 561 st.Close()
561 return nil, err 562 return nil, err
562 } 563 }
563 564
564 // Return an open state reference. 565 // Return an open state reference.
565 return st, nil 566 return st, nil
566 } 567 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b