Beispiel #1
0
func (cmd *UpdateZone) Run(c *cli.Context) {
	var zoneParams models.ZoneParams

	name := c.Args()[0]
	has_option := false

	if c.IsSet("z") {
		name_after := c.String("z")
		zoneParams.Name = &name_after
		has_option = true
	}

	if c.IsSet("p") {
		priority := c.Int("p")
		if priority < 1 {
			cmd.ui.Failed(T("Invalid priority. Priority must be a positive integer"))
			return
		}
		zoneParams.Priority = &priority
		has_option = true
	}

	if c.IsSet("d") {
		description := c.String("d")
		zoneParams.Description = &description
		has_option = true
	}

	if has_option == false {
		cmd.ui.Failed(T("No options given"))
		return
	}

	zone := cmd.zoneReq.GetZone()

	cmd.ui.Say(T("Updating zone {{.ZoneName}} as {{.Username}}...",
		map[string]interface{}{
			"ZoneName": terminal.EntityNameColor(name),
			"Username": terminal.EntityNameColor(cmd.config.Username())}))

	err := cmd.zoneRepo.Update(zone.Guid, zoneParams)
	if err != nil {
		cmd.ui.Failed(err.Error())
	}

	cmd.ui.Ok()
}
Beispiel #2
0
func (cmd CreateZone) Run(c *cli.Context) {
	var zoneParams models.ZoneParams

	name := c.Args()[0]
	zoneParams.Name = &name

	priority, err := strconv.Atoi(c.Args()[1])
	if err != nil || priority < 1 {
		cmd.ui.Failed(T("Invalid priority. A positive integer must be provided as priority"))
		return
	} else {
		zoneParams.Priority = &priority
	}

	if c.IsSet("d") {
		description := c.String("d")
		zoneParams.Description = &description
	}

	is_public := false
	if c.Bool("public") == true {
		is_public = true
	}
	zoneParams.IsPublic = &is_public

	if is_public == false {
		orgName := c.String("o")
		orgGuid := ""
		if orgName == "" {
			orgName = cmd.config.OrganizationFields().Name
			orgGuid = cmd.config.OrganizationFields().Guid
		}
		if orgGuid == "" {
			org, apiErr := cmd.orgRepo.FindByName(orgName)
			switch apiErr.(type) {
			case nil:
			case *errors.ModelNotFoundError:
				cmd.ui.Failed(T("Org {{.OrgName}} does not exist or is not accessible", map[string]interface{}{"OrgName": orgName}))
				return
			default:
				cmd.ui.Failed(T("Error finding org {{.OrgName}}\n{{.ErrorDescription}}",
					map[string]interface{}{
						"OrgName":          orgName,
						"ErrorDescription": apiErr.Error(),
					}))
				return
			}

			orgGuid = org.Guid
		}
		zoneParams.OrgGuid = &orgGuid

		cmd.ui.Say(T("Creating private zone {{.ZoneName}} for {{.OrgName}} as {{.Username}}...",
			map[string]interface{}{
				"ZoneName": terminal.EntityNameColor(name),
				"OrgName":  terminal.EntityNameColor(orgName),
				"Username": terminal.EntityNameColor(cmd.config.Username())}))
	} else {
		cmd.ui.Say(T("Creating public zone {{.ZoneName}} as {{.Username}}...",
			map[string]interface{}{
				"ZoneName": terminal.EntityNameColor(name),
				"Username": terminal.EntityNameColor(cmd.config.Username())}))
	}

	err = cmd.zoneRepo.Create(zoneParams)
	if err != nil {
		cmd.ui.Failed(err.Error())
	}

	cmd.ui.Ok()
}