Add initial network and tenant spec

Change-Id: Ia1e2d52c73539a45d294b7403c9290882c5d42d0
Implements: blueprint tenant-spec
This commit is contained in:
Pengfei Ni
2017-06-01 14:33:33 +08:00
parent 291127f0d1
commit 69c1e4013c
3023 changed files with 1689020 additions and 2 deletions

44
pkg/apis/v1/register.go Normal file
View File

@@ -0,0 +1,44 @@
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)
var (
// SchemeBuilder collects functions that add things to a scheme.
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme applies all the stored functions to the scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
// GroupName is the group name use in this package
const GroupName = "stackube.kubernetes.io"
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
SchemeBuilder.Register(addKnownTypes)
}
// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&Network{},
&NetworkList{},
&Tenant{},
&TenantList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

96
pkg/apis/v1/types.go Normal file
View File

@@ -0,0 +1,96 @@
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
// NetworkResourcePlural is the plural of network resource.
NetworkResourcePlural = "networks"
// TenantResourcePlural is the plural of tenant resource.
TenantResourcePlural = "tenants"
)
// Network describes a Neutron network.
type Network struct {
// TypeMeta defines type of the object and its API schema version.
metav1.TypeMeta `json:",inline"`
// ObjectMeta is metadata that all persisted resources must have.
metav1.ObjectMeta `json:"metadata"`
// Spec describes the behavior of a network.
Spec NetworkSpec
// Status describes the network status.
Status NetworkStatus `json:"status,omitempty"`
}
// NetworkSpec is the spec of a network.
type NetworkSpec struct {
// The CIDR of the network.
CIDR string `json:"cidr"`
// The gateway IP.
Gateway string `json:"gateway"`
// The network ID in Neutron.
// If provided, wouldn't create a network in Neutron.
NetworkID string `json:"networkID"`
}
// NetworkStatus is the status of a network.
type NetworkStatus struct {
// State describes the network state.
State string `json:"state,omitempty"`
// Message describes why network is in current state.
Message string `json:"message,omitempty"`
}
// NetworkList is a list of networks.
type NetworkList struct {
// TypeMeta defines type of the object and its API schema version.
metav1.TypeMeta `json:",inline"`
// ObjectMeta is metadata that all persisted resources must have.
metav1.ListMeta `json:"metadata"`
// Items contains a list of networks.
Items []Network `json:"items"`
}
// Tenant describes a Keystone tenant.
type Tenant struct {
// TypeMeta defines type of the object and its API schema version.
metav1.TypeMeta `json:",inline"`
// ObjectMeta is metadata that all persisted resources must have.
metav1.ObjectMeta `json:"metadata"`
// Spec defines the behavior of a tenant.
Spec TenantSpec
// Status describes the tenant status.
Status TenantStatus `json:"status,omitempty"`
}
// TenantSpec is the spec of a tenant.
type TenantSpec struct {
// The username of this user.
UserName string `json:"username"`
// The password of this user.
Password string `json:"password"`
// The tenant ID in Keystone.
// If provided, wouldn't create a new tenant in Keystone.
TenantID string `json:"tenantID"`
}
// TenantStatus is the status of a tenant.
type TenantStatus struct {
// State describes the tenant state.
State string `json:"state,omitempty"`
// Message describes why tenant is in current state.
Message string `json:"message,omitempty"`
}
// TenantList is a list of tenants.
type TenantList struct {
// TypeMeta defines type of the object and its API schema version.
metav1.TypeMeta `json:",inline"`
// ObjectMeta is metadata that all persisted resources must have.
metav1.ListMeta `json:"metadata"`
// Items contains a list of tenants.
Items []Tenant `json:"items"`
}