@@ -14,27 +14,46 @@ def self.which(cmd)
14
14
nil
15
15
end
16
16
17
- def self . command_string ( verbose , service , host_os , use_token )
17
+ def self . command_string ( verbose , service , host_os , use_token , ondemand = nil )
18
18
ssh_path = which ( 'ssh' )
19
19
raise 'Could not determine path to ssh' unless ssh_path
20
-
21
- os_types = { }
20
+ os_types = Utils . generate_os_hash ( [ host_os ] )
22
21
os_types [ host_os ] = 1
23
22
24
- response = service . retrieve ( verbose , os_types , use_token )
23
+ response = service . retrieve ( verbose , os_types , use_token , ondemand )
25
24
raise "Could not get vm from #{ service . type } :\n #{ response } " unless response [ 'ok' ]
26
25
27
26
user = /win/ . match? ( host_os ) ? 'Administrator' : 'root'
28
27
29
- hostname = response [ host_os ] [ 'hostname' ]
30
- hostname = response [ host_os ] [ 'hostname' ] [ 0 ] if response [ host_os ] [ 'hostname' ] . is_a? ( Array )
31
- hostname = "#{ hostname } .#{ response [ 'domain' ] } " unless hostname . end_with? ( 'puppetlabs.net' )
28
+ if ondemand
29
+ requestid = response [ 'request_id' ]
30
+ service . wait_for_request ( verbose , requestid )
31
+ response = service . retrieve ( verbose , os_types , use_token , ondemand )
32
+ hosts = service . check_ondemandvm ( verbose , requestid , service . url )
33
+ if hosts [ 'domain' ] . nil?
34
+ hostname = hosts [ host_os ] [ 'hostname' ]
35
+ hostname = hosts [ host_os ] [ 'hostname' ] [ 0 ] if hosts [ host_os ] [ 'hostname' ] . is_a? ( Array )
36
+ else
37
+ # Provides backwards compatibility with VMPooler API v1
38
+ hostname = "#{ hosts [ host_os ] [ 'hostname' ] [ 0 ] } .#{ hosts [ 'domain' ] } "
39
+ hostname = "#{ hosts [ host_os ] [ 'hostname' ] [ 0 ] } .#{ hosts [ 'domain' ] } " if hosts [ host_os ] [ 'hostname' ] . is_a? ( Array )
40
+ end
41
+ else
42
+ if response [ 'domain' ] . nil?
43
+ hostname = response [ host_os ] [ 'hostname' ]
44
+ hostname = response [ host_os ] [ 'hostname' ] [ 0 ] if response [ host_os ] [ 'hostname' ] . is_a? ( Array )
45
+ else
46
+ # Provides backwards compatibility with VMPooler API v1
47
+ hostname = "#{ response [ host_os ] [ 'hostname' ] } .#{ response [ 'domain' ] } "
48
+ hostname = "#{ response [ host_os ] [ 'hostname' ] [ 0 ] } .#{ response [ 'domain' ] } " if response [ host_os ] [ 'hostname' ] . is_a? ( Array )
49
+ end
50
+ end
32
51
33
52
"#{ ssh_path } #{ user } @#{ hostname } "
34
53
end
35
54
36
- def self . ssh ( verbose , service , host_os , use_token )
37
- cmd = command_string ( verbose , service , host_os , use_token )
55
+ def self . ssh ( verbose , service , host_os , use_token , ondemand )
56
+ cmd = command_string ( verbose , service , host_os , use_token , ondemand )
38
57
# TODO: Should this respect more ssh settings? Can it be configured
39
58
# by users ssh config and does this respect those settings?
40
59
Kernel . exec ( cmd )
0 commit comments