本文整理汇总了Golang中github.com/lxc/lxd.Response类的典型用法代码示例。如果您正苦于以下问题:Golang Response类的具体用法?Golang Response怎么用?Golang Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Response类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: run
func (c *launchCmd) run(config *lxd.Config, args []string) error {
if len(args) > 2 || len(args) < 1 {
return errArgs
}
iremote, image := config.ParseRemoteAndContainer(args[0])
var name string
var remote string
if len(args) == 2 {
remote, name = config.ParseRemoteAndContainer(args[1])
} else {
remote, name = config.ParseRemoteAndContainer("")
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
/*
* requested_empty_profiles means user requested empty
* !requested_empty_profiles but len(profArgs) == 0 means use profile default
*/
var resp *lxd.Response
profiles := []string{}
for _, p := range profArgs {
profiles = append(profiles, p)
}
if !requested_empty_profiles && len(profiles) == 0 {
resp, err = d.Init(name, iremote, image, nil, configMap, ephem)
} else {
resp, err = d.Init(name, iremote, image, &profiles, configMap, ephem)
}
if err != nil {
return err
}
if name == "" {
op, err := resp.MetadataAsOperation()
if err != nil {
return fmt.Errorf(i18n.G("didn't get any affected image, container or snapshot from server"))
}
containers, ok := op.Resources["containers"]
if !ok || len(containers) == 0 {
return fmt.Errorf(i18n.G("didn't get any affected image, container or snapshot from server"))
}
var version string
toScan := strings.Replace(containers[0], "/", " ", -1)
count, err := fmt.Sscanf(toScan, " %s containers %s", &version, &name)
if err != nil {
return err
}
if count != 2 {
return fmt.Errorf(i18n.G("bad number of things scanned from image, container or snapshot"))
}
if version != shared.APIVersion {
return fmt.Errorf(i18n.G("got bad version"))
}
}
fmt.Printf(i18n.G("Creating %s")+" ", name)
if err = d.WaitForSuccess(resp.Operation); err != nil {
return err
}
fmt.Println(i18n.G("done."))
fmt.Printf(i18n.G("Starting %s")+" ", name)
resp, err = d.Action(name, shared.Start, -1, false)
if err != nil {
return err
}
err = d.WaitForSuccess(resp.Operation)
if err != nil {
fmt.Println(i18n.G("error."))
return fmt.Errorf("%s\n"+i18n.G("Try `lxc info --show-log %s` for more info"), err, name)
}
fmt.Println(i18n.G("done."))
return nil
}
示例2: run
func (c *initCmd) run(config *lxd.Config, args []string) error {
if len(args) > 2 || len(args) < 1 {
return errArgs
}
iremote, image := config.ParseRemoteAndContainer(args[0])
var name string
var remote string
if len(args) == 2 {
remote, name = config.ParseRemoteAndContainer(args[1])
} else {
remote, name = config.ParseRemoteAndContainer("")
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
// TODO: implement the syntax for supporting other image types/remotes
/*
* initRequestedEmptyProfiles means user requested empty
* !initRequestedEmptyProfiles but len(profArgs) == 0 means use profile default
*/
profiles := []string{}
for _, p := range c.profArgs {
profiles = append(profiles, p)
}
var resp *lxd.Response
if name == "" {
fmt.Printf(i18n.G("Creating the container") + "\n")
} else {
fmt.Printf(i18n.G("Creating %s")+"\n", name)
}
iremote, image = c.guessImage(config, d, remote, iremote, image)
devicesMap := map[string]shared.Device{}
if c.network != "" {
network, err := d.NetworkGet(c.network)
if err != nil {
return err
}
if network.Type == "bridge" {
devicesMap[c.network] = shared.Device{"type": "nic", "nictype": "bridged", "parent": c.network}
} else {
devicesMap[c.network] = shared.Device{"type": "nic", "nictype": "macvlan", "parent": c.network}
}
}
if !initRequestedEmptyProfiles && len(profiles) == 0 {
resp, err = d.Init(name, iremote, image, nil, configMap, devicesMap, c.ephem)
} else {
resp, err = d.Init(name, iremote, image, &profiles, configMap, devicesMap, c.ephem)
}
if err != nil {
return err
}
c.initProgressTracker(d, resp.Operation)
err = d.WaitForSuccess(resp.Operation)
if err != nil {
return err
} else {
op, err := resp.MetadataAsOperation()
if err != nil {
return fmt.Errorf(i18n.G("didn't get any affected image, container or snapshot from server"))
}
containers, ok := op.Resources["containers"]
if !ok || len(containers) == 0 {
return fmt.Errorf(i18n.G("didn't get any affected image, container or snapshot from server"))
}
if len(containers) == 1 && name == "" {
fields := strings.Split(containers[0], "/")
fmt.Printf(i18n.G("Container name is: %s")+"\n", fields[len(fields)-1])
}
}
c.checkNetwork(d, name)
return nil
}
示例3: run
func (c *initCmd) run(config *lxd.Config, args []string) error {
if len(args) > 2 || len(args) < 1 {
return errArgs
}
iremote, image := config.ParseRemoteAndContainer(args[0])
var name string
var remote string
if len(args) == 2 {
remote, name = config.ParseRemoteAndContainer(args[1])
} else {
remote, name = config.ParseRemoteAndContainer("")
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
// TODO: implement the syntax for supporting other image types/remotes
/*
* requested_empty_profiles means user requested empty
* !requested_empty_profiles but len(profArgs) == 0 means use profile default
*/
profiles := []string{}
for _, p := range profArgs {
profiles = append(profiles, p)
}
var resp *lxd.Response
if name == "" {
fmt.Printf(i18n.G("Creating") + " ")
} else {
fmt.Printf(i18n.G("Creating %s")+" ", name)
}
if !requested_empty_profiles && len(profiles) == 0 {
resp, err = d.Init(name, iremote, image, nil, configMap, ephem)
} else {
resp, err = d.Init(name, iremote, image, &profiles, configMap, ephem)
}
if err != nil {
return err
}
err = d.WaitForSuccess(resp.Operation)
if err != nil {
fmt.Println(i18n.G("error."))
return err
} else {
op, err := resp.MetadataAsOperation()
if err != nil {
return fmt.Errorf(i18n.G("didn't get any affected image, container or snapshot from server"))
}
containers, ok := op.Resources["containers"]
if !ok || len(containers) == 0 {
return fmt.Errorf(i18n.G("didn't get any affected image, container or snapshot from server"))
}
if len(containers) == 1 && name == "" {
cname := path.Base(containers[0])
fmt.Println(cname, i18n.G("done."))
} else {
fmt.Println(i18n.G("done."))
}
}
return nil
}
示例4: copyContainer
//.........这里部分代码省略.........
if err != nil {
return err
}
sourceProfs := shared.NewStringSet(status.Profiles)
destProfs := []string{}
profiles, err := dest.ListProfiles()
if err != nil {
return err
}
for _, profile := range profiles {
destProfs = append(destProfs, profile.Name)
}
if !sourceProfs.IsSubset(shared.NewStringSet(destProfs)) {
return fmt.Errorf(i18n.G("not all the profiles from the source exist on the target"))
}
if ephemeral == -1 {
ct, err := source.ContainerInfo(sourceName)
if err != nil {
return err
}
if ct.Ephemeral {
ephemeral = 1
} else {
ephemeral = 0
}
}
sourceWSResponse, err := source.GetMigrationSourceWS(sourceName)
if err != nil {
return err
}
secrets := map[string]string{}
op, err := sourceWSResponse.MetadataAsOperation()
if err != nil {
return err
}
for k, v := range *op.Metadata {
secrets[k] = v.(string)
}
addresses, err := source.Addresses()
if err != nil {
return err
}
/* Since we're trying a bunch of different network ports that
* may be invalid, we can get "bad handshake" errors when the
* websocket code tries to connect. If the first error is a
* real error, but the subsequent errors are only network
* errors, we should try to report the first real error. Of
* course, if all the errors are websocket errors, let's just
* report that.
*/
for _, addr := range addresses {
var migration *lxd.Response
sourceWSUrl := "https://" + addr + sourceWSResponse.Operation
示例5: run
func (c *launchCmd) run(config *lxd.Config, args []string) error {
if len(args) > 2 || len(args) < 1 {
return errArgs
}
iremote, image := config.ParseRemoteAndContainer(args[0])
var name string
var remote string
if len(args) == 2 {
remote, name = config.ParseRemoteAndContainer(args[1])
} else {
remote, name = config.ParseRemoteAndContainer("")
}
d, err := lxd.NewClient(config, remote)
if err != nil {
return err
}
/*
* initRequestedEmptyProfiles means user requested empty
* !initRequestedEmptyProfiles but len(profArgs) == 0 means use profile default
*/
var resp *lxd.Response
profiles := []string{}
for _, p := range c.init.profArgs {
profiles = append(profiles, p)
}
iremote, image = c.init.guessImage(config, d, remote, iremote, image)
devicesMap := map[string]shared.Device{}
if c.init.network != "" {
network, err := d.NetworkGet(c.init.network)
if err != nil {
return err
}
if network.Type == "bridge" {
devicesMap[c.init.network] = shared.Device{"type": "nic", "nictype": "bridged", "parent": c.init.network}
} else {
devicesMap[c.init.network] = shared.Device{"type": "nic", "nictype": "macvlan", "parent": c.init.network}
}
}
if !initRequestedEmptyProfiles && len(profiles) == 0 {
resp, err = d.Init(name, iremote, image, nil, configMap, devicesMap, c.init.ephem)
} else {
resp, err = d.Init(name, iremote, image, &profiles, configMap, devicesMap, c.init.ephem)
}
if err != nil {
return err
}
progress := ProgressRenderer{}
c.init.initProgressTracker(d, &progress, resp.Operation)
if name == "" {
op, err := resp.MetadataAsOperation()
if err != nil {
return fmt.Errorf(i18n.G("didn't get any affected image, container or snapshot from server"))
}
containers, ok := op.Resources["containers"]
if !ok || len(containers) == 0 {
return fmt.Errorf(i18n.G("didn't get any affected image, container or snapshot from server"))
}
var version string
toScan := strings.Replace(containers[0], "/", " ", -1)
count, err := fmt.Sscanf(toScan, " %s containers %s", &version, &name)
if err != nil {
return err
}
if count != 2 {
return fmt.Errorf(i18n.G("bad number of things scanned from image, container or snapshot"))
}
if version != shared.APIVersion {
return fmt.Errorf(i18n.G("got bad version"))
}
}
fmt.Printf(i18n.G("Creating %s")+"\n", name)
if err = d.WaitForSuccess(resp.Operation); err != nil {
return err
}
progress.Done("")
c.init.checkNetwork(d, name)
fmt.Printf(i18n.G("Starting %s")+"\n", name)
resp, err = d.Action(name, shared.Start, -1, false, false)
if err != nil {
return err
}
//.........这里部分代码省略.........