Пример #1
0
func (m *NetworkManagerImpl) initializePublicNetwork() {
	var network *types.VirtualNetwork
	obj, err := m.client.FindByName("virtual-network", m.config.PublicNetwork)
	if err != nil {
		fqn := strings.Split(m.config.PublicNetwork, ":")
		parent := strings.Join(fqn[0:len(fqn)-1], ":")
		projectId, err := m.client.UuidByName("project", parent)
		if err != nil {
			glog.Fatalf("%s: %v", parent, err)
		}
		var networkId string
		networkName := fqn[len(fqn)-1]
		if len(m.config.PublicSubnet) > 0 {
			networkId, err = config.CreateNetworkWithSubnet(
				m.client, projectId, networkName, m.config.PublicSubnet)
		} else {
			networkId, err = config.CreateNetwork(m.client, projectId, networkName)
		}
		if err != nil {
			glog.Fatalf("%s: %v", parent, err)
		}

		glog.Infof("Created network %s", m.config.PublicNetwork)

		obj, err := m.client.FindByUuid("virtual-network", networkId)
		if err != nil {
			glog.Fatalf("GET %s %v", networkId, err)
		}
		network = obj.(*types.VirtualNetwork)
	} else {
		network = obj.(*types.VirtualNetwork)
	}

	m.publicNetwork = network

	// TODO(prm): Ensure that the subnet is as specified.
	if len(m.config.PublicSubnet) > 0 {
		m.LocateFloatingIpPool(network, m.config.PublicSubnet)
	}
}
Пример #2
0
func networkCreate(client *contrail.Client, flagSet *flag.FlagSet) {
	if flagSet.NArg() < 1 {
		flagSet.Usage()
		os.Exit(2)
	}

	name := flagSet.Args()[0]

	parent_id, err := config.GetProjectId(
		client, networkCommonOpts.project, networkCommonOpts.project_id)
	if err != nil {
		fmt.Fprint(os.Stderr, err)
		os.Exit(1)
	}

	if len(networkCreateOpts.subnet) > 0 {
		config.CreateNetworkWithSubnet(client, parent_id, name,
			networkCreateOpts.subnet)
	} else {
		config.CreateNetwork(client, parent_id, name)
	}
}