hostlist

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

(C) Copyright 2019 Intel Corporation.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

(C) Copyright 2019 Intel Corporation.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

GOVERNMENT LICENSE RIGHTS-OPEN SOURCE SOFTWARE The Government's rights to use, modify, reproduce, release, perform, display, or disclose this software are subject to the terms of the Apache License as provided in Contract No. 8F-30005. Any reproduction of computer software, computer software documentation, or portions thereof marked with this legend must also reproduce the markings.

Index

Constants

View Source
const (
	// MaxRange is the largest host range (hi - lo) supported
	MaxRange = 16384
)

Variables

View Source
var (
	ErrEmpty    = errors.New("hostlist is empty")
	ErrNotFound = errors.New("hostname not found")
)

Functions

func Compress

func Compress(stringHosts string) (string, error)

Compress converts the supplied host list into a string of ranged host strings.

func Count

func Count(stringHosts string) (int, error)

Count returns the number of distinct hosts in the supplied host list.

func Expand

func Expand(stringHosts string) (string, error)

Expand converts a ranged host string into an expanded string of all hosts in the supplied range(s).

Types

type HostGroups

type HostGroups map[string]*HostSet

func (HostGroups) AddHost

func (hg HostGroups) AddHost(key, host string) error

func (HostGroups) Keys

func (hg HostGroups) Keys() []string

func (HostGroups) String

func (hg HostGroups) String() string

type HostList

type HostList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

HostList is a list of hostnames optimized for a "prefixXXXX" naming convention, where XXXX is a decimal, numeric suffix.

func Create

func Create(stringHosts string) (*HostList, error)

Create creates a new HostList from the supplied string representation.

func (*HostList) Count

func (hl *HostList) Count() int

Count returns the number of hosts in the HostList.

func (*HostList) Delete

func (hl *HostList) Delete(stringHosts string) (int, error)

Delete removes all hosts in the supplied string representation of a HostList. Returns the number of hosts successfully deleted.

func (*HostList) DeleteHost

func (hl *HostList) DeleteHost(stringHost string) error

DeleteHost removes the first host that matches the supplied hostname. Returns an error if the HostList is empty or the hostname is not found.

func (*HostList) DeleteNth

func (hl *HostList) DeleteNth(n int) error

DeleteNth removes the host at position N in the HostList. Returns an error if the HostList is empty or the index is incorrect.

func (*HostList) DerangedString

func (hl *HostList) DerangedString() string

DerangedString returns a string containing the hostnames of every host in the HostList, without any bracketing.

func (*HostList) Find

func (hl *HostList) Find(stringHost string) (int, bool)

Find searches the HostList for the given hostname. Returns the index of the host and true if found; -1 and false if not.

func (*HostList) Intersects

func (hl *HostList) Intersects(stringHosts string) (*HostList, error)

Intersects returns a *HostList containing hosts which are in both this HostList and the supplied hosts string.

func (*HostList) IsEmpty

func (hl *HostList) IsEmpty() bool

IsEmpty returns true if the HostList has zero hosts.

func (*HostList) Nth

func (hl *HostList) Nth(n int) (string, error)

Nth returns the string represenation of the n-th host in the HostList. Returns an error if the index is invalid.

func (*HostList) Pop

func (hl *HostList) Pop() (hostName string, err error)

Pop returns the string representation of the last host pushed onto the HostList and then removes it from the HostList. Returns an error if the HostList is empty.

func (*HostList) PopRange

func (hl *HostList) PopRange() (hostRange string, err error)

PopRange returns the string representation of the last bracketed list of hosts. All hosts in the returned list are removed from the HostList. Returns an error if the HostList is empty.

func (*HostList) Push

func (hl *HostList) Push(stringHosts string) error

Push adds a string representation of hostnames to this HostList.

func (*HostList) PushHost

func (hl *HostList) PushHost(stringHost string) error

PushHost adds a single host to this HostList.

func (*HostList) PushList

func (hl *HostList) PushList(other *HostList) error

PushList adds the supplied HostList onto this HostList.

func (*HostList) RangedString

func (hl *HostList) RangedString() string

RangedString returns a string containing a bracketed HostList representation.

func (*HostList) Shift

func (hl *HostList) Shift() (hostName string, err error)

Shift returns the string representation of the first host pushed onto the HostList and then removes it from the HostList. Returns an error if the HostList is empty.

func (*HostList) ShiftRange

func (hl *HostList) ShiftRange() (hostRange string, err error)

ShiftRange returns the string representation of the first bracketed list of hosts. All hosts in the returned list are removed from the HostList. Returns an error if the HostList is empty.

func (*HostList) String

func (hl *HostList) String() string

String returns a ranged string representation of the HostList.

func (*HostList) Uniq

func (hl *HostList) Uniq()

Uniq forces a sort operation on the HostList and removes duplicates.

func (*HostList) Within

func (hl *HostList) Within(stringHosts string) (bool, error)

Within returns true if all hosts in the supplied hosts are contained within the HostList, false otherwise.

type HostSet

type HostSet struct {
	sync.Mutex
	// contains filtered or unexported fields
}

HostSet is a special case of HostList which never contains duplicates and is always sorted alphanumerically based on prefix.

func CreateSet

func CreateSet(stringHosts string) (*HostSet, error)

CreateSet creates a new HostSet from the supplied string representation.

func (*HostSet) Count

func (hs *HostSet) Count() int

Count returns the number of hosts in the HostSet.

func (*HostSet) Delete

func (hs *HostSet) Delete(stringHosts string) (int, error)

Delete removes a host or list of hosts from the HostSet. Returns the number of hosts successfully removed.

func (*HostSet) DerangedString

func (hs *HostSet) DerangedString() string

DerangedString returns a string containing the hostnames of every host in the HostSet, without any bracketing.

func (*HostSet) Insert

func (hs *HostSet) Insert(stringHosts string) (int, error)

Insert adds a host or list of hosts to the HostSet. Returns the number of non-duplicate hosts successfully added.

func (*HostSet) Intersects

func (hs *HostSet) Intersects(stringHosts string) (*HostSet, error)

Intersects returns a *HostSet containing hosts which are in both this HostSet and the supplied hosts string.

func (*HostSet) MergeSet

func (hs *HostSet) MergeSet(other *HostSet) error

MergeSet merges the supplied HostSet into this one.

func (*HostSet) Pop

func (hs *HostSet) Pop() (string, error)

Pop returns the string representation of the last host pushed onto the HostSet and then removes it from the HostSet. Returns an error if the HostSet is empty

func (*HostSet) PopRange

func (hs *HostSet) PopRange() (string, error)

PopRange returns the string representation of the last bracketed list of hosts. All hosts in the returned list are removed from the HostSet. Returns an error if the HostSet is empty.

func (*HostSet) RangedString

func (hs *HostSet) RangedString() string

RangedString returns a string containing a bracketed HostSet representation.

func (*HostSet) Shift

func (hs *HostSet) Shift() (string, error)

Shift returns the string representation of the first host pushed onto the HostSet and then removes it from the HostSet. Returns an error if the HostSet is empty

func (*HostSet) ShiftRange

func (hs *HostSet) ShiftRange() (string, error)

ShiftRange returns the string representation of the first bracketed list of hosts. All hosts in the returned list are removed from the HostSet. Returns an error if the HostSet is empty.

func (*HostSet) String

func (hs *HostSet) String() string

func (*HostSet) Within

func (hs *HostSet) Within(stringHosts string) (bool, error)

Within returns true if all hosts in the supplied hosts are contained within the HostSet, false otherwise.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL