示例#1
0
//DeleteAppNw deletes the app profile from infra
func DeleteAppNw(app *contivModel.AppProfile) error {
	aciPresent, aErr := master.IsAciConfigured()
	if aErr != nil {
		log.Errorf("Couldn't read global config %v", aErr)
		return aErr
	}

	if !aciPresent {
		log.Debugf("ACI not configured")
		return nil
	}

	ans := &appNwSpec{}
	ans.TenantName = app.TenantName
	ans.AppName = app.AppProfileName

	url := proxyURL + "deleteAppProf"
	resp, err := httpPost(url, ans)
	if err != nil {
		log.Errorf("Delete failed. Error: %v", err)
		return err
	}

	if resp.Result != "success" {
		log.Errorf("Delete failed %v - %v", resp.Result, resp.Info)
	}

	time.Sleep(time.Second)
	return nil
}
示例#2
0
//CreateAppNw Fill in the Nw spec and launch the nw infra
func CreateAppNw(app *contivModel.AppProfile) error {
	aciPresent, aErr := master.IsAciConfigured()
	if aErr != nil {
		log.Errorf("Couldn't read global config %v", aErr)
		return aErr
	}

	if !aciPresent {
		log.Debugf("ACI not configured")
		return nil
	}

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

	eMap := &epgMap{}
	eMap.Specs = make(map[string]epgSpec)
	ans := &appNwSpec{}

	ans.TenantName = app.TenantName
	ans.AppName = app.AppProfileName

	// Gather all basic epg info into the epg map
	for epgKey := range app.LinkSets.EndpointGroups {
		epgObj := contivModel.FindEndpointGroup(epgKey)
		if epgObj == nil {
			err := fmt.Sprintf("Epg %v does not exist", epgKey)
			log.Errorf("%v", err)
			return errors.New(err)
		}

		if err := appendEpgInfo(eMap, epgObj, stateDriver); err != nil {
			log.Errorf("Error getting epg info %v", err)
			return err
		}
	}

	// walk the map and add to ANS
	for _, epg := range eMap.Specs {
		ans.Epgs = append(ans.Epgs, epg)
		log.Debugf("Added epg %v", epg.Name)
	}

	log.Infof("Launching appNwSpec: %+v", ans)
	lErr := ans.launch()
	time.Sleep(2 * time.Second)
	ans.notifyDP()

	return lErr
}
示例#3
0
//DeleteAppNw deletes the app profile from infra
func DeleteAppNw(app *contivModel.App) error {
	aciPresent, aErr := master.IsAciConfigured()
	if aErr != nil {
		log.Errorf("Couldn't read global config %v", aErr)
		return aErr
	}

	if !aciPresent {
		log.Debugf("ACI not configured")
		return nil
	}

	ans := &appNwSpec{}
	ans.TenantName = "CONTIV-" + app.TenantName
	ans.AppName = app.AppName

	url := proxyURL + "deleteAppProf"
	if err := httpPost(url, ans); err != nil {
		log.Errorf("Delete failed. Error: %v", err)
		return err
	}

	return nil
}
示例#4
0
//CreateAppNw Fill in the Nw spec and launch the nw infra
func CreateAppNw(app *contivModel.App) error {
	aciPresent, aErr := master.IsAciConfigured()
	if aErr != nil {
		log.Errorf("Couldn't read global config %v", aErr)
		return aErr
	}

	if !aciPresent {
		log.Debugf("ACI not configured")
		return nil
	}

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

	netName := ""
	eMap := &epgMap{}
	eMap.Specs = make(map[string]epgSpec)
	ans := &appNwSpec{}

	ans.TenantName = app.TenantName
	ans.AppName = app.AppName

	// Gather all basic epg info into the epg map
	for epgKey := range app.LinkSets.Services {
		epgObj := contivModel.FindEndpointGroup(epgKey)
		if epgObj == nil {
			err := fmt.Sprintf("Epg %v does not exist", epgKey)
			log.Errorf("%v", err)
			return errors.New(err)
		}

		if err := appendEpgInfo(eMap, epgObj, stateDriver); err != nil {
			log.Errorf("Error getting epg info %v", err)
			return err
		}
		netName = epgObj.NetworkName
	}

	// walk the map and add to ANS
	for _, epg := range eMap.Specs {
		ans.Epgs = append(ans.Epgs, epg)
		log.Debugf("Added epg %v", epg.Name)
	}

	// get the subnet info and add it to ans
	nwCfg := &mastercfg.CfgNetworkState{}
	nwCfg.StateDriver = stateDriver
	networkID := netName + "." + app.TenantName
	nErr := nwCfg.Read(networkID)
	if nErr != nil {
		log.Errorf("Failed to network info %v %v ", netName, nErr)
		return nErr
	}
	ans.Subnet = nwCfg.Gateway + "/" + strconv.Itoa(int(nwCfg.SubnetLen))
	log.Debugf("Nw %v subnet %v", netName, ans.Subnet)

	ans.launch()

	return nil
}