// CreateDomain creates a new domain in the account.
//
// See https://developer.dnsimple.com/v2/domains/#create
547148
func (s *DomainsService) CreateDomain(accountID string, domainAttributes Domain) (*domainResponse, error) {
	path := versioned(domainPath(accountID, ""))
	domainResponse := &domainResponse{}

	resp, err := s.client.post(path, domainAttributes, domainResponse)
	if err != nil {
		return nil, err
	}

	domainResponse.HttpResponse = resp
	return domainResponse, nil
}
1260836
func (client *Client) AddDomain(args *AddDomainArgs) (response *AddDomainResponse, err error) {
	action := "AddDomain"
	response = &AddDomainResponse{}
	err = client.Invoke(action, args, response)
	if err == nil {
		return response, nil
	} else {
		log.Printf("%s error, %v", action, err)
		return response, err
	}
}
1242645
func (c *Client) DomainCreate(domain string, Type string,
	conf DomainCreateOpts) (domainID int, err error) {

	args, err := c.argMarshal(conf)
	if err != nil {
		return 0, err
	}
	args["Domain"] = domain
	args["Type"] = Type

	data, err := c.apiCall("domain.create", args)
	if err != nil {
		return 0, err
	}

	err = unmarshalSingle(data, "DomainID", &domainID)
	if err != nil {
		return 0, err
	}

	return domainID, nil
}
1348359
func (client *Client) DeleteDomain(args *DeleteDomainArgs) (response *DeleteDomainResponse, err error) {
	action := "DeleteDomain"
	response = &DeleteDomainResponse{}
	err = client.Invoke(action, args, response)
	if err == nil {
		return response, nil
	} else {
		log.Printf("%s error, %v", action, err)
		return response, err
	}
}
182582
func (s *server) createToken(idt *lib.Identity) (string, error) {

	token := jwt.New(jwt.GetSigningMethod(s.p.signMethod))
	token.Claims["pid"] = idt.Pid
	token.Claims["idp"] = idt.Idp
	token.Claims["display_name"] = idt.DisplayName
	token.Claims["email"] = idt.Email
	token.Claims["iss"] = "localhost"
	token.Claims["exp"] = time.Now().Add(time.Second * 3600).UnixNano()

	tokenStr, err := token.SignedString([]byte(s.p.sharedSecret))
	if err != nil {
		return "", err
	}

	return tokenStr, nil
}
822923
func (c *Client) DeleteDomain(i *DeleteDomainInput) error {
	if i.Service == "" {
		return ErrMissingService
	}

	if i.Version == 0 {
		return ErrMissingVersion
	}

	if i.Name == "" {
		return ErrMissingName
	}

	path := fmt.Sprintf("/service/%s/version/%d/domain/%s", i.Service, i.Version, i.Name)
	_, err := c.Delete(path, nil)
	if err != nil {
		return err
	}
	return nil
}
1367608
func (d *DNS) CreateDomainResourceA(domainID int, name, target string, ttlSeconds int) (*ResourceResponse, error) {
	return d.createDomainResource(linode.Parameters{
		"Type":     "A",
		"DomainID": strconv.Itoa(domainID),
		"Name":     name,
		"Target":   target,
		"TTL_Sec":  strconv.Itoa(ttlSeconds),
	})
}
981081
func (self *Domain) Create(name, contactHandle string, years int64) (*operation.OperationInfo, error) {
	var res map[string]interface{}
	createArgs := map[string]interface{}{
		"admin":    contactHandle,
		"bill":     contactHandle,
		"owner":    contactHandle,
		"tech":     contactHandle,
		"duration": years,
	}
	params := []interface{}{self.Key, name, createArgs}
	if err := self.Call("domain.create", params, &res); err != nil {
		return nil, err
	}
	return operation.ToOperationInfo(res), nil
}
1171877
func (c *Client) CreateDomain(i *CreateDomainInput) (*Domain, error) {
	if i.Service == "" {
		return nil, ErrMissingService
	}

	if i.Version == 0 {
		return nil, ErrMissingVersion
	}

	path := fmt.Sprintf("/service/%s/version/%d/domain", i.Service, i.Version)
	resp, err := c.PostForm(path, i, nil)
	if err != nil {
		return nil, err
	}

	var d *Domain
	if err := decodeJSON(&d, resp.Body); err != nil {
		return nil, err
	}
	return d, nil
}
476889
func (o *Enterprise) CreateL2Domain(child *L2Domain) *bambou.Error {

	return bambou.CurrentSession().CreateChild(o, child)
}
314291
func NewDomain() *Domain {

	return &Domain{
		PATEnabled:            "DISABLED",
		DHCPBehavior:          "CONSUME",
		FIPIgnoreDefaultRoute: "DISABLED",
		FIPUnderlay:           false,
		DPI:                   "DISABLED",
		VXLANECMPEnabled:      false,
		MaintenanceMode:       "DISABLED",
		AggregateFlowsEnabled: false,
		FlowCollectionEnabled: "INHERITED",
		Encryption:            "DISABLED",
		UnderlayEnabled:       "DISABLED",
		TunnelType:            "DC_DEFAULT",
	}
}
832648
func NewDomain(p domainParams) (Domain, error) {
	if err := p.ValidateDomainParams(); err != nil {
		return Domain{}, errors.Trace(err)
	}

	d := Domain{
		Type:          "kvm",
		Name:          p.Host(),
		VCPU:          p.CPUs(),
		CurrentMemory: Memory{Unit: "MiB", Text: p.RAM()},
		Memory:        Memory{Unit: "MiB", Text: p.RAM()},
		OS:            generateOSElement(p),
		Features:      generateFeaturesElement(p),
		CPU:           generateCPU(p),
		Disk:          []Disk{},
		Interface:     []Interface{},
		Serial: Serial{
			Type: "pty",
			Source: SerialSource{
				Path: "/dev/pts/2",
			},
			Target: SerialTarget{
				Port: 0,
			},
		},
		Console: []Console{
			{
				Type: "pty",
				TTY:  "/dev/pts/2",
				Target: ConsoleTarget{
					Port: 0,
				},
				Source: ConsoleSource{
					Path: "/dev/pts/2",
				},
			},
		},
	}
	for i, diskInfo := range p.DiskInfo() {
		devID, err := deviceID(i)
		if err != nil {
			return Domain{}, errors.Trace(err)
		}
		switch diskInfo.Driver() {
		case "raw":
			d.Disk = append(d.Disk, Disk{
				Device: "disk",
				Type:   "file",
				Driver: DiskDriver{Type: diskInfo.Driver(), Name: "qemu"},
				Source: DiskSource{File: diskInfo.Source()},
				Target: DiskTarget{Dev: devID},
			})
		case "qcow2":
			d.Disk = append(d.Disk, Disk{
				Device: "disk",
				Type:   "file",
				Driver: DiskDriver{Type: diskInfo.Driver(), Name: "qemu"},
				Source: DiskSource{File: diskInfo.Source()},
				Target: DiskTarget{Dev: devID},
			})
		default:
			return Domain{}, errors.Errorf(
				"unsupported disk type %q", diskInfo.Driver())
		}
	}
	for _, iface := range p.NetworkInfo() {
		d.Interface = append(d.Interface, Interface{
			Type:   "bridge",
			MAC:    InterfaceMAC{Address: iface.MACAddress()},
			Model:  Model{Type: "virtio"},
			Source: InterfaceSource{Bridge: iface.ParentInterfaceName()},
			Guest:  InterfaceGuest{Dev: iface.InterfaceName()},
		})
	}
	return d, nil
}
843190
func (c *Client) CreateRecord(domain *Domain, record *Record) error {
	url := fmt.Sprintf("%s/%d/%s", "/dns/managed", domain.ID, "records")

	resp, err := c.sendRequest(http.MethodPost, url, record)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	return nil
}
407784
func (h *Hostlist) RemoveDomain(domain string) int {
	return h.RemoveDomainV(domain, 4) + h.RemoveDomainV(domain, 6)
}
1307891
func (s *RegistrarService) RegisterDomain(accountID string, domainName string, request *DomainRegisterRequest) (*domainRegistrationResponse, error) {
	path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/registrations", accountID, domainName))
	registrationResponse := &domainRegistrationResponse{}

	// TODO: validate mandatory attributes RegistrantID

	resp, err := s.client.post(path, request, registrationResponse)
	if err != nil {
		return nil, err
	}

	registrationResponse.HttpResponse = resp
	return registrationResponse, nil
}
933241
func (z *Zone) Create(zoneInfo Info) (status *CreateStatus, err error) {
	if debug {
		fmt.Printf("DEBUG: Create WILL SET SharingID=%v domain=%v\n", zoneInfo.SharingID, zoneInfo.Name)
	}
	_, err = z.Post(fmt.Sprintf("/zones?sharing_id=%s", zoneInfo.SharingID), zoneInfo, &status)
	return
}
46031
func (s *DomainService) NewCreateDomainParams(name string) *CreateDomainParams {
	p := &CreateDomainParams{}
	p.p = make(map[string]interface{})
	p.p["name"] = name
	return p
}