1919
2020from .account import AccountMixin
2121from .blueprint import BlueprintMixin
22- from .exceptions import BlueprintException , StackException , IncompatibleVersionException
22+ from .config import StackdioConfig
23+ from .exceptions import (
24+ BlueprintException ,
25+ StackException ,
26+ IncompatibleVersionException ,
27+ MissingUrlException
28+ )
2329from .formula import FormulaMixin
24- from .http import get , post , patch
30+ from .http import HttpMixin , get , post , patch
2531from .image import ImageMixin
2632from .region import RegionMixin
2733from .settings import SettingsMixin
2834from .stack import StackMixin
2935from .version import _parse_version_string
3036
3137logger = logging .getLogger (__name__ )
38+ logger .addHandler (logging .NullHandler ())
3239
3340
34- class StackdIO (BlueprintMixin , FormulaMixin , AccountMixin ,
35- ImageMixin , RegionMixin , StackMixin , SettingsMixin ):
41+ class StackdioClient (BlueprintMixin , FormulaMixin , AccountMixin , ImageMixin ,
42+ RegionMixin , StackMixin , SettingsMixin , HttpMixin ):
3643
37- def __init__ (self , protocol = "https" , host = "localhost" , port = 443 ,
38- base_url = None , auth = None , verify = True ):
44+ def __init__ (self , url = None , username = None , password = None , verify = True ):
45+ self . config = StackdioConfig ()
3946
40- super (StackdIO , self ).__init__ (auth = auth , verify = verify )
41- if base_url :
42- self .url = base_url if base_url .endswith ('/' ) else "%s/" % base_url
43- else :
44- self .url = "{protocol}://{host}:{port}/api/" .format (
45- protocol = protocol ,
46- host = host ,
47- port = port )
47+ if self .config .usable_config :
48+ # Grab stuff from the config
49+ url = self .config ['url' ]
50+ username = self .config ['username' ]
51+ verify = self .config ['verify' ]
4852
49- self .auth = auth
53+ super (StackdioClient , self ).__init__ (url = url , auth = (username , password ), verify = verify )
54+ self .url = url
5055
51- _ , self .version = _parse_version_string (self .get_version ())
56+ try :
57+ _ , self .version = _parse_version_string (self .get_version ())
58+ except MissingUrlException :
59+ self .version = None
5260
53- if self .version [0 ] != 0 or self .version [1 ] != 7 :
61+ if self .version and self . version [0 ] != 0 or self .version [1 ] != 7 :
5462 raise IncompatibleVersionException ('Server version {0}.{1}.{2} not '
5563 'supported.' .format (** self .version ))
5664
65+ def usable (self ):
66+ return self .config .usable_config
67+
5768 @get ('' )
5869 def get_root (self ):
5970 pass
@@ -67,12 +78,12 @@ def get_version(self, resp):
6778 return resp ['version' ]
6879
6980 @post ('cloud/security_groups/' )
70- def create_security_group (self , name , description , cloud_provider , is_default = True ):
71- """Create a security group"""
81+ def create_security_group (self , name , description , cloud_account , group_id , is_default = True ):
7282
7383 return {
74- "name" : name ,
75- "description" : description ,
76- "cloud_provider" : cloud_provider ,
77- "is_default" : is_default
84+ 'name' : name ,
85+ 'description' : description ,
86+ 'cloud_account' : cloud_account ,
87+ 'group_id' : group_id ,
88+ 'is_default' : is_default
7889 }
0 commit comments