@@ -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.
@@ -2467,6 +2473,7 @@ def _to_node(self, api_node):
24672473 power_state = api_node .get ("OS-EXT-STS:power_state" , None ),
24682474 progress = api_node .get ("progress" , None ),
24692475 fault = api_node .get ("fault" ),
2476+ hypervisor_hostname = api_node .get ("OS-EXT-SRV-ATTR:hypervisor_hostname" ),
24702477 ),
24712478 )
24722479
@@ -2813,6 +2820,15 @@ def encode_data(self, data):
28132820 return json .dumps (data )
28142821
28152822
2823+ class OpenStack_2_ReservationConnection (OpenStackReservationConnection ):
2824+ responseCls = OpenStack_1_1_Response
2825+ accept_format = "application/json"
2826+ default_content_type = "application/json; charset=UTF-8"
2827+
2828+ def encode_data (self , data ):
2829+ return json .dumps (data )
2830+
2831+
28162832class OpenStack_2_PortInterfaceState (Type ):
28172833 """
28182834 Standard states of OpenStack_2_PortInterfaceState
@@ -2873,6 +2889,10 @@ class OpenStack_2_NodeDriver(OpenStack_1_1_NodeDriver):
28732889 volumev3_connection = None
28742890 volume_connection = None
28752891
2892+ # Connection to the Blazar reservation API
2893+ reservation_connectionCls = OpenStack_2_ReservationConnection
2894+ reservation_connection = None
2895+
28762896 type = Provider .OPENSTACK
28772897
28782898 features = {"create_node" : ["generates_password" ]}
@@ -2929,6 +2949,16 @@ def __init__(self, *args, **kwargs):
29292949 super ().__init__ (* args , ** kwargs )
29302950 self .network_connection = self .connection
29312951
2952+ # We run the init once to get the Blazar API connection
2953+ # and put that on the object under self.reservation_connection.
2954+ if original_ex_force_base_url or kwargs .get ("ex_force_reservation_url" ):
2955+ kwargs ["ex_force_base_url" ] = str (
2956+ kwargs .pop ("ex_force_reservation_url" , original_ex_force_base_url )
2957+ )
2958+ self .connectionCls = self .reservation_connectionCls
2959+ super ().__init__ (* args , ** kwargs )
2960+ self .reservation_connection = self .connection
2961+
29322962 # We run the init once again to get the compute API connection
29332963 # and that's put under self.connection as normal.
29342964 self ._ex_force_base_url = original_ex_force_base_url
@@ -4368,6 +4398,100 @@ def ex_detach_floating_ip_from_node(self, node, ip):
43684398 )
43694399 return resp .status == httplib .OK
43704400
4401+ def ex_list_leases (self ):
4402+ """
4403+ List leases
4404+
4405+ :rtype: ``list`` of :class:`OpenStack_2_Lease`
4406+ """
4407+ return self ._to_leases (self .reservation_connection .request ("/leases" ).object )
4408+
4409+ def _to_leases (self , obj ):
4410+ lease_elements = obj ["leases" ]
4411+ return [self ._to_lease (lease ) for lease in lease_elements ]
4412+
4413+ def _to_lease (self , obj ):
4414+ return OpenStack_2_Lease (
4415+ id = obj ["id" ],
4416+ name = obj ["name" ],
4417+ start = obj ["start_date" ],
4418+ end = obj ["end_date" ],
4419+ status = obj ["status" ],
4420+ reservations = obj ["reservations" ],
4421+ driver = self .reservation_connection .driver ,
4422+ )
4423+
4424+ def ex_list_hosts (self ):
4425+ """
4426+ List leases
4427+
4428+ :rtype: ``list`` of :class:`OpenStack_2_Host`
4429+ """
4430+ return self ._to_hosts (self .reservation_connection .request ("/os-hosts" ).object )
4431+
4432+ def _to_hosts (self , obj ):
4433+ host_elements = obj ["hosts" ]
4434+ return [self ._to_host (host ) for host in host_elements ]
4435+
4436+ def _to_host (self , obj ):
4437+ return OpenStack_2_Host (
4438+ id = obj ["id" ],
4439+ hypervisor_hostname = obj ["hypervisor_hostname" ],
4440+ vcpus = obj ["vcpus" ],
4441+ memory_mb = obj ["memory_mb" ],
4442+ local_gb = obj ["local_gb" ],
4443+ service_name = obj ["service_name" ],
4444+ )
4445+
4446+
4447+ class OpenStack_2_Host :
4448+ """
4449+ Host info.
4450+ """
4451+
4452+ def __init__ (self , id , hypervisor_hostname , vcpus , memory_mb , local_gb , service_name ):
4453+ self .id = id
4454+ self .hypervisor_hostname = hypervisor_hostname
4455+ self .vcpus = vcpus
4456+ self .memory_mb = memory_mb
4457+ self .local_gb = local_gb
4458+ self .service_name = service_name
4459+
4460+ def __repr__ (self ):
4461+ return "<OpenStack_2_Host: id={}, hypervisor_hostname={}>" .format (
4462+ self .id ,
4463+ self .hypervisor_hostname ,
4464+ )
4465+
4466+
4467+ class OpenStack_2_Lease :
4468+ """
4469+ Lease info.
4470+ """
4471+
4472+ PENDING = "PENDING"
4473+ ACTIVE = "ACTIVE"
4474+ TERMINATED = "TERMINATED"
4475+ DELETED = "DELETED"
4476+ CREATING = "CREATING"
4477+ UPDATING = "UPDATING"
4478+ DELETING = "DELETING"
4479+ ERROR = "ERROR"
4480+
4481+ def __init__ (self , id , name , start , end , status , reservations , driver ):
4482+ self .id = id
4483+ self .name = name
4484+ self .start = start
4485+ self .end = end
4486+ self .status = status
4487+ self .reservations = reservations
4488+ self .driver = driver
4489+
4490+ def __repr__ (self ):
4491+ return "<OpenStack_2_Lease: id={}, name={}, status={}>" .format (
4492+ self .id , self .name , self .status
4493+ )
4494+
43714495
43724496class OpenStack_1_1_FloatingIpPool :
43734497 """
0 commit comments