Example #1
0
func subnetSingle(subnet *osSubnets.Subnet) map[string]interface{} {
	m := structs.Map(subnet)

	tmpMap := make([]map[string]interface{}, len(m["AllocationPools"].([]osSubnets.AllocationPool)))
	for i, pool := range m["AllocationPools"].([]osSubnets.AllocationPool) {
		tmpMap[i] = structs.Map(pool)
	}

	m["AllocationPools"] = tmpMap

	/*
		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["DNSNameservers"] = strings.Join(nameServers, ", ")
	} else {
		m["DNSNameservers"] = ""
	}

	return m
}
Example #2
0
func portSingle(port *osPorts.Port) map[string]interface{} {
	m := structs.Map(port)

	tmpMap := make([]map[string]interface{}, len(m["FixedIPs"].([]osPorts.IP)))
	for i, pool := range m["FixedIPs"].([]osPorts.IP) {
		tmpMap[i] = structs.Map(pool)
	}

	m["FixedIPs"] = tmpMap

	m["Up"] = m["AdminStateUp"]

	/*
		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
}
Example #3
0
func securityGroupSingle(securityGroup *osSecurityGroups.SecGroup) map[string]interface{} {
	m := structs.Map(securityGroup)

	tmpMap := make([]map[string]interface{}, len(m["Rules"].([]osSecurityGroupRules.SecGroupRule)))
	for i, pool := range m["Rules"].([]osSecurityGroupRules.SecGroupRule) {
		tmpMap[i] = map[string]interface{}{
			"ID":        pool.ID,
			"Direction": pool.Direction,
			"EtherType": pool.EtherType,
			"Protocol":  pool.Protocol,
		}
	}

	m["Rules"] = tmpMap

	/*
		if rules, ok := m["Rules"].([]osSecurityGroupRules.SecGroupRule); ok && len(rules) > 0 {
			out := []string{"ID\tDirection\tEtherType\tProtocol"}
			for _, rule := range rules {
				out = append(out, fmt.Sprintf("%s\t%s\t%s\t%s", rule.ID, rule.Direction, rule.EtherType, rule.Protocol))
			}
			m["Rules"] = strings.Join(out, "\n")
		} else {
			m["Rules"] = ""
		}
	*/

	return m
}
Example #4
0
func (command *commandGetSchema) PreCSV(resource *handler.Resource) error {
	resource.Result = structs.Map(resource.Result)
	resource.FlattenMap("Attributes")
	resource.FlattenMap("Properties")
	resource.FlattenMap("SupportStatus")
	return nil
}
Example #5
0
func securityGroupRuleSingle(rule *osSecurityGroupRules.SecGroupRule) map[string]interface{} {
	m := structs.Map(rule)

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

	return m
}
Example #6
0
func resourceSingle(rawResource interface{}) map[string]interface{} {
	m := structs.Map(rawResource)
	switch resource := rawResource.(type) {
	case *osStackResources.Resource:
		if resource.CreationTime.Unix() != -62135596800 {
			m["CreationTime"] = resource.CreationTime
		} else {
			m["CreationTime"] = ""
		}
		if resource.UpdatedTime.Unix() != -62135596800 {
			m["UpdatedTime"] = resource.UpdatedTime
		} else {
			m["UpdatedTime"] = ""
		}
		if resource.Links != nil {
			links := make([]map[string]interface{}, len(resource.Links))
			for i, link := range resource.Links {
				links[i] = map[string]interface{}{
					"Href": link.Href,
					"Rel":  link.Rel,
				}
			}
			m["Links"] = links
		}
		return m
	}
	return nil

}
Example #7
0
func (command *commandListEvents) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsListEvents)
	opts := params.opts
	stackName := params.stackName
	stackID := params.stackID
	resourceName := params.resourceName

	pager := stackevents.ListResourceEvents(command.Ctx.ServiceClient, stackName, stackID, resourceName, opts)

	pages, err := pager.AllPages()
	if err != nil {
		resource.Err = err
		return
	}
	info, err := osStackEvents.ExtractResourceEvents(pages)
	if err != nil {
		resource.Err = err
		return
	}
	result := make([]map[string]interface{}, len(info))
	for j, event := range info {
		result[j] = structs.Map(&event)
		result[j]["Time"] = event.Time
	}
	resource.Result = result
}
Example #8
0
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.Results <- resource
			return true, nil
		})
		if err != nil {
			resource.Err = err
			return
		}
	}
}
Example #9
0
func (command *commandGet) Execute(resource *handler.Resource) {
	buildids, err := buildinfo.Get(command.Ctx.ServiceClient).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(buildids)
}
Example #10
0
func (command *commandAbandon) PreCSV(resource *handler.Resource) error {
	resource.Result = structs.Map(resource.Result)
	resource.FlattenMap("Template")
	resource.FlattenMap("Files")
	resource.FlattenMap("Environment")
	resource.FlattenMap("Resources")
	return nil
}
Example #11
0
func networkSingle(network *osNetworks.Network) map[string]interface{} {
	m := structs.Map(network)
	m["Up"] = m["AdminStateUp"]
	if subnets, ok := m["Subnets"].([]string); ok {
		m["Subnets"] = strings.Join(subnets, ",")
	}
	return m
}
Example #12
0
func volumeSingle(volume *volumes.Volume) map[string]interface{} {
	m := structs.Map(volume)
	for k, v := range m {
		if v == nil {
			m[k] = ""
		}
	}
	return m
}
Example #13
0
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)
}
Example #14
0
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)
}
Example #15
0
func (command *commandUpload) Execute(resource *handler.Resource) {
	opts := resource.Params.(*paramsUpload).opts
	keypair, err := keypairs.Create(command.Ctx.ServiceClient, opts).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(keypair)
}
Example #16
0
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)
}
Example #17
0
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)
}
Example #18
0
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
}
Example #19
0
func (command *commandValidate) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsValidate).opts

	result, err := stacktemplates.Validate(command.Ctx.ServiceClient, params).Extract()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(result)
}
Example #20
0
func (command *commandGet) Execute(resource *handler.Resource) {
	info, err := buildinfo.Get(command.Ctx.ServiceClient).Extract()
	if err != nil {
		resource.Err = err
	}
	result := structs.Map(info)
	for k, v := range result {
		result[k] = v.(map[string]interface{})["Revision"]
	}
	resource.Result = result
}
Example #21
0
func securityGroupSingle(securityGroup *osSecurityGroups.SecGroup) map[string]interface{} {
	m := structs.Map(securityGroup)

	if rules, ok := m["Rules"].([]osSecurityGroupRules.SecGroupRule); ok && len(rules) > 0 {
		out := []string{"ID\tDirection\tEtherType\tProtocol"}
		for _, rule := range rules {
			out = append(out, fmt.Sprintf("%s\t%s\t%s\t%s", rule.ID, rule.Direction, rule.EtherType, rule.Protocol))
		}
		m["Rules"] = strings.Join(out, "\n")
	} else {
		m["Rules"] = ""
	}

	return m
}
Example #22
0
func (command *commandGet) Execute(resource *handler.Resource) {
	containerName := resource.Params.(*paramsGet).container
	containerRaw := containers.Get(command.Ctx.ServiceClient, containerName)
	containerInfo, err := containerRaw.Extract()
	if err != nil {
		resource.Err = err
		return
	}
	containerMetadata, err := containerRaw.ExtractMetadata()
	if err != nil {
		resource.Err = err
		return
	}
	resource.Result = structs.Map(containerInfo)
	resource.Result.(map[string]interface{})["Name"] = containerName
	resource.Result.(map[string]interface{})["Metadata"] = containerMetadata
}
Example #23
0
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
	}
}
Example #24
0
func stackList(client *gophercloud.ServiceClient) ([]map[string]interface{}, error) {
	pager := osStacks.List(client, nil)
	pages, err := pager.AllPages()
	if err != nil {
		return nil, err
	}
	info, err := osStacks.ExtractStacks(pages)
	if err != nil {
		return nil, err
	}
	result := make([]map[string]interface{}, len(info))
	for j, stack := range info {
		result[j] = structs.Map(&stack)
		result[j]["CreationTime"] = stack.CreationTime
		result[j]["UpdatedTime"] = stack.UpdatedTime
	}
	return result, nil
}
Example #25
0
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
	}
}
Example #26
0
func serverSingle(rawServer interface{}) map[string]interface{} {
	server, ok := rawServer.(*osServers.Server)
	if !ok {
		return nil
	}
	m := structs.Map(rawServer)
	m["PublicIPv4"] = server.AccessIPv4
	m["PublicIPv6"] = server.AccessIPv6
	m["PrivateIPv4"] = ""
	ips, ok := server.Addresses["private"].([]interface{})
	if ok || len(ips) > 0 {
		priv, ok := ips[0].(map[string]interface{})
		if ok {
			m["PrivateIPv4"] = priv["addr"]
		}
	}
	m["Flavor"] = server.Flavor["id"]
	m["Image"] = server.Image["id"]
	return m
}
Example #27
0
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
}
Example #28
0
func eventSingle(rawEvent interface{}) map[string]interface{} {
	m := structs.Map(rawEvent)
	switch event := rawEvent.(type) {
	case *osStackEvents.Event:
		if event.Time.Unix() != -62135596800 {
			m["Time"] = event.Time
		} else {
			m["Time"] = ""
		}
		if event.Links != nil {
			links := make([]map[string]interface{}, len(event.Links))
			for i, link := range event.Links {
				links[i] = map[string]interface{}{
					"Href": link.Href,
					"Rel":  link.Rel,
				}
			}
			m["Links"] = links
		}
		return m
	}
	return nil
}
Example #29
0
func (command *commandList) Execute(resource *handler.Resource) {
	params := resource.Params.(*paramsList)
	opts := params.opts
	stackName := params.stackName
	stackID := params.stackID
	pager := stackresources.List(command.Ctx.ServiceClient, stackName, stackID, opts)
	pages, err := pager.AllPages()
	if err != nil {
		resource.Err = err
		return
	}
	info, err := osStackResources.ExtractResources(pages)
	if err != nil {
		resource.Err = err
		return
	}
	result := make([]map[string]interface{}, len(info))
	for j, resource := range info {
		result[j] = structs.Map(&resource)
		result[j]["UpdatedTime"] = resource.UpdatedTime
	}
	resource.Result = result
}
Example #30
0
func (command *commandGet) Execute(resource *handler.Resource) {

	pager := stacks.List(command.Ctx.ServiceClient, nil)
	//fmt.Println(pager)
	pages, err := pager.AllPages()
	if err != nil {
		resource.Err = err
		return
	}
	//fmt.Println(pages)
	info, err := osStacks.ExtractStacks(pages)
	//fmt.Println("Yeah!")
	if err != nil {
		resource.Err = err
		return
	}
	result := make([]map[string]interface{}, len(info))
	for j, stack := range info {
		result[j] = structs.Map(stack)
	}
	fmt.Println(result)
	resource.Result = result

}