Edit cluster and host models.

To allow different users to use the same cluster and host name.

Change-Id: Icf68735b54c7e051ea655624ee83f2b6ae2c43bd
This commit is contained in:
Xicheng Chang 2016-07-14 02:01:42 -04:00
parent 0a50f8da51
commit 63dd7d6fc0
3 changed files with 20 additions and 7 deletions

View File

@ -359,7 +359,7 @@ def add_cluster(
cluster = utils.add_db_object(
session, models.Cluster, exception_when_existing,
name, creator_id=user.id, adapter_id=adapter_id,
name, user.id, adapter_id=adapter_id,
flavor_id=flavor_id, flavor=flavor, **kwargs
)
return cluster

View File

@ -658,10 +658,11 @@ def _add_host_network(
"""Add hostnetwork to a host."""
host = _get_host(host_id, session=session)
check_host_editable(host, user=user)
user_id = user.id
return utils.add_db_object(
session, models.HostNetwork,
exception_when_existing,
host.id, interface, ip=ip, **kwargs
host.id, interface, user_id, ip=ip, **kwargs
)

View File

@ -204,17 +204,20 @@ class HostNetwork(BASE, TimestampMixin, HelperMixin):
Integer,
ForeignKey('subnet.id', onupdate='CASCADE', ondelete='CASCADE')
)
ip_int = Column(BigInteger, unique=True, nullable=False)
user_id = Column(Integer, ForeignKey('user.id'))
ip_int = Column(BigInteger, nullable=False)
is_mgmt = Column(Boolean, default=False)
is_promiscuous = Column(Boolean, default=False)
__table_args__ = (
UniqueConstraint('host_id', 'interface', name='constraint'),
UniqueConstraint('ip_int', 'user_id', name='constraint')
)
def __init__(self, host_id, interface, **kwargs):
def __init__(self, host_id, interface, user_id, **kwargs):
self.host_id = host_id
self.interface = interface
self.user_id = user_id
super(HostNetwork, self).__init__(**kwargs)
def __str__(self):
@ -265,6 +268,7 @@ class HostNetwork(BASE, TimestampMixin, HelperMixin):
dict_info['interface'] = self.interface
dict_info['netmask'] = self.netmask
dict_info['subnet'] = self.subnet.subnet
dict_info['user_id'] = self.user_id
return dict_info
@ -702,7 +706,7 @@ class Host(BASE, TimestampMixin, HelperMixin):
"""Host table."""
__tablename__ = 'host'
name = Column(String(80), unique=True, nullable=True)
name = Column(String(80), nullable=True)
config_step = Column(String(80), default='')
os_config = Column(JSONEncoded, default={})
config_validated = Column(Boolean, default=False)
@ -712,6 +716,10 @@ class Host(BASE, TimestampMixin, HelperMixin):
owner = Column(String(80))
os_installer = Column(JSONEncoded, default={})
__table_args__ = (
UniqueConstraint('name', 'owner', name='constraint'),
)
id = Column(
Integer,
ForeignKey('machine.id', onupdate='CASCADE', ondelete='CASCADE'),
@ -972,7 +980,7 @@ class Cluster(BASE, TimestampMixin, HelperMixin):
__tablename__ = 'cluster'
id = Column(Integer, primary_key=True)
name = Column(String(80), unique=True, nullable=False)
name = Column(String(80), nullable=False)
reinstall_distributed_system = Column(Boolean, default=True)
config_step = Column(String(80), default='')
os_name = Column(String(80))
@ -1000,9 +1008,13 @@ class Cluster(BASE, TimestampMixin, HelperMixin):
cascade='all, delete-orphan',
backref=backref('cluster')
)
__table_args__ = (
UniqueConstraint('name', 'creator_id', name='constraint'),
)
def __init__(self, name, **kwargs):
def __init__(self, name, creator_id, **kwargs):
self.name = name
self.creator_id = creator_id
self.state = ClusterState()
super(Cluster, self).__init__(**kwargs)