Esempio n. 1
0
func (env *environ) destroyHostedModelResources() error {
	// Destroy all instances where juju-controller-uuid,
	// but not juju-model-uuid, matches env.uuid.
	prefix := common.EnvFullName("")
	instances, err := env.prefixedInstances(prefix)
	if err != nil {
		return errors.Annotate(err, "listing instances")
	}
	logger.Debugf("instances: %v", instances)
	var names []string
	for _, inst := range instances {
		metadata := inst.raw.Metadata()
		if metadata[tags.JujuModel] == env.uuid {
			continue
		}
		if metadata[tags.JujuController] != env.uuid {
			continue
		}
		names = append(names, string(inst.Id()))
	}
	if err := env.raw.RemoveInstances(prefix, names...); err != nil {
		return errors.Annotate(err, "removing hosted model instances")
	}
	return nil
}
Esempio n. 2
0
func (s *environSuite) TestDestroyHostedModels(c *gc.C) {
	s.UpdateConfig(c, map[string]interface{}{
		"controller-uuid": s.Config.UUID(),
	})
	s.Stub.ResetCalls()

	// machine0 is in the controller model.
	machine0 := s.NewRawInstance(c, "juju-whatever-machine-0")
	machine0.InstanceSummary.Metadata["juju-model-uuid"] = s.Config.UUID()
	machine0.InstanceSummary.Metadata["juju-controller-uuid"] = s.Config.UUID()
	// machine1 is not in the controller model, but managed
	// by the same controller.
	machine1 := s.NewRawInstance(c, "juju-whatever-machine-1")
	machine1.InstanceSummary.Metadata["juju-model-uuid"] = "not-" + s.Config.UUID()
	machine1.InstanceSummary.Metadata["juju-controller-uuid"] = s.Config.UUID()
	// machine2 is not managed by the same controller.
	machine2 := s.NewRawInstance(c, "juju-whatever-machine-2")
	machine2.InstanceSummary.Metadata["juju-model-uuid"] = "not-" + s.Config.UUID()
	machine2.InstanceSummary.Metadata["juju-controller-uuid"] = "not-" + s.Config.UUID()
	s.Client.Insts = append(s.Client.Insts, *machine0, *machine1, *machine2)

	err := s.Env.DestroyController(s.Config.UUID())
	c.Assert(err, jc.ErrorIsNil)

	prefix := s.Prefix()
	fwname := common.EnvFullName(s.Env.Config().UUID())
	s.Stub.CheckCalls(c, []gitjujutesting.StubCall{
		{"Ports", []interface{}{fwname}},
		{"Destroy", nil},
		{"Instances", []interface{}{prefix, lxdclient.AliveStatuses}},
		{"RemoveInstances", []interface{}{prefix, []string{machine1.Name}}},
	})
}
Esempio n. 3
0
func (s *environSuite) TestDestroyAPI(c *gc.C) {
	err := s.Env.Destroy()
	c.Assert(err, jc.ErrorIsNil)

	fwname := common.EnvFullName(s.Env.Config().UUID())
	s.Stub.CheckCalls(c, []gitjujutesting.StubCall{{
		FuncName: "Ports",
		Args: []interface{}{
			fwname,
		},
	}, {
		FuncName: "Destroy",
		Args:     nil,
	}})
}
Esempio n. 4
0
func (s *environSuite) TestDestroyAPI(c *gc.C) {
	err := s.Env.Destroy()
	c.Assert(err, jc.ErrorIsNil)

	c.Check(s.FakeConn.Calls, gc.HasLen, 1)
	c.Check(s.FakeConn.Calls[0].FuncName, gc.Equals, "Ports")
	fwname := common.EnvFullName(s.Env.Config().UUID())
	c.Check(s.FakeConn.Calls[0].FirewallName, gc.Equals, fwname)
	s.FakeCommon.CheckCalls(c, []gce.FakeCall{{
		FuncName: "Destroy",
		Args: gce.FakeCallArgs{
			"switch": s.Env,
		},
	}})
}
Esempio n. 5
0
// globalFirewallName returns the name to use for the global firewall.
func (env *environ) globalFirewallName() string {
	return common.EnvFullName(env)
}