@@ -114,6 +114,12 @@ class OpenStackVolumeV3Connection(OpenStackBaseConnection):
114114 service_region = "RegionOne"
115115
116116
117+ class OpenStackReservationConnection (OpenStackBaseConnection ):
118+ service_type = "reservation"
119+ service_name = "blazar"
120+ service_region = "RegionOne"
121+
122+
117123class OpenStackNodeDriver (NodeDriver , OpenStackDriverMixin ):
118124 """
119125 Base OpenStack node driver. Should not be used directly.
@@ -2813,6 +2819,15 @@ def encode_data(self, data):
28132819 return json .dumps (data )
28142820
28152821
2822+ class OpenStack_2_ReservationConnection (OpenStackReservationConnection ):
2823+ responseCls = OpenStack_1_1_Response
2824+ accept_format = "application/json"
2825+ default_content_type = "application/json; charset=UTF-8"
2826+
2827+ def encode_data (self , data ):
2828+ return json .dumps (data )
2829+
2830+
28162831class OpenStack_2_PortInterfaceState (Type ):
28172832 """
28182833 Standard states of OpenStack_2_PortInterfaceState
@@ -2873,6 +2888,10 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
28732888 volumev3_connection = None
28742889 volume_connection = None
28752890
2891+ # Connection to the Blazar reservation API
2892+ reservation_connectionCls = OpenStack_2_ReservationConnection
2893+ reservation_connection = None
2894+
28762895 type = Provider .OPENSTACK
28772896
28782897 features = {"create_node" : ["generates_password" ]}
@@ -2929,6 +2948,16 @@ def __init__(self, *args, **kwargs):
29292948 super ().__init__ (* args , ** kwargs )
29302949 self .network_connection = self .connection
29312950
2951+ # We run the init once to get the Blazar API connection
2952+ # and put that on the object under self.reservation_connection.
2953+ if original_ex_force_base_url or kwargs .get ("ex_force_reservation_url" ):
2954+ kwargs ["ex_force_base_url" ] = str (
2955+ kwargs .pop ("ex_force_reservation_url" , original_ex_force_base_url )
2956+ )
2957+ self .connectionCls = self .reservation_connectionCls
2958+ super ().__init__ (* args , ** kwargs )
2959+ self .reservation_connection = self .connection
2960+
29322961 # We run the init once again to get the compute API connection
29332962 # and that's put under self.connection as normal.
29342963 self ._ex_force_base_url = original_ex_force_base_url
@@ -4368,6 +4397,100 @@ def ex_detach_floating_ip_from_node(self, node, ip):
43684397 )
43694398 return resp .status == httplib .OK
43704399
4400+ def ex_list_leases (self ):
4401+ """
4402+ List leases
4403+
4404+ :rtype: ``list`` of :class:`OpenStack_2_Lease`
4405+ """
4406+ return self ._to_leases (self .reservation_connection .request ("/leases" ).object )
4407+
4408+ def _to_leases (self , obj ):
4409+ lease_elements = obj ["leases" ]
4410+ return [self ._to_lease (lease ) for lease in lease_elements ]
4411+
4412+ def _to_lease (self , obj ):
4413+ return OpenStack_2_Lease (
4414+ id = obj ["id" ],
4415+ name = obj ["name" ],
4416+ start = obj ["start_date" ],
4417+ end = obj ["end_date" ],
4418+ status = obj ["status" ],
4419+ reservations = obj ["reservations" ],
4420+ driver = self .reservation_connection .driver ,
4421+ )
4422+
4423+ def ex_list_hosts (self ):
4424+ """
4425+ List leases
4426+
4427+ :rtype: ``list`` of :class:`OpenStack_2_Host`
4428+ """
4429+ return self ._to_hosts (self .reservation_connection .request ("/os-hosts" ).object )
4430+
4431+ def _to_hosts (self , obj ):
4432+ host_elements = obj ["hosts" ]
4433+ return [self ._to_host (host ) for host in host_elements ]
4434+
4435+ def _to_host (self , obj ):
4436+ return OpenStack_2_Host (
4437+ id = obj ["id" ],
4438+ hypervisor_hostname = obj ["hypervisor_hostname" ],
4439+ vcpus = obj ["vcpus" ],
4440+ memory_mb = obj ["memory_mb" ],
4441+ local_gb = obj ["local_gb" ],
4442+ service_name = obj ["service_name" ],
4443+ )
4444+
4445+
4446+ class OpenStack_2_Host :
4447+ """
4448+ Host info.
4449+ """
4450+
4451+ def __init__ (self , id , hypervisor_hostname , vcpus , memory_mb , local_gb , service_name ):
4452+ self .id = id
4453+ self .hypervisor_hostname = hypervisor_hostname
4454+ self .vcpus = vcpus
4455+ self .memory_mb = memory_mb
4456+ self .local_gb = local_gb
4457+ self .service_name = service_name
4458+
4459+ def __repr__ (self ):
4460+ return "<OpenStack_2_Host: id={}, hypervisor_hostname={}>" .format (
4461+ self .id ,
4462+ self .hypervisor_hostname ,
4463+ )
4464+
4465+
4466+ class OpenStack_2_Lease :
4467+ """
4468+ Lease info.
4469+ """
4470+
4471+ PENDING = "PENDING"
4472+ ACTIVE = "ACTIVE"
4473+ TERMINATED = "TERMINATED"
4474+ DELETED = "DELETED"
4475+ CREATING = "CREATING"
4476+ UPDATING = "UPDATING"
4477+ DELETING = "DELETING"
4478+ ERROR = "ERROR"
4479+
4480+ def __init__ (self , id , name , start , end , status , reservations , driver ):
4481+ self .id = id
4482+ self .name = name
4483+ self .start = start
4484+ self .end = end
4485+ self .status = status
4486+ self .reservations = reservations
4487+ self .driver = driver
4488+
4489+ def __repr__ (self ):
4490+ return "<OpenStack_2_Lease: id={}, name={}, status={}>" .format (
4491+ self .id , self .name , self .status
4492+ )
4493+
43714494
43724495class OpenStack_1_1_FloatingIpPool :
43734496 """
0 commit comments