本文整理汇总了Python中plumbery.nodes.PlumberyNodes类的典型用法代码示例。如果您正苦于以下问题:Python PlumberyNodes类的具体用法?Python PlumberyNodes怎么用?Python PlumberyNodes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PlumberyNodes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: destroy_all_blueprints
def destroy_all_blueprints(self):
"""
Destroys all blueprints at this facility
"""
self.power_on()
nodes = PlumberyNodes(self)
infrastructure = PlumberyInfrastructure(self)
basement = self.list_basement()
for name in self.expand_blueprint('*'):
if name in basement:
continue
blueprint = self.get_blueprint(name)
plogging.debug("Destroying blueprint '{}'".format(name))
nodes.destroy_blueprint(blueprint)
infrastructure.destroy_blueprint(blueprint)
for name in basement:
blueprint = self.get_blueprint(name)
plogging.debug("Destroying blueprint '{}'".format(name))
nodes.destroy_blueprint(blueprint)
infrastructure.destroy_blueprint(blueprint)
示例2: polish_blueprint
def polish_blueprint(self, names, polishers):
"""
Walks a named blueprint for this facility and polish related resources
:param names: the name(s) of the blueprint(s) to polish
:type names: ``str`` or ``list`` of ``str``
:param polishers: polishers to be applied
:type polishers: list of :class:`plumbery.PlumberyPolisher`
"""
if isinstance(polishers, str):
polishers = PlumberyPolisher.filter(self.plumbery.polishers,
polishers)
self.power_on()
infrastructure = PlumberyInfrastructure(self)
nodes = PlumberyNodes(self)
for polisher in polishers:
polisher.move_to(self)
for name in self.expand_blueprint(names):
blueprint = self.get_blueprint(name)
container = infrastructure.get_container(blueprint)
for polisher in polishers:
polisher.shine_container(container)
nodes.polish_blueprint(blueprint, polishers, container)
示例3: stop_blueprint
def stop_blueprint(self, names):
"""
Stops nodes of the given blueprint at this facility
:param names: the name(s) of the target blueprint(s)
:type names: ``str`` or ``list`` of ``str``
You can use the following setting to prevent plumbery from stopping a
node::
- sql:
domain: *vdc1
ethernet: *data
nodes:
- slaveSQL:
running: always
"""
nodes = PlumberyNodes(self)
for name in self.expand_blueprint(names):
blueprint = self.get_blueprint(name)
if 'nodes' not in blueprint:
continue
nodes.stop_blueprint(blueprint)
示例4: build_blueprint
def build_blueprint(self, names):
"""
Builds a named blueprint for this facility
:param names: the name(s) of the blueprint(s) to build
:type names: ``str`` or ``list`` of ``str``
This function builds the named blueprint in two steps: the
infrastructure comes first, and then the nodes themselves.
>>>facility.build_blueprint('sql')
If the keyword ``basement`` mentions one or several blueprints,
then network domains of these special blueprints are built before
the actual target blueprint.
Example ``fittings.yaml``::
---
basement: admin
blueprints:
- admin:
ethernet: control
- sql:
ethernet: data
nodes:
- server1:
glue: control
In this example, the node ``server1``has two network interfaces. The
main network interface is connected to the network ``data``, and the
secondary network interface is connected to the network ``control``.
"""
self.power_on()
infrastructure = PlumberyInfrastructure(self)
nodes = PlumberyNodes(self)
basement = self.list_basement()
for name in basement:
blueprint = self.get_blueprint(name)
infrastructure.build(blueprint)
for name in self.expand_blueprint(names):
blueprint = self.get_blueprint(name)
if name not in basement:
infrastructure.build(blueprint)
nodes.build_blueprint(
blueprint,
infrastructure.get_container(blueprint))
示例5: lookup
def lookup(self, token):
"""
Retrieves the value attached to a token
:param token: the token, e.g., 'node.ipv6'
:type token: ``str``
:return: the value attached to this token, or `None`
"""
if token in self.cache:
return str(self.cache[token])
value = None
if self.context is not None:
value = self.context.lookup(token)
if value is not None:
return value
if self.container is None:
return None
tokens = token.split(".")
if len(tokens) < 2:
tokens.append("private")
nodes = PlumberyNodes(self.container.facility)
node = nodes.get_node(tokens[0])
if node is None:
return None
if self.context is not None:
self.context.remember(tokens[0], node.private_ips[0])
self.context.remember(tokens[0] + ".private", node.private_ips[0])
self.context.remember(tokens[0] + ".ipv6", node.extra["ipv6"])
if len(node.public_ips) > 0:
self.context.remember(tokens[0] + ".public", node.public_ips[0])
if tokens[1] == "private":
return node.private_ips[0]
if tokens[1] == "ipv6":
return node.extra["ipv6"]
if tokens[1] == "public":
if len(node.public_ips) > 0:
return node.public_ips[0]
else:
return ""
return None
示例6: shine_container
def shine_container(self, container):
"""
Rubs a container until it shines
:param container: the container to be polished
:type container: :class:`plumbery.PlumberyInfrastructure`
This is where the hard work is done. You have to override this
function in your own polisher. Note that you can compare the reality
versus the theoritical settings if you want.
"""
logging.info("Spitting at blueprint '{}'".format(
container.blueprint['target']))
if container.network is None:
logging.info("- aborted - no network here")
return
nodes = PlumberyNodes(self.facility)
names = nodes.list_nodes(container.blueprint)
logging.info("Waiting for nodes of '{}' to be deployed".format(
container.blueprint['target']))
for name in names:
while True:
node = nodes.get_node(name)
if node is None:
logging.info("- aborted - missing node '{}'".format(name))
return
if node.extra['status'].action is None:
break
if (node is not None
and node.extra['status'].failure_reason is not None):
logging.info("- aborted - failed deployment "
"of node '{}'".format(name))
return
time.sleep(20)
logging.info("- done")
container._build_firewall_rules()
container._reserve_ipv4()
container._build_balancer()
示例7: list_nodes
def list_nodes(self):
"""
Retrieves the list of nodes that have been defined across
blueprints for this facility
:return: names of nodes defined for this facility
:rtype: ``list`` of ``str`` or ``[]``
Nodes are defined in blueprints.
"""
labels = []
for blueprint in self.blueprints:
name = list(blueprint)[0]
if 'nodes' in blueprint[name]:
for item in blueprint[name]['nodes']:
if type(item) is dict:
label = list(item)[0]
else:
label = item
for label in PlumberyNodes.expand_labels(label):
if label in labels:
plogging.warning("Duplicate node name '{}'"
.format(label))
else:
labels.append(label)
return labels
示例8: wipe_blueprint
def wipe_blueprint(self, names):
"""
Destroys nodes of a given blueprint at this facility
:param names: the names of the blueprint to destroy
:type names: ``str`` or ``list`` of ``str``
"""
self.power_on()
nodes = PlumberyNodes(self)
for name in self.expand_blueprint(names):
blueprint = self.get_blueprint(name)
nodes.destroy_blueprint(blueprint)
示例9: destroy_blueprint
def destroy_blueprint(self, names):
"""
Destroys a given blueprint at this facility
:param names: the name(s) of the blueprint(s) to destroy
:type names: ``str`` or ``list`` of ``str``
"""
self.power_on()
nodes = PlumberyNodes(self)
infrastructure = PlumberyInfrastructure(self)
for name in self.expand_blueprint(names):
blueprint = self.get_blueprint(name)
nodes.destroy_blueprint(blueprint)
infrastructure.destroy_blueprint(blueprint)
示例10: start_blueprint
def start_blueprint(self, names):
"""
Starts nodes from a given blueprint at this facility
:param names: the name(s) of the target blueprint(s)
:type names: ``str`` or ``list`` of ``str``
"""
nodes = PlumberyNodes(self)
for name in self.expand_blueprint(names):
blueprint = self.get_blueprint(name)
if 'nodes' not in blueprint:
continue
nodes.start_blueprint(blueprint)
示例11: do_polish
def do_polish(polisher):
engine = PlumberyEngine()
engine.set_shared_secret('fake_secret')
engine.set_user_name('fake_name')
engine.set_user_password('fake_password')
engine.from_text(myInformation)
polisher.go(engine)
facility = engine.list_facility('NA9')[0]
DimensionDataNodeDriver.connectionCls.conn_classes = (
None, DimensionDataMockHttp)
DimensionDataMockHttp.type = None
facility.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)
polisher.move_to(facility)
blueprint = facility.get_blueprint('test')
infrastructure = PlumberyInfrastructure(facility)
container = infrastructure.get_container(blueprint)
polisher.shine_container(container)
nodes = PlumberyNodes(facility)
node = nodes.get_node('stackstorm')
polisher.shine_node(
node=node, settings=fakeNodeSettings, container=container)
node = nodes.get_node('node1')
polisher.shine_node(
node=node, settings=fakeNodeSettings, container=container)
polisher.move_to(FakeFacility())
polisher.shine_container(FakeContainer())
polisher.shine_node(
node=FakeNode(), settings=fakeNodeSettings, container=FakeContainer())
polisher.reap()
示例12: TestPlumberyNodes
class TestPlumberyNodes(unittest.TestCase):
def setUp(self):
self.nodes = PlumberyNodes(FakeFacility())
def tearDown(self):
self.nodes = None
def test_build_blueprint(self):
domain = FakeDomain()
self.nodes.build_blueprint(fakeBlueprint, domain)
def test_destroy_blueprint(self):
self.nodes.destroy_blueprint(fakeBlueprint)
def test_get_node(self):
self.nodes.get_node("stackstorm")
def test_start_nodes(self):
self.nodes.start_blueprint("fake")
def test_stop_nodes(self):
self.nodes.stop_blueprint("fake")
示例13: move_to
def move_to(self, facility):
"""
Moves to another API endpoint
:param facility: access to local parameters and functions
:type facility: :class:`plumbery.PlumberyFacility`
"""
self.facility = facility
self.region = facility.region
self.nodes = PlumberyNodes(facility)
示例14: build_all_blueprints
def build_all_blueprints(self):
"""
Builds all blueprints defined for this facility
This function builds all network domains across all blueprints, then
it builds all nodes across all blueprints.
If the keyword ``basement`` mentions one or several blueprints,
then these are built before the other blueprints.
"""
self.power_on()
infrastructure = PlumberyInfrastructure(self)
nodes = PlumberyNodes(self)
basement = self.list_basement()
for name in basement:
blueprint = self.get_blueprint(name)
infrastructure.build(blueprint)
blueprints = self.expand_blueprint('*')
for name in blueprints:
if name not in basement:
blueprint = self.get_blueprint(name)
infrastructure.build(blueprint)
for name in basement:
blueprint = self.get_blueprint(name)
container = infrastructure.get_container(blueprint)
nodes.build_blueprint(blueprint, container)
for name in blueprints:
if name not in basement:
blueprint = self.get_blueprint(name)
container = infrastructure.get_container(blueprint)
nodes.build_blueprint(blueprint, container)
示例15: SpitPolisher
class SpitPolisher(PlumberyPolisher):
"""
Finalizes the setup of fittings
This polisher looks at each node in sequence, and adjust settings
according to fittings plan. This is covering various features that
can not be set during the creation of nodes, such as:
- number of CPU
- quantity of RAM
- monitoring
"""
def move_to(self, facility):
"""
Moves to another API endpoint
:param facility: access to local parameters and functions
:type facility: :class:`plumbery.PlumberyFacility`
"""
self.facility = facility
self.region = facility.region
self.nodes = PlumberyNodes(facility)
def shine_container(self, container):
"""
Rubs a container until it shines
:param container: the container to be polished
:type container: :class:`plumbery.PlumberyInfrastructure`
This is where the hard work is done. You have to override this
function in your own polisher. Note that you can compare the reality
versus the theoritical settings if you want.
"""
logging.info("Spitting at blueprint '{}'".format(
container.blueprint['target']))
if container.network is None:
logging.info("- aborted - no network here")
return
nodes = PlumberyNodes(self.facility)
names = nodes.list_nodes(container.blueprint)
logging.info("- waiting for nodes to be deployed")
for name in names:
while True:
node = nodes.get_node(name)
if node is None:
logging.info("- aborted - missing node '{}'".format(name))
return
if node.extra['status'].action is None:
break
if (node is not None
and node.extra['status'].failure_reason is not None):
logging.info("- aborted - failed deployment "
"of node '{}'".format(name))
return
time.sleep(20)
logging.info("- nodes have been deployed")
container._build_firewall_rules()
container._build_balancer()
def shine_node(self, node, settings, container):
"""
Finalizes setup of one node
:param node: the node to be polished
:type node: :class:`libcloud.compute.base.Node`
:param settings: the fittings plan for this node
:type settings: ``dict``
:param container: the container of this node
:type container: :class:`plumbery.PlumberyInfrastructure`
"""
logging.info("Spitting at node '{}'".format(settings['name']))
if node is None:
logging.info("- not found")
return
if 'disks' in settings:
for item in settings['disks']:
#.........这里部分代码省略.........