コード例 #1
0
ファイル: remove.go プロジェクト: jak-atx/vic
func (cmd *remove) Remove(ctx context.Context, host *object.HostSystem) error {
	var h mo.HostSystem
	err := host.Properties(ctx, host.Reference(), []string{"parent"}, &h)
	if err != nil {
		return err
	}

	remove := host.Destroy

	if h.Parent.Type == "ComputeResource" {
		// Standalone host.  From the docs:
		// "Invoking remove on a HostSystem of standalone type throws a NotSupported fault.
		//  A standalone HostSystem can be removeed only by invoking remove on its parent ComputeResource."
		remove = object.NewComputeResource(host.Client(), *h.Parent).Destroy
	}

	task, err := remove(ctx)
	if err != nil {
		return err
	}

	logger := cmd.ProgressLogger(fmt.Sprintf("%s removing... ", host.InventoryPath))
	defer logger.Wait()

	_, err = task.WaitForResult(ctx, logger)
	return err
}
コード例 #2
0
ファイル: firewall_info.go プロジェクト: jak-atx/vic
// GetFirewallInfo via 'esxcli network firewall get'
// The HostFirewallSystem type does not expose this data.
// This helper can be useful in particular to determine if the firewall is enabled or disabled.
func GetFirewallInfo(s *object.HostSystem) (*FirewallInfo, error) {
	x, err := NewExecutor(s.Client(), s)

	res, err := x.Run([]string{"network", "firewall", "get"})
	if err != nil {
		return nil, err
	}

	info := &FirewallInfo{
		Loaded:        res.Values[0]["Loaded"][0] == "true",
		Enabled:       res.Values[0]["Enabled"][0] == "true",
		DefaultAction: res.Values[0]["DefaultAction"][0],
	}

	return info, nil
}