本文整理匯總了Golang中github.com/Symantec/Dominator/lib/mdb.Machine類的典型用法代碼示例。如果您正苦於以下問題:Golang Machine類的具體用法?Golang Machine怎麽用?Golang Machine使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Machine類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: loadCis
func loadCis(reader io.Reader, logger *log.Logger) (*mdb.Mdb, error) {
type sourceType struct {
Name string
}
type hitType struct {
Source sourceType `json:"_source"`
}
type hitListType struct {
Hits []hitType
}
type inMdbType struct {
Hits hitListType
}
var inMdb inMdbType
var outMdb mdb.Mdb
decoder := json.NewDecoder(reader)
if err := decoder.Decode(&inMdb); err != nil {
return nil, errors.New("Error decoding: " + err.Error())
}
for _, hit := range inMdb.Hits.Hits {
var outMachine mdb.Machine
outMachine.Hostname = hit.Source.Name
outMdb.Machines = append(outMdb.Machines, outMachine)
}
return &outMdb, nil
}
示例2: loadDsHostFqdn
func loadDsHostFqdn(reader io.Reader, logger *log.Logger) (*mdb.Mdb, error) {
type machineType struct {
Fqdn string
}
type dataCentreType map[string]machineType
type inMdbType map[string]dataCentreType
var inMdb inMdbType
var outMdb mdb.Mdb
decoder := json.NewDecoder(reader)
if err := decoder.Decode(&inMdb); err != nil {
return nil, errors.New("Error decoding: " + err.Error())
}
for dsName, dataCentre := range inMdb {
for machineName, inMachine := range dataCentre {
var outMachine mdb.Machine
if inMachine.Fqdn == "" {
outMachine.Hostname = machineName + "." + dsName
} else {
outMachine.Hostname = inMachine.Fqdn
}
outMdb.Machines = append(outMdb.Machines, outMachine)
}
}
return &outMdb, nil
}
示例3: loadText
func loadText(reader io.Reader, logger *log.Logger) (*mdb.Mdb, error) {
scanner := bufio.NewScanner(reader)
var newMdb mdb.Mdb
for scanner.Scan() {
fields := strings.Fields(scanner.Text())
if len(fields) > 0 {
if fields[0][0] == '#' {
continue
}
var machine mdb.Machine
machine.Hostname = fields[0]
if len(fields) > 1 {
machine.RequiredImage = fields[1]
if len(fields) > 2 {
machine.PlannedImage = fields[2]
}
}
newMdb.Machines = append(newMdb.Machines, machine)
}
}
if err := scanner.Err(); err != nil {
return nil, err
}
return &newMdb, nil
}
示例4: extractMdb
func extractMdb(output *ec2.DescribeInstancesOutput) *mdb.Mdb {
var result mdb.Mdb
for _, reservation := range output.Reservations {
for _, instance := range reservation.Instances {
if instance.PrivateDnsName != nil {
machine := mdb.Machine{
Hostname: *instance.PrivateDnsName,
AwsMetadata: &mdb.AwsMetadata{
InstanceId: *instance.InstanceId,
},
}
if instance.PrivateIpAddress != nil {
machine.IpAddress = *instance.PrivateIpAddress
}
extractTags(instance.Tags, &machine)
result.Machines = append(result.Machines, machine)
}
}
}
return &result
}
示例5: extractTags
func extractTags(tags []*ec2.Tag, machine *mdb.Machine) {
for _, tag := range tags {
switch *tag.Key {
case "RequiredImage":
if tag.Value != nil {
machine.RequiredImage = *tag.Value
}
case "PlannedImage":
if tag.Value != nil {
machine.PlannedImage = *tag.Value
}
case "DisableUpdates":
if tag.Value != nil {
machine.DisableUpdates = true
}
case "OwnerGroup":
if tag.Value != nil {
machine.OwnerGroup = *tag.Value
}
}
}
}
示例6: loadCis
func loadCis(reader io.Reader, datacentre string, logger *log.Logger) (
*mdb.Mdb, error) {
type instanceMetadataType struct {
RequiredImage string `json:"required_image"`
PlannedImage string `json:"planned_image"`
DisableUpdates bool `json:"disable_updates"`
OwnerGroup string `json:"owner_group"`
}
type sourceType struct {
HostName string `json:"host_name"`
InstanceMetadata instanceMetadataType `json:"instance_metadata"`
Fqdn string
}
type hitType struct {
Source sourceType `json:"_source"`
}
type hitListType struct {
Hits []hitType
}
type inMdbType struct {
Hits hitListType
}
var inMdb inMdbType
var outMdb mdb.Mdb
decoder := json.NewDecoder(reader)
if err := decoder.Decode(&inMdb); err != nil {
return nil, errors.New("Error decoding: " + err.Error())
}
for _, hit := range inMdb.Hits.Hits {
var outMachine mdb.Machine
if hit.Source.Fqdn != "" {
outMachine.Hostname = hit.Source.Fqdn
} else {
outMachine.Hostname = hit.Source.HostName
}
outMachine.RequiredImage = hit.Source.InstanceMetadata.RequiredImage
outMachine.PlannedImage = hit.Source.InstanceMetadata.PlannedImage
outMachine.DisableUpdates = hit.Source.InstanceMetadata.DisableUpdates
outMachine.OwnerGroup = hit.Source.InstanceMetadata.OwnerGroup
outMdb.Machines = append(outMdb.Machines, outMachine)
}
return &outMdb, nil
}