// TenantCreate creates a tenant
func (ac *APIController) TenantCreate(tenant *contivModel.Tenant) error {
	log.Infof("Received TenantCreate: %+v", tenant)

	if tenant.TenantName == "" {
		return core.Errorf("Invalid tenant name")
	}

	// Get the state driver
	stateDriver, err := utils.GetStateDriver()
	if err != nil {
		return err
	}

	// Build tenant config
	tenantCfg := intent.ConfigTenant{
		Name:           tenant.TenantName,
		DefaultNetwork: tenant.DefaultNetwork,
	}

	// Create the tenant
	err = master.CreateTenant(stateDriver, &tenantCfg)
	if err != nil {
		log.Errorf("Error creating tenant {%+v}. Err: %v", tenant, err)
		return err
	}

	return nil
}
Esempio n. 2
0
// TenantCreate creates a tenant
func (ac *APIController) TenantCreate(tenant *contivModel.Tenant) error {
	log.Infof("Received TenantCreate: %+v", tenant)

	if tenant.TenantName == "" {
		return core.Errorf("Invalid tenant name")
	}

	// Get the state driver
	stateDriver, err := utils.GetStateDriver()
	if err != nil {
		return err
	}

	// Build tenant config
	tenantCfg := intent.ConfigTenant{
		Name:           tenant.TenantName,
		DefaultNetType: "vlan",
		DefaultNetwork: tenant.DefaultNetwork,
		SubnetPool:     tenant.SubnetPool,
		AllocSubnetLen: uint(tenant.SubnetLen),
		VLANs:          tenant.Vlans,
		VXLANs:         tenant.Vxlans,
	}

	// Create the tenant
	err = master.CreateTenant(stateDriver, &tenantCfg)
	if err != nil {
		log.Errorf("Error creating tenant {%+v}. Err: %v", tenant, err)
		return err
	}

	// Create private network for the tenant
	err = contivModel.CreateNetwork(&contivModel.Network{
		Key:         tenant.TenantName + ":" + "private",
		IsPublic:    false,
		IsPrivate:   true,
		Encap:       "vxlan",
		PktTag:      1001,
		Subnet:      "10.1.0.0/16",
		Gateway:     "10.1.254.254",
		NetworkName: "private",
		TenantName:  tenant.TenantName,
	})
	if err != nil {
		log.Errorf("Error creating privateNet for tenant: %+v. Err: %v", tenant, err)
		return err
	}

	// Create public network for the tenant
	err = contivModel.CreateNetwork(&contivModel.Network{
		Key:         tenant.TenantName + ":" + "public",
		IsPublic:    true,
		IsPrivate:   false,
		Encap:       "vlan",
		PktTag:      1,
		Subnet:      "192.168.1.0/24",
		Gateway:     "192.168.1.254",
		NetworkName: "public",
		TenantName:  tenant.TenantName,
	})
	if err != nil {
		log.Errorf("Error creating publicNet for tenant: %+v. Err: %v", tenant, err)
		return err
	}

	return nil
}
Esempio n. 3
0
// TenantCreate creates a tenant
func (ac *APIController) TenantCreate(tenant *contivModel.Tenant) error {
	log.Infof("Received TenantCreate: %+v", tenant)

	if tenant.TenantName == "" {
		return errors.New("Invalid tenant name")
	}

	// Get the state driver
	stateDriver, err := utils.GetStateDriver()
	if err != nil {
		return err
	}

	// Build tenant config
	tenantCfg := intent.ConfigTenant{
		Name:           tenant.TenantName,
		DefaultNetType: "vlan",
		SubnetPool:     tenant.SubnetPool,
		AllocSubnetLen: uint(tenant.SubnetLen),
		VLANs:          tenant.Vlans,
		VXLANs:         tenant.Vxlans,
	}

	// Create the tenant
	err = master.CreateTenant(stateDriver, &tenantCfg)
	if err != nil {
		log.Errorf("Error creating tenant {%+v}. Err: %v", tenant, err)
		return err
	}

	// Create private network for the tenant
	err = contivModel.CreateNetwork(&contivModel.Network{
		Key:         tenant.TenantName + ":" + "private",
		IsPublic:    false,
		IsPrivate:   true,
		Encap:       "vxlan",
		Subnet:      "10.1.0.0/16",
		DefaultGw:   "10.1.0.1",
		NetworkName: "private",
		TenantName:  tenant.TenantName,
	})
	if err != nil {
		log.Errorf("Error creating privateNet for tenant: %+v. Err: %v", tenant, err)
		return err
	}

	// Create public network for the tenant
	err = contivModel.CreateNetwork(&contivModel.Network{
		Key:         tenant.TenantName + ":" + "public",
		IsPublic:    true,
		IsPrivate:   false,
		Encap:       "vlan",
		Subnet:      "192.168.1.0/24",
		DefaultGw:   "192.168.1.1",
		NetworkName: "public",
		TenantName:  tenant.TenantName,
	})
	if err != nil {
		log.Errorf("Error creating publicNet for tenant: %+v. Err: %v", tenant, err)
		return err
	}

	// Create a default volume profile for the tenant
	err = contivModel.CreateVolumeProfile(&contivModel.VolumeProfile{
		Key:               tenant.TenantName + ":" + "default",
		VolumeProfileName: "default",
		TenantName:        tenant.TenantName,
		DatastoreType:     "none",
		PoolName:          "",
		Size:              "",
		MountPoint:        "",
	})
	if err != nil {
		log.Errorf("Error creating default volume profile. Err: %v", err)
		return err
	}

	return nil
}