func (broker *lxdBroker) StartInstance(args environs.StartInstanceParams) (*environs.StartInstanceResult, error) { if args.InstanceConfig.HasNetworks() { return nil, errors.New("starting lxd containers with networks is not supported yet") } machineId := args.InstanceConfig.MachineId bridgeDevice := broker.agentConfig.Value(agent.LxcBridge) if bridgeDevice == "" { var err error bridgeDevice, err = lxdclient.GetDefaultBridgeName() if err != nil { return nil, errors.Trace(err) } } preparedInfo, err := prepareOrGetContainerInterfaceInfo( broker.api, machineId, bridgeDevice, true, // allocate if possible, do not maintain existing. broker.enableNAT, args.NetworkInfo, lxdLogger, ) if err != nil { // It's not fatal (yet) if we couldn't pre-allocate addresses for the // container. logger.Warningf("failed to prepare container %q network config: %v", machineId, err) } else { args.NetworkInfo = preparedInfo } network := container.BridgeNetworkConfig(bridgeDevice, 0, args.NetworkInfo) series := args.Tools.OneSeries() args.InstanceConfig.MachineContainerType = instance.LXD args.InstanceConfig.Tools = args.Tools[0] config, err := broker.api.ContainerConfig() if err != nil { lxdLogger.Errorf("failed to get container config: %v", err) return nil, err } if err := instancecfg.PopulateInstanceConfig( args.InstanceConfig, config.ProviderType, config.AuthorizedKeys, config.SSLHostnameVerification, config.Proxy, config.AptProxy, config.AptMirror, config.PreferIPv6, config.EnableOSRefreshUpdate, config.EnableOSUpgrade, ); err != nil { lxdLogger.Errorf("failed to populate machine config: %v", err) return nil, err } storageConfig := &container.StorageConfig{} inst, hardware, err := broker.manager.CreateContainer(args.InstanceConfig, series, network, storageConfig, args.StatusCallback) if err != nil { return nil, err } return &environs.StartInstanceResult{ Instance: inst, Hardware: hardware, NetworkInfo: network.Interfaces, }, nil }
// StartInstance is specified in the Broker interface. func (broker *kvmBroker) StartInstance(args environs.StartInstanceParams) (*environs.StartInstanceResult, error) { if args.InstanceConfig.HasNetworks() { return nil, errors.New("starting kvm containers with networks is not supported yet") } // TODO: refactor common code out of the container brokers. machineId := args.InstanceConfig.MachineId kvmLogger.Infof("starting kvm container for machineId: %s", machineId) // TODO: Default to using the host network until we can configure. Yes, // this is using the LxcBridge value, we should put it in the api call for // container config. bridgeDevice := broker.agentConfig.Value(agent.LxcBridge) if bridgeDevice == "" { bridgeDevice = kvm.DefaultKvmBridge } if !environs.AddressAllocationEnabled() { logger.Debugf( "address allocation feature flag not enabled; using DHCP for container %q", machineId, ) } else { logger.Debugf("trying to allocate static IP for container %q", machineId) allocatedInfo, err := configureContainerNetwork( machineId, bridgeDevice, broker.api, args.NetworkInfo, true, // allocate a new address. broker.enableNAT, ) if err != nil { // It's fine, just ignore it. The effect will be that the // container won't have a static address configured. logger.Infof("not allocating static IP for container %q: %v", machineId, err) } else { args.NetworkInfo = allocatedInfo } } // Unlike with LXC, we don't override the default MTU to use. network := container.BridgeNetworkConfig(bridgeDevice, 0, args.NetworkInfo) series := args.Tools.OneSeries() args.InstanceConfig.MachineContainerType = instance.KVM args.InstanceConfig.Tools = args.Tools[0] config, err := broker.api.ContainerConfig() if err != nil { kvmLogger.Errorf("failed to get container config: %v", err) return nil, err } if err := instancecfg.PopulateInstanceConfig( args.InstanceConfig, config.ProviderType, config.AuthorizedKeys, config.SSLHostnameVerification, config.Proxy, config.AptProxy, config.AptMirror, config.PreferIPv6, config.EnableOSRefreshUpdate, config.EnableOSUpgrade, ); err != nil { kvmLogger.Errorf("failed to populate machine config: %v", err) return nil, err } storageConfig := &container.StorageConfig{ AllowMount: true, } inst, hardware, err := broker.manager.CreateContainer(args.InstanceConfig, series, network, storageConfig) if err != nil { kvmLogger.Errorf("failed to start container: %v", err) return nil, err } kvmLogger.Infof("started kvm container for machineId: %s, %s, %s", machineId, inst.Id(), hardware.String()) return &environs.StartInstanceResult{ Instance: inst, Hardware: hardware, NetworkInfo: network.Interfaces, }, nil }
// StartInstance is specified in the Broker interface. func (broker *lxcBroker) StartInstance(args environs.StartInstanceParams) (*environs.StartInstanceResult, error) { // TODO: refactor common code out of the container brokers. machineId := args.InstanceConfig.MachineId lxcLogger.Infof("starting lxc container for machineId: %s", machineId) // Default to using the host network until we can configure. bridgeDevice := broker.agentConfig.Value(agent.LxcBridge) if bridgeDevice == "" { bridgeDevice = container.DefaultLxcBridge } config, err := broker.api.ContainerConfig() if err != nil { lxcLogger.Errorf("failed to get container config: %v", err) return nil, err } preparedInfo, err := prepareOrGetContainerInterfaceInfo( broker.api, machineId, bridgeDevice, true, // allocate if possible, do not maintain existing. broker.enableNAT, args.NetworkInfo, lxcLogger, config.ProviderType, ) if err != nil { // It's not fatal (yet) if we couldn't pre-allocate addresses for the // container. logger.Warningf("failed to prepare container %q network config: %v", machineId, err) } else { args.NetworkInfo = preparedInfo } network := container.BridgeNetworkConfig(bridgeDevice, broker.defaultMTU, args.NetworkInfo) // The provisioner worker will provide all tools it knows about // (after applying explicitly specified constraints), which may // include tools for architectures other than the host's. We // must constrain to the host's architecture for LXC. archTools, err := matchHostArchTools(args.Tools) if err != nil { return nil, errors.Trace(err) } series := archTools.OneSeries() args.InstanceConfig.MachineContainerType = instance.LXC if err := args.InstanceConfig.SetTools(archTools); err != nil { return nil, errors.Trace(err) } storageConfig := &container.StorageConfig{ AllowMount: config.AllowLXCLoopMounts, } if err := instancecfg.PopulateInstanceConfig( args.InstanceConfig, config.ProviderType, config.AuthorizedKeys, config.SSLHostnameVerification, config.Proxy, config.AptProxy, config.AptMirror, config.PreferIPv6, config.EnableOSRefreshUpdate, config.EnableOSUpgrade, ); err != nil { lxcLogger.Errorf("failed to populate machine config: %v", err) return nil, err } inst, hardware, err := broker.manager.CreateContainer(args.InstanceConfig, series, network, storageConfig, args.StatusCallback) if err != nil { lxcLogger.Errorf("failed to start container: %v", err) return nil, err } lxcLogger.Infof("started lxc container for machineId: %s, %s, %s", machineId, inst.Id(), hardware.String()) return &environs.StartInstanceResult{ Instance: inst, Hardware: hardware, NetworkInfo: network.Interfaces, }, nil }
// StartInstance is specified in the Broker interface. func (broker *kvmBroker) StartInstance(args environs.StartInstanceParams) (*environs.StartInstanceResult, error) { if args.InstanceConfig.HasNetworks() { return nil, errors.New("starting kvm containers with networks is not supported yet") } // TODO: refactor common code out of the container brokers. machineId := args.InstanceConfig.MachineId kvmLogger.Infof("starting kvm container for machineId: %s", machineId) // TODO: Default to using the host network until we can configure. Yes, // this is using the LxcBridge value, we should put it in the api call for // container config. bridgeDevice := broker.agentConfig.Value(agent.LxcBridge) if bridgeDevice == "" { bridgeDevice = kvm.DefaultKvmBridge } preparedInfo, err := prepareOrGetContainerInterfaceInfo( broker.api, machineId, bridgeDevice, true, // allocate if possible, do not maintain existing. broker.enableNAT, args.NetworkInfo, kvmLogger, ) if err != nil { // It's not fatal (yet) if we couldn't pre-allocate addresses for the // container. logger.Warningf("failed to prepare container %q network config: %v", machineId, err) } else { args.NetworkInfo = preparedInfo } // Unlike with LXC, we don't override the default MTU to use. network := container.BridgeNetworkConfig(bridgeDevice, 0, args.NetworkInfo) series := args.Tools.OneSeries() args.InstanceConfig.MachineContainerType = instance.KVM args.InstanceConfig.Tools = args.Tools[0] config, err := broker.api.ContainerConfig() if err != nil { kvmLogger.Errorf("failed to get container config: %v", err) return nil, err } if err := instancecfg.PopulateInstanceConfig( args.InstanceConfig, config.ProviderType, config.AuthorizedKeys, config.SSLHostnameVerification, config.Proxy, config.AptProxy, config.AptMirror, config.PreferIPv6, config.EnableOSRefreshUpdate, config.EnableOSUpgrade, ); err != nil { kvmLogger.Errorf("failed to populate machine config: %v", err) return nil, err } storageConfig := &container.StorageConfig{ AllowMount: true, } inst, hardware, err := broker.manager.CreateContainer(args.InstanceConfig, series, network, storageConfig, args.StatusCallback) if err != nil { kvmLogger.Errorf("failed to start container: %v", err) return nil, err } kvmLogger.Infof("started kvm container for machineId: %s, %s, %s", machineId, inst.Id(), hardware.String()) return &environs.StartInstanceResult{ Instance: inst, Hardware: hardware, NetworkInfo: network.Interfaces, }, nil }
func (broker *lxdBroker) StartInstance(args environs.StartInstanceParams) (*environs.StartInstanceResult, error) { machineId := args.InstanceConfig.MachineId bridgeDevice := broker.agentConfig.Value(agent.LxdBridge) if bridgeDevice == "" { bridgeDevice = network.DefaultLXDBridge } config, err := broker.api.ContainerConfig() if err != nil { lxdLogger.Errorf("failed to get container config: %v", err) return nil, err } preparedInfo, err := prepareOrGetContainerInterfaceInfo( broker.api, machineId, bridgeDevice, true, // allocate if possible, do not maintain existing. args.NetworkInfo, lxdLogger, ) if err != nil { // It's not fatal (yet) if we couldn't pre-allocate addresses for the // container. logger.Warningf("failed to prepare container %q network config: %v", machineId, err) } else { args.NetworkInfo = preparedInfo } network := container.BridgeNetworkConfig(bridgeDevice, 0, args.NetworkInfo) interfaces, err := finishNetworkConfig(bridgeDevice, args.NetworkInfo) if err != nil { return nil, errors.Trace(err) } network.Interfaces = interfaces // The provisioner worker will provide all tools it knows about // (after applying explicitly specified constraints), which may // include tools for architectures other than the host's. We // must constrain to the host's architecture for LXD. archTools, err := matchHostArchTools(args.Tools) if err != nil { return nil, errors.Trace(err) } series := archTools.OneSeries() args.InstanceConfig.MachineContainerType = instance.LXD if err := args.InstanceConfig.SetTools(archTools); err != nil { return nil, errors.Trace(err) } if err := instancecfg.PopulateInstanceConfig( args.InstanceConfig, config.ProviderType, config.AuthorizedKeys, config.SSLHostnameVerification, config.Proxy, config.AptProxy, config.AptMirror, config.EnableOSRefreshUpdate, config.EnableOSUpgrade, ); err != nil { lxdLogger.Errorf("failed to populate machine config: %v", err) return nil, err } storageConfig := &container.StorageConfig{} inst, hardware, err := broker.manager.CreateContainer( args.InstanceConfig, args.Constraints, series, network, storageConfig, args.StatusCallback, ) if err != nil { return nil, err } return &environs.StartInstanceResult{ Instance: inst, Hardware: hardware, NetworkInfo: interfaces, }, nil }
// StartInstance is specified in the Broker interface. func (broker *lxcBroker) StartInstance(args environs.StartInstanceParams) (*environs.StartInstanceResult, error) { if args.InstanceConfig.HasNetworks() { return nil, errors.New("starting lxc containers with networks is not supported yet") } // TODO: refactor common code out of the container brokers. machineId := args.InstanceConfig.MachineId lxcLogger.Infof("starting lxc container for machineId: %s", machineId) // Default to using the host network until we can configure. bridgeDevice := broker.agentConfig.Value(agent.LxcBridge) if bridgeDevice == "" { bridgeDevice = lxc.DefaultLxcBridge } if !environs.AddressAllocationEnabled() { logger.Debugf( "address allocation feature flag not enabled; using DHCP for container %q", machineId, ) } else { logger.Debugf("trying to allocate static IP for container %q", machineId) allocatedInfo, err := configureContainerNetwork( machineId, bridgeDevice, broker.api, args.NetworkInfo, true, // allocate a new address. broker.enableNAT, ) if err != nil { // It's fine, just ignore it. The effect will be that the // container won't have a static address configured. logger.Infof("not allocating static IP for container %q: %v", machineId, err) } else { args.NetworkInfo = allocatedInfo } } network := container.BridgeNetworkConfig(bridgeDevice, broker.defaultMTU, args.NetworkInfo) // The provisioner worker will provide all tools it knows about // (after applying explicitly specified constraints), which may // include tools for architectures other than the host's. We // must constrain to the host's architecture for LXC. archTools, err := args.Tools.Match(tools.Filter{ Arch: version.Current.Arch, }) if err == tools.ErrNoMatches { return nil, errors.Errorf( "need tools for arch %s, only found %s", version.Current.Arch, args.Tools.Arches(), ) } series := archTools.OneSeries() args.InstanceConfig.MachineContainerType = instance.LXC args.InstanceConfig.Tools = archTools[0] config, err := broker.api.ContainerConfig() if err != nil { lxcLogger.Errorf("failed to get container config: %v", err) return nil, err } storageConfig := &container.StorageConfig{ AllowMount: config.AllowLXCLoopMounts, } if err := instancecfg.PopulateInstanceConfig( args.InstanceConfig, config.ProviderType, config.AuthorizedKeys, config.SSLHostnameVerification, config.Proxy, config.AptProxy, config.AptMirror, config.PreferIPv6, config.EnableOSRefreshUpdate, config.EnableOSUpgrade, ); err != nil { lxcLogger.Errorf("failed to populate machine config: %v", err) return nil, err } inst, hardware, err := broker.manager.CreateContainer(args.InstanceConfig, series, network, storageConfig) if err != nil { lxcLogger.Errorf("failed to start container: %v", err) return nil, err } lxcLogger.Infof("started lxc container for machineId: %s, %s, %s", machineId, inst.Id(), hardware.String()) return &environs.StartInstanceResult{ Instance: inst, Hardware: hardware, NetworkInfo: network.Interfaces, }, nil }
// StartInstance is specified in the Broker interface. func (broker *kvmBroker) StartInstance(args environs.StartInstanceParams) (*environs.StartInstanceResult, error) { // TODO: refactor common code out of the container brokers. machineId := args.InstanceConfig.MachineId kvmLogger.Infof("starting kvm container for machineId: %s", machineId) // TODO: Default to using the host network until we can configure. Yes, // this is using the LxcBridge value, we should put it in the api call for // container config. bridgeDevice := broker.agentConfig.Value(agent.LxcBridge) if bridgeDevice == "" { bridgeDevice = container.DefaultKvmBridge } config, err := broker.api.ContainerConfig() if err != nil { kvmLogger.Errorf("failed to get container config: %v", err) return nil, err } preparedInfo, err := prepareOrGetContainerInterfaceInfo( broker.api, machineId, bridgeDevice, true, // allocate if possible, do not maintain existing. args.NetworkInfo, kvmLogger, ) if err != nil { // It's not fatal (yet) if we couldn't pre-allocate addresses for the // container. logger.Warningf("failed to prepare container %q network config: %v", machineId, err) } else { args.NetworkInfo = preparedInfo } network := container.BridgeNetworkConfig(bridgeDevice, 0, args.NetworkInfo) interfaces, err := finishNetworkConfig(bridgeDevice, args.NetworkInfo) if err != nil { return nil, errors.Trace(err) } network.Interfaces = interfaces // The provisioner worker will provide all tools it knows about // (after applying explicitly specified constraints), which may // include tools for architectures other than the host's. // // container/kvm only allows running container==host arch, so // we constrain the tools to host arch here regardless of the // constraints specified. archTools, err := matchHostArchTools(args.Tools) if err != nil { return nil, errors.Trace(err) } series := archTools.OneSeries() args.InstanceConfig.MachineContainerType = instance.KVM if err := args.InstanceConfig.SetTools(archTools); err != nil { return nil, errors.Trace(err) } if err := instancecfg.PopulateInstanceConfig( args.InstanceConfig, config.ProviderType, config.AuthorizedKeys, config.SSLHostnameVerification, config.Proxy, config.AptProxy, config.AptMirror, config.EnableOSRefreshUpdate, config.EnableOSUpgrade, ); err != nil { kvmLogger.Errorf("failed to populate machine config: %v", err) return nil, err } storageConfig := &container.StorageConfig{ AllowMount: true, } inst, hardware, err := broker.manager.CreateContainer( args.InstanceConfig, args.Constraints, series, network, storageConfig, args.StatusCallback, ) if err != nil { kvmLogger.Errorf("failed to start container: %v", err) return nil, err } kvmLogger.Infof("started kvm container for machineId: %s, %s, %s", machineId, inst.Id(), hardware.String()) return &environs.StartInstanceResult{ Instance: inst, Hardware: hardware, NetworkInfo: interfaces, }, nil }