예제 #1
0
파일: list.go 프로젝트: hdansou/rack
func (command *commandList) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsList).opts
	opts.Full = true
	containerName := resource.Params.(*paramsList).container
	allPages := resource.Params.(*paramsList).allPages
	pager := objects.List(command.Ctx.ServiceClient, containerName, opts)
	if allPages {
		pages, err := pager.AllPages()
		if err != nil {
			resource.Err = err
			return
		}
		info, err := objects.ExtractInfo(pages)
		if err != nil {
			resource.Err = err
			return
		}
		result := make([]map[string]interface{}, len(info))
		for j, obj := range info {
			result[j] = structs.Map(&obj)
		}
		resource.Result = result
	} else {
		limit := opts.Limit
		err := pager.EachPage(func(page pagination.Page) (bool, error) {
			info, err := objects.ExtractInfo(page)
			if err != nil {
				return false, err
			}
			result := make([]map[string]interface{}, len(info))
			for j, obj := range info {
				result[j] = structs.Map(&obj)
			}
			resource.Result = result
			if len(info) >= limit {
				return false, nil
			}
			limit -= len(info)
			command.Ctx.WaitGroup.Add(1)
			command.Ctx.Results <- resource
			return true, nil
		})
		if err != nil {
			resource.Err = err
			return
		}
	}
}
예제 #2
0
파일: common.go 프로젝트: hdansou/rack
func securityGroupRuleSingle(rule *osSecurityGroupRules.SecGroupRule) map[string]interface{} {
	m := structs.Map(rule)

	m["SecurityGroupID"] = m["SecGroupID"]

	return m
}
예제 #3
0
파일: list.go 프로젝트: harshalhshah/rack
func (command *commandList) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsList).opts
	allPages := resource.Params.(*paramsList).allPages
	pager := flavors.ListDetail(command.Ctx.ServiceClient, opts)
	if allPages {
		pages, err := pager.AllPages()
		if err != nil {
			resource.Err = err
			return
		}
		info, err := flavors.ExtractFlavors(pages)
		if err != nil {
			resource.Err = err
			return
		}
		result := make([]map[string]interface{}, len(info))
		for j, flavor := range info {
			result[j] = structs.Map(flavor)
		}
		resource.Result = result
	} else {
		limit := opts.Limit
		err := pager.EachPage(func(page pagination.Page) (bool, error) {
			info, err := flavors.ExtractFlavors(page)
			if err != nil {
				return false, err
			}
			result := make([]map[string]interface{}, len(info))
			for j, flavor := range info {
				result[j] = structs.Map(flavor)
			}
			resource.Result = result
			if len(info) >= opts.Limit {
				return false, nil
			}
			limit -= len(info)
			command.Ctx.Results <- resource
			return true, nil
		})
		if err != nil {
			resource.Err = err
			return
		}
	}
}
예제 #4
0
파일: create.go 프로젝트: harshalhshah/rack
func (command *commandCreate) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsCreate)
	volumeAttachment, err := osVolumeAttach.Create(command.Ctx.ServiceClient, params.serverID, params.opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(volumeAttachment)
}
예제 #5
0
파일: common.go 프로젝트: hdansou/rack
func volumeSingle(volume *volumes.Volume) map[string]interface{} {
	m := structs.Map(volume)
	for k, v := range m {
		if v == nil {
			m[k] = ""
		}
	}
	return m
}
예제 #6
0
func (command *commandGenerate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsGenerate).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(keypair)
}
예제 #7
0
파일: get.go 프로젝트: harshalhshah/rack
func (command *commandGet) Execute(resource *handler.Resource) {
	flavorID := resource.Params.(*paramsGet).flavor
	flavor, err := flavors.Get(command.Ctx.ServiceClient, flavorID).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(flavor)
}
예제 #8
0
파일: get.go 프로젝트: hdansou/rack
func (command *commandGet) Execute(resource *handler.Resource) {
	imageID := resource.Params.(*paramsGet).image
	image, err := images.Get(command.Ctx.ServiceClient, imageID).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(image)
}
예제 #9
0
파일: common.go 프로젝트: hdansou/rack
func networkSingle(network *osNetworks.Network) map[string]interface{} {
	m := structs.Map(network)
	m["Up"] = m["AdminStateUp"]
	m["Tenant ID"] = m["TenantID"]
	if subnets, ok := m["Subnets"].([]string); ok {
		m["Subnets"] = strings.Join(subnets, ",")
	}
	return m
}
예제 #10
0
파일: get.go 프로젝트: harshalhshah/rack
func (command *commandGet) Execute(resource *handler.Resource) {
	keypairName := resource.Params.(*paramsGet).keypair
	keypair, err := keypairs.Get(command.Ctx.ServiceClient, keypairName).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(keypair)
}
예제 #11
0
파일: common.go 프로젝트: hdansou/rack
func snapshotSingle(snapshot *osSnapshots.Snapshot) map[string]interface{} {
	m := structs.Map(snapshot)
	if attachments := m["Attachments"].([]string); len(attachments) > 0 {
		m["Attachments"] = strings.Join(attachments, ",")
	} else {
		m["Attachments"] = ""
	}
	return m
}
예제 #12
0
파일: get.go 프로젝트: hdansou/rack
func (command *commandGet) Execute(resource *handler.Resource) {
	containerName := resource.Params.(*paramsGet).container
	containerInfo, err := containers.Get(command.Ctx.ServiceClient, containerName).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(containerInfo)
	resource.Result.(map[string]interface{})["Name"] = containerName
}
예제 #13
0
파일: generate.go 프로젝트: mrhillsman/rack
func (command *commandGenerate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsGenerate).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	c := command.Ctx.CLIContext
	if c.IsSet("json") || c.IsSet("csv") || c.GlobalIsSet("json") || c.GlobalIsSet("csv") {
		resource.Result = structs.Map(keypair)
	} else {
		resource.Result = printGenerate(keypair)
	}
}
예제 #14
0
파일: generate.go 프로젝트: hdansou/rack
func (command *commandGenerate) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsGenerate).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}

	if command.Ctx.OutputFormat == "json" || command.Ctx.OutputFormat == "csv" {
		resource.Result = structs.Map(keypair)
	} else {
		resource.Result = printGenerate(keypair)
	}
}
예제 #15
0
파일: get.go 프로젝트: hdansou/rack
func (command *commandGet) Execute(resource *handler.Resource) {
	keypairName := resource.Params.(*paramsGet).keypair
	keypair, err := keypairs.Get(command.Ctx.ServiceClient, keypairName).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	result := structs.Map(keypair)
	if command.Ctx.OutputFormat == "json" {
		resource.Result = result
	} else {
		// Assume they want the key directly
		resource.Result = result["PublicKey"]
	}
}
예제 #16
0
파일: get.go 프로젝트: harshalhshah/rack
func (command *commandGet) Execute(resource *handler.Resource) {
	containerName := resource.Params.(*paramsGet).container
	objectName := resource.Params.(*paramsGet).object
	objectRaw := objects.Get(command.Ctx.ServiceClient, containerName, objectName, nil)
	objectInfo, err := objectRaw.Extract()
	if err != nil {
		resource.Err = err
		return
	}
	objectMetadata, err := objectRaw.ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(objectInfo)
	resource.Result.(map[string]interface{})["Name"] = objectName
	resource.Result.(map[string]interface{})["Metadata"] = objectMetadata
}
예제 #17
0
파일: list.go 프로젝트: harshalhshah/rack
func (command *commandList) Execute(resource *handler.Resource) {
	err := keypairs.List(command.Ctx.ServiceClient).EachPage(func(page pagination.Page) (bool, error) {
		info, err := osKeypairs.ExtractKeyPairs(page)
		if err != nil {
			return false, err
		}
		result := make([]map[string]interface{}, len(info))
		for j, key := range info {
			result[j] = structs.Map(key)
		}
		resource.Result = result
		return false, nil
	})
	if err != nil {
		resource.Err = err
		return
	}
}
예제 #18
0
파일: list.go 프로젝트: harshalhshah/rack
func (command *commandList) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsList)
	err := osVolumeAttach.List(command.Ctx.ServiceClient, params.serverID).EachPage(func(page pagination.Page) (bool, error) {
		volumeAttachments, err := osVolumeAttach.ExtractVolumeAttachments(page)
		if err != nil {
			return false, err
		}
		result := make([]map[string]interface{}, len(volumeAttachments))
		for j, volumeAttachment := range volumeAttachments {
			result[j] = structs.Map(volumeAttachment)
		}
		resource.Result = result
		return false, nil
	})
	if err != nil {
		resource.Err = err
		return
	}
}
예제 #19
0
파일: common.go 프로젝트: hdansou/rack
func serverSingle(rawServer interface{}) map[string]interface{} {
	server, ok := rawServer.(*osServers.Server)
	if !ok {
		return nil
	}
	m := structs.Map(rawServer)
	m["Public IPv4"] = server.AccessIPv4
	m["Public IPv6"] = server.AccessIPv6
	m["Private IPv4"] = ""
	ips, ok := server.Addresses["private"].([]interface{})
	if ok || len(ips) > 0 {
		priv, ok := ips[0].(map[string]interface{})
		if ok {
			m["Private IPv4"] = priv["addr"]
		}
	}
	m["Flavor"] = server.Flavor["id"]
	m["Image"] = server.Image["id"]
	return m
}
예제 #20
0
파일: common.go 프로젝트: hdansou/rack
func portSingle(port *osPorts.Port) map[string]interface{} {
	m := structs.Map(port)

	if fixedIPs, ok := m["FixedIPs"].([]osPorts.IP); ok && len(fixedIPs) > 0 {
		out := []string{"Subnet ID\tIP Address"}
		for _, ip := range fixedIPs {
			out = append(out, fmt.Sprintf("%s\t%s", ip.SubnetID, ip.IPAddress))
		}
		m["FixedIPs"] = strings.Join(out, "\n")
	} else {
		m["FixedIPs"] = ""
	}

	if nameServers, ok := m["SecurityGroups"].([]string); ok && len(nameServers) > 0 {
		m["SecurityGroups"] = strings.Join(nameServers, "\n")
	} else {
		m["SecurityGroups"] = ""
	}

	return m
}
예제 #21
0
파일: common.go 프로젝트: hdansou/rack
func subnetSingle(subnet *osSubnets.Subnet) map[string]interface{} {
	m := structs.Map(subnet)

	if allocationPools, ok := m["AllocationPools"].([]osSubnets.AllocationPool); ok && len(allocationPools) > 0 {
		out := []string{"Start\tEnd"}
		for _, pool := range allocationPools {
			out = append(out, fmt.Sprintf("%s\t%s", pool.Start, pool.End))
		}
		m["Allocation Pools"] = strings.Join(out, "\n")
	}

	/*
		m["Host Routes"] = m["HostRoutes"]
		delete(m, "HostRoutes")
		if hostRoutes, ok := m["Host Routes"].([]osSubnets.HostRoute); ok && len(hostRoutes) > 0 {
			fmt.Printf("hostRoutes: %+v\n", hostRoutes)
			out := []string{"Destination CIDR\tNext Hop"}
			for _, route := range hostRoutes {
				out = append(out, fmt.Sprintf("%s\t%s", route.DestinationCIDR, route.NextHop))
			}
			m["Host Routes"] = strings.Join(out, "\n")
		} else {
			m["Host Routes"] = ""
		}
	*/

	if nameServers, ok := m["DNSNameservers"].([]string); ok && len(nameServers) > 0 {
		m["DNS Nameservers"] = strings.Join(nameServers, "\n")
	} else {
		m["DNS Nameservers"] = ""
	}

	m["Tenant ID"] = m["TenantID"]
	m["Network ID"] = m["NetworkID"]
	m["Gateway IP"] = m["GatewayIP"]

	return m
}